X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FRequest.php;h=e6e0fdf1220241961241592b0fbf35940eb1bc57;hb=45ee78a6430516d54fa9aecb2f3a0f8b1dd40d8b;hp=831947358ed61658aab352e5009adb8c22eca973;hpb=eaf537d9b91fa5f2aa8b915fbf057bc657cce76f;p=civicrm-core.git diff --git a/CRM/Utils/Request.php b/CRM/Utils/Request.php index 831947358e..e6e0fdf122 100644 --- a/CRM/Utils/Request.php +++ b/CRM/Utils/Request.php @@ -126,8 +126,10 @@ class CRM_Utils_Request { } // minor hack for action - if ($name == 'action' && is_string($value)) { - $value = CRM_Core_Action::resolve($value); + if ($name == 'action') { + if (!is_numeric($value) && is_string($value)) { + $value = CRM_Core_Action::resolve($value); + } } if (isset($value) && $store) { @@ -219,4 +221,35 @@ class CRM_Utils_Request { return CRM_Utils_Request::retrieve((string) $name, (string) $type, $null, (bool) $isRequired, $defaultValue, $method, TRUE); } + /** + * Retrieve the component from the action attribute of a form. + * + * Contribution Page forms and Event Management forms detect the value of a + * component (and therefore the desired tab key) by reaching into the "action" + * attribute of a form and reading the final item of the path. In WordPress, + * however, the URL may be urlencoded, and so the URL may need to be decoded + * before parsing it. + * + * @see https://lab.civicrm.org/dev/wordpress/issues/12#note_10699 + * + * @param array $attributes + * The form attributes array. + * + * @return string $value + * The desired value. + */ + public static function retrieveComponent($attributes) { + $url = CRM_Utils_Array::value('action', $attributes); + // Whilst the following is a fallible universal test for urlencoded URLs, + // thankfully the "action" URL has a limited and predictable form and + // therefore this comparison is sufficient for our purposes. + if (rawurlencode(rawurldecode($url)) !== $url) { + $value = strtolower(basename(rawurldecode($url))); + } + else { + $value = strtolower(basename($url)); + } + return $value; + } + }