Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-21716

Links in Drupal Views are improperly URL-encoded

    Details

    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code
    • Verified?:
      No
    • Overview:
      When you have a Drupal View that contains a field with a link to its CiviCRM record, the resulting query string in the link is URL-encoded when it should not be.
    • How it works currently:
      Hide
      Say you have the field "CiviCRM Contacts: Display Name" in your view, and the field option "Link this field to its CiviCRM Contact" is checked. The resulting link will have a URL similar to the following:
      http://domain.tld/civicrm/contact/view%3Fcid%3D5765%26reset%3D1
      Show
      Say you have the field "CiviCRM Contacts: Display Name" in your view, and the field option "Link this field to its CiviCRM Contact" is checked. The resulting link will have a URL similar to the following: http://domain.tld/civicrm/contact/view%3Fcid%3D5765%26reset%3D1
    • How it should work:
      Hide
      The resulting link should have a URL similar to the following:
      http://domain.tld/civicrm/contact/view?cid=5765&reset=1
      Show
      The resulting link should have a URL similar to the following: http://domain.tld/civicrm/contact/view?cid=5765&reset=1
    • Acceptance Criteria:
      Links in Drupal Views to CiviCRM records should not be URL-encoded.

      Description

      When you have a Drupal View that contains a field with a link to a CiviCRM page, and the link does not have a Drupal alias, the resulting query string in the link is URL-encoded when it should not be.

      Say you have the field "CiviCRM Contacts: Display Name" in your view, and the field option "Link this field to its CiviCRM Contact" is checked. The resulting link will have a URL similar to the following:
      http://domain.tld/civicrm/contact/view%3Fcid%3D5765%26reset%3D1

      The resulting link should have a URL similar to the following:
      http://domain.tld/civicrm/contact/view?cid=5765&reset=1

      I have a case where my view contains an Event Title field that is linked to display Event Participants.  When the link is clicked, the list of participants displays correctly.  Then, when you click the Participant column header to sort the list by participant name, participants for all events display.

      The code in drupal/modules/views/civicrm.views.inc should check for a Drupal alias first, and if none,  pass the query data to the Drupal url() function in the $options array, and not include it in the path.

      Here is a version of civicrm_views_url() with the fix:

      function civicrm_views_url($path, $query, $absolute = FALSE) {
        // Force alphabetical order of query params, for consistent support
        // of Drupal aliases. This is required because $query is a string that may
        // be coming to us in any order; but query parameter order matters when
        // passing that query string as part of $path in drupal_get_path_alias().
        $original_path = $path;
        $query_data = array();
        if (!empty($query)) {
          if (is_array($query)) {
            $query_data = $query;
          }
          else {
            parse_str($query, $query_data);
          }
          ksort($query_data);
          $query = http_build_query($query_data);
          $path .= "?{$query}";
        }
        $options = array(
          'absolute' => $absolute,
        );
        $alias = drupal_get_path_alias($path);
        if ($alias != $path) {
          $path = $alias;
          $options['alias'] = TRUE;
        }
        else {
          $path = $original_path;
          $options['query'] = $query_data;
        }
        $url = url($path, $options);
        return $url;
      }
      

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              marty Marty Wright
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: