123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- <?php
- namespace Drupal\Core\Menu;
- /**
- * Defines an interface for storing a menu tree containing menu link IDs.
- *
- * The tree contains a hierarchy of menu links which have an ID as well as a
- * route name or external URL.
- */
- interface MenuTreeStorageInterface {
- /**
- * The maximum depth of tree the storage implementation supports.
- *
- * @return int
- * The maximum depth.
- */
- public function maxDepth();
- /**
- * Clears all definitions cached in memory.
- */
- public function resetDefinitions();
- /**
- * Rebuilds the stored menu link definitions.
- *
- * Links that saved by passing definitions into this method must be included
- * on all future calls, or they will be purged. This allows for automatic
- * cleanup e.g. when modules are uninstalled.
- *
- * @param array $definitions
- * The new menu link definitions.
- */
- public function rebuild(array $definitions);
- /**
- * Loads a menu link plugin definition from the storage.
- *
- * @param string $id
- * The menu link plugin ID.
- *
- * @return array|false
- * The plugin definition, or FALSE if no definition was found for the ID.
- */
- public function load($id);
- /**
- * Loads multiple plugin definitions from the storage.
- *
- * @param array $ids
- * An array of plugin IDs.
- *
- * @return array
- * An array of plugin definition arrays keyed by plugin ID, which are the
- * actual definitions after the loadMultiple() including all those plugins
- * from $ids.
- */
- public function loadMultiple(array $ids);
- /**
- * Loads multiple plugin definitions from the storage based on properties.
- *
- * @param array $properties
- * The properties to filter by.
- *
- * @return array
- * An array of menu link definition arrays.
- *
- * @throws \InvalidArgumentException
- * Thrown if an invalid property name is specified in $properties.
- */
- public function loadByProperties(array $properties);
- /**
- * Loads multiple plugin definitions from the storage based on route.
- *
- * @param string $route_name
- * The route name.
- * @param array $route_parameters
- * (optional) The route parameters. Defaults to an empty array.
- * @param string $menu_name
- * (optional) Restricts the found links to just those in the named menu.
- *
- * @return array
- * An array of menu link definitions keyed by ID and ordered by depth.
- */
- public function loadByRoute($route_name, array $route_parameters = [], $menu_name = NULL);
- /**
- * Saves a plugin definition to the storage.
- *
- * @param array $definition
- * A definition for a \Drupal\Core\Menu\MenuLinkInterface plugin.
- *
- * @return array
- * The menu names affected by the save operation. This will be one menu
- * name if the link is saved to the sane menu, or two if it is saved to a
- * new menu.
- *
- * @throws \Exception
- * Thrown if the storage back-end does not exist and could not be created.
- * @throws \Drupal\Component\Plugin\Exception\PluginException
- * Thrown if the definition is invalid - for example, if the specified
- * parent would cause the links children to be moved to greater than the
- * maximum depth.
- */
- public function save(array $definition);
- /**
- * Deletes a menu link definition from the storage.
- *
- * @param string $id
- * The menu link plugin ID.
- */
- public function delete($id);
- /**
- * Loads a menu link tree from the storage.
- *
- * This function may be used build the data for a menu tree only, for example
- * to further massage the data manually before further processing happens.
- * MenuLinkTree::checkAccess() needs to be invoked afterwards.
- *
- * The tree order is maintained using an optimized algorithm, for example by
- * storing each parent in an individual field, see
- * https://www.drupal.org/node/141866 for more details. However, any details
- * of the storage should not be relied upon since it may be swapped with a
- * different implementation.
- *
- * @param string $menu_name
- * The name of the menu.
- * @param \Drupal\Core\Menu\MenuTreeParameters $parameters
- * The parameters to determine which menu links to be loaded into a tree.
- *
- * @return array
- * An array with 2 elements:
- * - tree: A fully built menu tree containing an array.
- * @see static::treeDataRecursive()
- * - route_names: An array of all route names used in the tree.
- */
- public function loadTreeData($menu_name, MenuTreeParameters $parameters);
- /**
- * Loads all the enabled menu links that are below the given ID.
- *
- * The returned links are not ordered, and visible children will be included
- * even if they have parent that is not enabled or ancestor so would not
- * normally appear in a rendered tree.
- *
- * @param string $id
- * The parent menu link ID.
- * @param int $max_relative_depth
- * The maximum relative depth of the children relative to the passed parent.
- *
- * @return array
- * An array of enabled link definitions, keyed by ID.
- */
- public function loadAllChildren($id, $max_relative_depth = NULL);
- /**
- * Loads all the IDs for menu links that are below the given ID.
- *
- * @param string $id
- * The parent menu link ID.
- *
- * @return array
- * An unordered array of plugin IDs corresponding to all children.
- */
- public function getAllChildIds($id);
- /**
- * Loads a subtree rooted by the given ID.
- *
- * The returned links are structured like those from loadTreeData().
- *
- * @param string $id
- * The menu link plugin ID.
- * @param int $max_relative_depth
- * (optional) The maximum depth of child menu links relative to the passed
- * in. Defaults to NULL, in which case the full subtree will be returned.
- *
- * @return array
- * An array with 2 elements:
- * - subtree: A fully built menu tree element or FALSE.
- * - route_names: An array of all route names used in the subtree.
- */
- public function loadSubtreeData($id, $max_relative_depth = NULL);
- /**
- * Returns all the IDs that represent the path to the root of the tree.
- *
- * @param string $id
- * A menu link ID.
- *
- * @return array
- * An associative array of IDs with keys equal to values that represents the
- * path from the given ID to the root of the tree. If $id is an ID that
- * exists, the returned array will at least include it. An empty array is
- * returned if the ID does not exist in the storage. An example $id (8) with
- * two parents (1, 6) looks like the following:
- * @code
- * array(
- * 'p1' => 1,
- * 'p2' => 6,
- * 'p3' => 8,
- * 'p4' => 0,
- * 'p5' => 0,
- * 'p6' => 0,
- * 'p7' => 0,
- * 'p8' => 0,
- * 'p9' => 0
- * )
- * @endcode
- */
- public function getRootPathIds($id);
- /**
- * Finds expanded links in a menu given a set of possible parents.
- *
- * @param string $menu_name
- * The menu name.
- * @param array $parents
- * One or more parent IDs to match.
- *
- * @return array
- * The menu link IDs that are flagged as expanded in this menu.
- */
- public function getExpanded($menu_name, array $parents);
- /**
- * Finds the height of a subtree rooted by the given ID.
- *
- * @param string $id
- * The ID of an item in the storage.
- *
- * @return int
- * Returns the height of the subtree. This will be at least 1 if the ID
- * exists, or 0 if the ID does not exist in the storage.
- */
- public function getSubtreeHeight($id);
- /**
- * Determines whether a specific menu name is used in the tree.
- *
- * @param string $menu_name
- * The menu name.
- *
- * @return bool
- * Returns TRUE if the given menu name is used, otherwise FALSE.
- */
- public function menuNameInUse($menu_name);
- /**
- * Returns the used menu names in the tree storage.
- *
- * @return array
- * The menu names.
- */
- public function getMenuNames();
- /**
- * Counts the total number of menu links in one menu or all menus.
- *
- * @param string $menu_name
- * (optional) The menu name to count by. Defaults to all menus.
- *
- * @return int
- * The number of menu links in the named menu, or in all menus if the menu
- * name is NULL.
- */
- public function countMenuLinks($menu_name = NULL);
- }
|