Merge pull request #15300 from civicrm/5.18
[civicrm-core.git] / CRM / Core / Menu.php
index c7c0904355069c8ce6dcc3d801dd0fb692196622..c6fefdc91a5951343e3edf09bacfff9781cbea00 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -29,7 +29,7 @@
  * This file contains the various menus of the CiviCRM module
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  */
 
 require_once 'CRM/Core/I18n.php';
@@ -44,16 +44,16 @@ class CRM_Core_Menu {
    *
    * @var array
    */
-  static $_items = NULL;
+  public static $_items = NULL;
 
   /**
    * The list of permissioned menu items.
    *
    * @var array
    */
-  static $_permissionedItems = NULL;
+  public static $_permissionedItems = NULL;
 
-  static $_serializedElements = array(
+  public static $_serializedElements = array(
     'access_arguments',
     'access_callback',
     'page_arguments',
@@ -61,7 +61,7 @@ class CRM_Core_Menu {
     'breadcrumb',
   );
 
-  static $_menuCache = NULL;
+  public static $_menuCache = NULL;
   const MENU_ITEM = 1;
 
   /**
@@ -317,7 +317,7 @@ class CRM_Core_Menu {
       $menu->find(TRUE);
 
       if (!CRM_Core_Config::isUpgradeMode() ||
-        CRM_Core_DAO::checkFieldExists('civicrm_menu', 'module_data', FALSE)
+        CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_menu', 'module_data', FALSE)
       ) {
         // Move unrecognized fields to $module_data.
         $module_data = array();
@@ -367,13 +367,12 @@ class CRM_Core_Menu {
         'title' => $item['title'],
         'desc' => CRM_Utils_Array::value('desc', $item),
         'id' => strtr($item['title'], array(
-            '(' => '_',
-            ')' => '',
-            ' ' => '',
-            ',' => '_',
-            '/' => '_',
-          )
-        ),
+          '(' => '_',
+          ')' => '',
+          ' ' => '',
+          ',' => '_',
+          '/' => '_',
+        )),
         'url' => CRM_Utils_System::url($path, $query,
           FALSE,
           NULL,
@@ -402,120 +401,6 @@ class CRM_Core_Menu {
     $menu['admin'] = array('breadcrumb' => $values);
   }
 
-  /**
-   * Get navigation.
-   *
-   * @param bool $all
-   *
-   * @return mixed
-   * @throws Exception
-   */
-  public static function &getNavigation($all = FALSE) {
-    CRM_Core_Error::fatal();
-
-    if (!self::$_menuCache) {
-      self::get('navigation');
-    }
-
-    if (CRM_Core_Config::isUpgradeMode()) {
-      return array();
-    }
-
-    if (!array_key_exists('navigation', self::$_menuCache)) {
-      // problem could be due to menu table empty. Just do a
-      // menu store and try again
-      self::store();
-
-      // here we goo
-      self::get('navigation');
-      if (!array_key_exists('navigation', self::$_menuCache)) {
-        CRM_Core_Error::fatal();
-      }
-    }
-    $nav = &self::$_menuCache['navigation'];
-
-    if (!$nav ||
-      !isset($nav['breadcrumb'])
-    ) {
-      return NULL;
-    }
-
-    $values = &$nav['breadcrumb'];
-    $config = CRM_Core_Config::singleton();
-    foreach ($values as $index => $item) {
-      if (strpos(CRM_Utils_Array::value($config->userFrameworkURLVar, $_REQUEST),
-          $item['path']
-        ) === 0
-      ) {
-        $values[$index]['active'] = 'class="active"';
-      }
-      else {
-        $values[$index]['active'] = '';
-      }
-
-      if ($values[$index]['parent']) {
-        $parent = $values[$index]['parent'];
-
-        // only reset if still a leaf
-        if ($values[$parent]['class'] == 'leaf') {
-          $values[$parent]['class'] = 'collapsed';
-        }
-
-        // if a child or the parent is active, expand the menu
-        if ($values[$index]['active'] ||
-          $values[$parent]['active']
-        ) {
-          $values[$parent]['class'] = 'expanded';
-        }
-
-        // make the parent inactive if the child is active
-        if ($values[$index]['active'] &&
-          $values[$parent]['active']
-        ) {
-          $values[$parent]['active'] = '';
-        }
-      }
-    }
-
-    if (!$all) {
-      // remove all collapsed menu items from the array
-      foreach ($values as $weight => $v) {
-        if ($v['parent'] &&
-          $values[$v['parent']]['class'] == 'collapsed'
-        ) {
-          unset($values[$weight]);
-        }
-      }
-    }
-
-    // check permissions for the rest
-    $activeChildren = array();
-
-    foreach ($values as $weight => $v) {
-      if (CRM_Core_Permission::checkMenuItem($v)) {
-        if ($v['parent']) {
-          $activeChildren[] = $weight;
-        }
-      }
-      else {
-        unset($values[$weight]);
-      }
-    }
-
-    // add the start / end tags
-    $len = count($activeChildren) - 1;
-    if ($len >= 0) {
-      $values[$activeChildren[0]]['start'] = TRUE;
-      $values[$activeChildren[$len]]['end'] = TRUE;
-    }
-
-    ksort($values, SORT_NUMERIC);
-    $i18n = CRM_Core_I18n::singleton();
-    $i18n->localizeTitles($values);
-
-    return $values;
-  }
-
   /**
    * Get admin links.
    *
@@ -570,11 +455,16 @@ class CRM_Core_Menu {
           'title' => $menu[$currentPath]['title'],
           'url' => CRM_Utils_System::url($currentPath,
             'reset=1' . $urlVar,
-            FALSE, // absolute
-            NULL, // fragment
-            TRUE, // htmlize
-            FALSE, // frontend
-            TRUE // forceBackend; CRM-14439 work-around; acceptable for now because we don't display breadcrumbs on frontend
+            // absolute
+            FALSE,
+            // fragment
+            NULL,
+            // htmlize
+            TRUE,
+            // frontend
+            FALSE,
+            // forceBackend; CRM-14439 work-around; acceptable for now because we don't display breadcrumbs on frontend
+            TRUE
           ),
         );
       }