dev/core#3719 fix inconistent handling of job_type:label
[civicrm-core.git] / CRM / Core / Menu.php
index a25a8e39cbc6b8198cec5ec4886331cbdda04eb8..c7376b2d345382f76542b2372ad0238ea02c1198 100644 (file)
@@ -16,8 +16,6 @@
  * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
 
-require_once 'CRM/Core/I18n.php';
-
 /**
  * Class CRM_Core_Menu.
  */
@@ -37,13 +35,13 @@ class CRM_Core_Menu {
    */
   public static $_permissionedItems = NULL;
 
-  public static $_serializedElements = array(
+  public static $_serializedElements = [
     'access_arguments',
     'access_callback',
     'page_arguments',
     'page_callback',
     'breadcrumb',
-  );
+  ];
 
   public static $_menuCache = NULL;
   const MENU_ITEM = 1;
@@ -58,8 +56,6 @@ class CRM_Core_Menu {
    */
   public static function &xmlItems($fetchFromXML = FALSE) {
     if (!self::$_items || $fetchFromXML) {
-      $config = CRM_Core_Config::singleton();
-
       // We needs this until Core becomes a component
       $coreMenuFilesNamespace = 'CRM_Core_xml_Menu';
       $coreMenuFilesPath = str_replace('_', DIRECTORY_SEPARATOR, $coreMenuFilesNamespace);
@@ -121,7 +117,7 @@ class CRM_Core_Menu {
 
       if ($item->ids_arguments) {
         $ids = [];
-        foreach (array('json' => 'json', 'html' => 'html', 'exception' => 'exceptions') as $tag => $attr) {
+        foreach (['json' => 'json', 'html' => 'html', 'exception' => 'exceptions'] as $tag => $attr) {
           $ids[$attr] = [];
           foreach ($item->ids_arguments->{$tag} as $value) {
             $ids[$attr][] = (string) $value;
@@ -158,10 +154,10 @@ class CRM_Core_Menu {
             foreach ($elements as $element) {
               $items[] = $element;
             }
-            $value = array($items, $op);
+            $value = [$items, $op];
           }
           else {
-            $value = array(array($value), 'and');
+            $value = [[$value], 'and'];
           }
         }
         elseif ($key == 'is_public' || $key == 'is_ssl') {
@@ -191,8 +187,8 @@ class CRM_Core_Menu {
    *
    * @return bool
    */
-  public static function isArrayTrue(&$values) {
-    foreach ($values as $name => $value) {
+  public static function isArrayTrue($values) {
+    foreach ($values as $value) {
       if (!$value) {
         return FALSE;
       }
@@ -209,13 +205,13 @@ class CRM_Core_Menu {
    * @throws CRM_Core_Exception
    */
   public static function fillMenuValues(&$menu, $path) {
-    $fieldsToPropagate = array(
+    $fieldsToPropagate = [
       'access_callback',
       'access_arguments',
       'page_callback',
       'page_arguments',
       'is_ssl',
-    );
+    ];
     $fieldsPresent = [];
     foreach ($fieldsToPropagate as $field) {
       $fieldsPresent[$field] = isset($menu[$path][$field]);
@@ -355,16 +351,16 @@ class CRM_Core_Menu {
 
       $query = !empty($item['path_arguments']) ? str_replace(',', '&', $item['path_arguments']) . '&reset=1' : 'reset=1';
 
-      $value = array(
+      $value = [
         'title' => $item['title'],
         'desc' => $item['desc'] ?? NULL,
-        'id' => strtr($item['title'], array(
+        'id' => strtr($item['title'], [
           '(' => '_',
           ')' => '',
           ' ' => '',
           ',' => '_',
           '/' => '_',
-        )),
+        ]),
         'url' => CRM_Utils_System::url($path, $query,
           FALSE,
           NULL,
@@ -375,7 +371,7 @@ class CRM_Core_Menu {
         ),
         'icon' => $item['icon'] ?? NULL,
         'extra' => $item['extra'] ?? NULL,
-      );
+      ];
       if (!array_key_exists($item['adminGroup'], $values)) {
         $values[$item['adminGroup']] = [];
         $values[$item['adminGroup']]['fields'] = [];
@@ -388,25 +384,17 @@ class CRM_Core_Menu {
       ksort($values[$group]);
     }
 
-    $menu['admin'] = array('breadcrumb' => $values);
+    $menu['admin'] = ['breadcrumb' => $values];
   }
 
   /**
    * Get admin links.
    *
-   * @return null
+   * @return array|null
    */
-  public static function &getAdminLinks() {
+  public static function getAdminLinks() {
     $links = self::get('admin');
-
-    if (!$links ||
-      !isset($links['breadcrumb'])
-    ) {
-      return NULL;
-    }
-
-    $values = &$links['breadcrumb'];
-    return $values;
+    return $links['breadcrumb'] ?? NULL;
   }
 
   /**
@@ -441,7 +429,7 @@ class CRM_Core_Menu {
         isset($menu[$currentPath]['title'])
       ) {
         $urlVar = !empty($menu[$currentPath]['path_arguments']) ? '&' . $menu[$currentPath]['path_arguments'] : '';
-        $crumbs[] = array(
+        $crumbs[] = [
           'title' => $menu[$currentPath]['title'],
           'url' => CRM_Utils_System::url($currentPath,
             'reset=1' . $urlVar,
@@ -456,7 +444,7 @@ class CRM_Core_Menu {
             // forceBackend; CRM-14439 work-around; acceptable for now because we don't display breadcrumbs on frontend
             TRUE
           ),
-        );
+        ];
       }
     }
     $menu[$path]['breadcrumb'] = $crumbs;
@@ -465,8 +453,8 @@ class CRM_Core_Menu {
   }
 
   /**
-   * @param $menu
-   * @param $path
+   * @param array $menu
+   * @param string|int $path
    */
   public static function buildReturnUrl(&$menu, $path) {
     if (!isset($menu[$path]['return_url'])) {
@@ -486,21 +474,17 @@ class CRM_Core_Menu {
       array_pop($pathElements);
 
       if (empty($pathElements)) {
-        return array(NULL, NULL);
+        return [NULL, NULL];
       }
       $newPath = implode('/', $pathElements);
 
       return self::getReturnUrl($menu, $newPath);
     }
     else {
-      return array(
-        CRM_Utils_Array::value('return_url',
-          $menu[$path]
-        ),
-        CRM_Utils_Array::value('return_url_args',
-          $menu[$path]
-        ),
-      );
+      return [
+        $menu[$path]['return_url'] ?? NULL,
+        $menu[$path]['return_url_args'] ?? NULL,
+      ];
     }
   }
 
@@ -544,16 +528,13 @@ class CRM_Core_Menu {
   }
 
   /**
-   * @param $path string
+   * @param string $path
    *   Path of menu item to retrieve.
    *
    * @return array
    *   Menu entry array.
    */
   public static function get($path) {
-    // return null if menu rebuild
-    $config = CRM_Core_Config::singleton();
-
     $args = explode('/', $path);
 
     $elements = [];
@@ -622,20 +603,10 @@ UNION (
       }
     }
 
-    // *FIXME* : hack for 4.1 -> 4.2 upgrades.
     if (preg_match('/^civicrm\/(upgrade\/)?queue\//', $path)) {
       CRM_Queue_Menu::alter($path, $menuPath);
     }
 
-    // Part of upgrade framework but not run inside main upgrade because it deletes data
-    // Once we have another example of a 'cleanup' we should generalize the clause below so it grabs string
-    // which follows upgrade/ and checks for existence of a function in Cleanup class.
-    if ($path == 'civicrm/upgrade/cleanup425') {
-      $menuPath['page_callback'] = array('CRM_Upgrade_Page_Cleanup', 'cleanup425');
-      $menuPath['access_arguments'][0][] = 'administer CiviCRM';
-      $menuPath['access_callback'] = array('CRM_Core_Permission', 'checkMenu');
-    }
-
     if (!empty($menuPath)) {
       $i18n = CRM_Core_I18n::singleton();
       $i18n->localizeTitles($menuPath);
@@ -652,7 +623,7 @@ UNION (
     if (!is_string($pathArgs)) {
       return;
     }
-    $args = [];
+    $arr = [];
 
     $elements = explode(',', $pathArgs);
     foreach ($elements as $keyVal) {