class WorkspacesMenuTreeStorage

Same name in other branches
  1. 11.x core/modules/workspaces/src/WorkspacesMenuTreeStorage.php \Drupal\workspaces\WorkspacesMenuTreeStorage

Overrides the default menu storage to provide workspace-specific menu links.

@internal

Hierarchy

Expanded class hierarchy of WorkspacesMenuTreeStorage

1 string reference to 'WorkspacesMenuTreeStorage'
workspaces.services.yml in core/modules/workspaces/workspaces.services.yml
core/modules/workspaces/workspaces.services.yml
1 service uses WorkspacesMenuTreeStorage
workspaces.menu.tree_storage in core/modules/workspaces/workspaces.services.yml
Drupal\workspaces\WorkspacesMenuTreeStorage

File

core/modules/workspaces/src/WorkspacesMenuTreeStorage.php, line 17

Namespace

Drupal\workspaces
View source
class WorkspacesMenuTreeStorage extends CoreMenuTreeStorage {
    
    /**
     * WorkspacesMenuTreeStorage constructor.
     *
     * @param \Drupal\workspaces\WorkspaceManagerInterface $workspaceManager
     *   The workspace manager service.
     * @param \Drupal\workspaces\WorkspaceAssociationInterface $workspaceAssociation
     *   The workspace association service.
     * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
     *   The entity type manager.
     * @param \Drupal\Core\Database\Connection $connection
     *   A Database connection to use for reading and writing configuration data.
     * @param \Drupal\Core\Cache\CacheBackendInterface $menu_cache_backend
     *   Cache backend instance for the extracted tree data.
     * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
     *   The cache tags invalidator.
     * @param string $table
     *   A database table name to store configuration data in.
     * @param array $options
     *   (optional) Any additional database connection options to use in queries.
     */
    public function __construct(WorkspaceManagerInterface $workspaceManager, WorkspaceAssociationInterface $workspaceAssociation, EntityTypeManagerInterface $entityTypeManager, Connection $connection, CacheBackendInterface $menu_cache_backend, CacheTagsInvalidatorInterface $cache_tags_invalidator, string $table, array $options = []) {
        parent::__construct($connection, $menu_cache_backend, $cache_tags_invalidator, $table, $options);
    }
    
    /**
     * {@inheritdoc}
     */
    public function loadTreeData($menu_name, MenuTreeParameters $parameters) {
        // Add the active workspace as a menu tree condition parameter in order to
        // include it in the cache ID.
        if ($active_workspace = $this->workspaceManager
            ->getActiveWorkspace()) {
            $parameters->conditions['workspace'] = $active_workspace->id();
        }
        return parent::loadTreeData($menu_name, $parameters);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function loadLinks($menu_name, MenuTreeParameters $parameters) {
        $links = parent::loadLinks($menu_name, $parameters);
        // Replace the menu link plugin definitions with workspace-specific ones.
        if ($active_workspace = $this->workspaceManager
            ->getActiveWorkspace()) {
            $tracked_revisions = $this->workspaceAssociation
                ->getTrackedEntities($active_workspace->id());
            if (isset($tracked_revisions['menu_link_content'])) {
                
                /** @var \Drupal\menu_link_content\MenuLinkContentInterface[] $workspace_revisions */
                $workspace_revisions = $this->entityTypeManager
                    ->getStorage('menu_link_content')
                    ->loadMultipleRevisions(array_keys($tracked_revisions['menu_link_content']));
                foreach ($workspace_revisions as $workspace_revision) {
                    if (isset($links[$workspace_revision->getPluginId()])) {
                        $pending_plugin_definition = $workspace_revision->getPluginDefinition();
                        $links[$workspace_revision->getPluginId()] = [
                            'title' => serialize($pending_plugin_definition['title']),
                            'description' => serialize($pending_plugin_definition['description']),
                            'enabled' => (string) $pending_plugin_definition['enabled'],
                            'url' => $pending_plugin_definition['url'],
                            'route_name' => $pending_plugin_definition['route_name'],
                            'route_parameters' => serialize($pending_plugin_definition['route_parameters']),
                            'options' => serialize($pending_plugin_definition['options']),
                        ] + $links[$workspace_revision->getPluginId()];
                    }
                }
            }
        }
        return $links;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
MenuLinkFieldDefinitions::$defaults protected property Provides some default values for the definition of all menu link plugins.
MenuTreeStorage::$cacheTagsInvalidator protected property The cache tags invalidator.
MenuTreeStorage::$connection protected property The database connection.
MenuTreeStorage::$definitions protected property Stores definitions that have already been loaded for better performance.
MenuTreeStorage::$menuCacheBackend protected property Cache backend instance for the extracted tree data.
MenuTreeStorage::$options protected property Additional database connection options to use in queries.
MenuTreeStorage::$serializedFields protected property List of serialized fields.
MenuTreeStorage::$table protected property The database table name.
MenuTreeStorage::collectRoutesAndDefinitions protected function Traverses the menu tree and collects all the route names and definitions.
MenuTreeStorage::countMenuLinks public function
MenuTreeStorage::definitionFields protected function Determines fields that are part of the plugin definition.
MenuTreeStorage::delete public function
MenuTreeStorage::doBuildTreeData protected function Prepares the data for calling $this->treeDataRecursive().
MenuTreeStorage::doCollectRoutesAndDefinitions protected function Collects all the route names and definitions.
MenuTreeStorage::doDeleteMultiple protected function Purge menu links from the database.
MenuTreeStorage::doFindChildrenRelativeDepth protected function Finds the relative depth of this link's deepest child.
MenuTreeStorage::doSave protected function Saves a link without clearing caches.
MenuTreeStorage::ensureTableExists protected function Checks if the tree table exists and create it if not.
MenuTreeStorage::findNoLongerExistingLinks protected function Find any previously discovered menu links that no longer exist.
MenuTreeStorage::findParent protected function Loads the parent definition if it exists.
MenuTreeStorage::getAllChildIds public function
MenuTreeStorage::getExpanded public function
MenuTreeStorage::getMenuNames public function
MenuTreeStorage::getRootPathIds public function
MenuTreeStorage::getSubtreeHeight public function
MenuTreeStorage::load public function
MenuTreeStorage::loadAllChildren public function
MenuTreeStorage::loadByProperties public function
MenuTreeStorage::loadByRoute public function
MenuTreeStorage::loadFull protected function Loads all table fields, not just those that are in the plugin definition.
MenuTreeStorage::loadFullMultiple protected function Loads all table fields for multiple menu link definitions by ID.
MenuTreeStorage::loadMultiple public function
MenuTreeStorage::loadSubtreeData public function
MenuTreeStorage::maxDepth public function
MenuTreeStorage::MAX_DEPTH constant The maximum depth of a menu links tree.
MenuTreeStorage::menuNameInUse public function
MenuTreeStorage::moveChildren protected function Re-parents a link's children when the link itself is moved.
MenuTreeStorage::prepareLink protected function Prepares a link by unserializing values and saving the definition.
MenuTreeStorage::preSave protected function Fills in all the fields the database save needs, using the link definition.
MenuTreeStorage::purgeMultiple protected function Purges multiple menu links that no longer exist.
MenuTreeStorage::rebuild public function
MenuTreeStorage::resetDefinitions public function
MenuTreeStorage::safeExecuteSelect protected function Executes a select query while making sure the database table exists.
MenuTreeStorage::save public function
MenuTreeStorage::saveRecursive protected function Saves menu links recursively.
MenuTreeStorage::schemaDefinition protected static function Defines the schema for the tree table.
MenuTreeStorage::serializedFields protected function Determines serialized fields in the storage.
MenuTreeStorage::setParents protected function Sets the materialized path field values based on the parent.
MenuTreeStorage::treeDataRecursive protected function Builds the data representing a menu tree.
MenuTreeStorage::updateParentalStatus protected function Sets has_children for the link's parent if it has visible children.
WorkspacesMenuTreeStorage::loadLinks protected function Loads links in the given menu, according to the given tree parameters. Overrides MenuTreeStorage::loadLinks
WorkspacesMenuTreeStorage::loadTreeData public function Overrides MenuTreeStorage::loadTreeData
WorkspacesMenuTreeStorage::__construct public function WorkspacesMenuTreeStorage constructor. Overrides MenuTreeStorage::__construct

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.