MenuTreeStorage
class MenuTreeStorage implements MenuTreeStorageInterface (View source)
Provides a menu tree storage using the database.
Constants
| MAX_DEPTH |
The maximum depth of a menu links tree. |
Properties
| protected Connection | $connection | The database connection. |
|
| protected CacheBackendInterface | $menuCacheBackend | Cache backend instance for the extracted tree data. |
|
| protected CacheTagsInvalidatorInterface | $cacheTagsInvalidator | The cache tags invalidator. |
|
| protected string | $table | The database table name. |
|
| protected array | $options | Additional database connection options to use in queries. |
|
| protected array | $definitions | Stores definitions that have already been loaded for better performance. |
|
| protected array | $serializedFields | List of serialized fields. |
|
| protected array | $definitionFields | List of plugin definition fields. |
Methods
Constructs a new \Drupal\Core\Menu\MenuTreeStorage.
The maximum depth of tree the storage implementation supports.
Clears all definitions cached in memory.
Rebuilds the stored menu link definitions.
Purges multiple menu links that no longer exist.
Executes a select query while making sure the database table exists.
Saves a plugin definition to the storage.
Saves a link without clearing caches.
Fills in all the fields the database save needs, using the link definition.
Deletes a menu link definition from the storage.
Finds the height of a subtree rooted by the given ID.
Finds the relative depth of this link's deepest child.
Sets the materialized path field values based on the parent.
Re-parents a link's children when the link itself is moved.
Loads the parent definition if it exists.
Sets has_children for the link's parent if it has visible children.
Prepares a link by unserializing values and saving the definition.
Loads multiple plugin definitions from the storage based on properties.
Loads multiple plugin definitions from the storage based on route.
Loads multiple plugin definitions from the storage.
Loads a menu link plugin definition from the storage.
Loads all table fields, not just those that are in the plugin definition.
Loads all table fields for multiple menu link definitions by ID.
Returns all the IDs that represent the path to the root of the tree.
Finds expanded links in a menu given a set of possible parents.
Saves menu links recursively.
Loads a menu link tree from the storage.
Loads links in the given menu, according to the given tree parameters.
Traverses the menu tree and collects all the route names and definitions.
Collects all the route names and definitions.
Loads a subtree rooted by the given ID.
Determines whether a specific menu name is used in the tree.
Returns the used menu names in the tree storage.
Counts the total number of menu links in one menu or all menus.
Loads all the IDs for menu links that are below the given ID.
Loads all the enabled menu links that are below the given ID.
Prepares the data for calling $this->treeDataRecursive().
Builds the data representing a menu tree.
Checks if the tree table exists and create it if not.
Determines serialized fields in the storage.
Determines fields that are part of the plugin definition.
Defines the schema for the tree table.
Find any previously discovered menu links that no longer exist.
Purge menu links from the database.
Details
__construct(Connection $connection, CacheBackendInterface $menu_cache_backend, CacheTagsInvalidatorInterface $cache_tags_invalidator, string $table, array $options = [])
Constructs a new \Drupal\Core\Menu\MenuTreeStorage.
int
maxDepth()
The maximum depth of tree the storage implementation supports.
resetDefinitions()
Clears all definitions cached in memory.
rebuild(array $definitions)
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.
protected
purgeMultiple(array $ids)
Purges multiple menu links that no longer exist.
protected StatementInterface|null
safeExecuteSelect(SelectInterface $query)
Executes a select query while making sure the database table exists.
array
save(array $link)
Saves a plugin definition to the storage.
protected array
doSave(array $link)
Saves a link without clearing caches.
protected array
preSave(array $link, array $original)
Fills in all the fields the database save needs, using the link definition.
delete(string $id)
Deletes a menu link definition from the storage.
int
getSubtreeHeight(string $id)
Finds the height of a subtree rooted by the given ID.
protected int
doFindChildrenRelativeDepth(array $original)
Finds the relative depth of this link's deepest child.
protected
setParents(array $fields, array|false $parent, array $original)
Sets the materialized path field values based on the parent.
protected
moveChildren(array $fields, array $original)
Re-parents a link's children when the link itself is moved.
protected array|false
findParent(array $link, array|false $original)
Loads the parent definition if it exists.
protected
updateParentalStatus(array $link)
Sets has_children for the link's parent if it has visible children.
protected array
prepareLink(array $link, bool $intersect = FALSE)
Prepares a link by unserializing values and saving the definition.
array
loadByProperties(array $properties)
Loads multiple plugin definitions from the storage based on properties.
array
loadByRoute(string $route_name, array $route_parameters = [], string $menu_name = NULL)
Loads multiple plugin definitions from the storage based on route.
array
loadMultiple(array $ids)
Loads multiple plugin definitions from the storage.
array|false
load(string $id)
Loads a menu link plugin definition from the storage.
protected array
loadFull(string $id)
Loads all table fields, not just those that are in the plugin definition.
protected array
loadFullMultiple(array $ids)
Loads all table fields for multiple menu link definitions by ID.
array
getRootPathIds(string $id)
Returns all the IDs that represent the path to the root of the tree.
array
getExpanded(string $menu_name, array $parents)
Finds expanded links in a menu given a set of possible parents.
protected
saveRecursive(string $id, array $children, array $links)
Saves menu links recursively.
array
loadTreeData(string $menu_name, MenuTreeParameters $parameters)
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.
protected array
loadLinks(string $menu_name, MenuTreeParameters $parameters)
Loads links in the given menu, according to the given tree parameters.
protected array
collectRoutesAndDefinitions(array $tree, array $definitions)
Traverses the menu tree and collects all the route names and definitions.
protected array
doCollectRoutesAndDefinitions(array $tree, array $definitions)
Collects all the route names and definitions.
array
loadSubtreeData(string $id, int $max_relative_depth = NULL)
Loads a subtree rooted by the given ID.
The returned links are structured like those from loadTreeData().
bool
menuNameInUse(string $menu_name)
Determines whether a specific menu name is used in the tree.
array
getMenuNames()
Returns the used menu names in the tree storage.
int
countMenuLinks(string $menu_name = NULL)
Counts the total number of menu links in one menu or all menus.
array
getAllChildIds(string $id)
Loads all the IDs for menu links that are below the given ID.
array
loadAllChildren(string $id, int $max_relative_depth = NULL)
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.
protected
doBuildTreeData(array $links, array $parents = [], $depth = 1)
Prepares the data for calling $this->treeDataRecursive().
protected array
treeDataRecursive(array $links, array $parents, int $depth)
Builds the data representing a menu tree.
The function is a bit complex because the rendering of a link depends on the next menu link.
protected bool
ensureTableExists()
Checks if the tree table exists and create it if not.
protected array
serializedFields()
Determines serialized fields in the storage.
protected array
definitionFields()
Determines fields that are part of the plugin definition.
static protected array
schemaDefinition()
| internal |
Defines the schema for the tree table.
protected array
findNoLongerExistingLinks(array $definitions)
Find any previously discovered menu links that no longer exist.
protected
doDeleteMultiple(array $ids)
Purge menu links from the database.