public function MenuPositionLink::getDerivativeDefinitions in Menu Position 8
Gets the definition of all derivatives of a base plugin.
Parameters
array $base_plugin_definition: The definition array of the base plugin.
Return value
array An array of full derivative definitions keyed on derivative id.
Overrides DeriverBase::getDerivativeDefinitions
See also
getDerivativeDefinition()
File
- src/
Plugin/ Derivative/ MenuPositionLink.php, line 64
Class
- MenuPositionLink
- Provides menu links for Menu Position Rules.
Namespace
Drupal\menu_position\Plugin\DerivativeCode
public function getDerivativeDefinitions($base_plugin_definition) {
// Reset the discovered definitions.
$this->derivatives = [];
foreach ($this->storage
->loadMultiple() as $menu_position_rule) {
/* @var \Drupal\menu_position\Entity\MenuPositionRule $menu_position_rule */
/* @var \Drupal\menu_position\Plugin\Menu\MenuPositionLink $menu_link */
if ($menu_link = $menu_position_rule
->getMenuLinkPlugin()) {
// Link already exists, use that.
$definition = $menu_link
->getPluginDefinition();
}
else {
// Provide defaults, they will be updated by the rule.
$definition = [
'id' => $base_plugin_definition['id'] . ':' . $menu_position_rule
->id(),
'title' => $this
->t('@label (menu position rule)', [
'@label' => $menu_position_rule
->getLabel(),
]),
'menu_name' => $menu_position_rule
->getMenuName(),
'parent' => $menu_position_rule
->getParent(),
'weight' => 0,
'metadata' => [
'entity_id' => $menu_position_rule
->id(),
],
// Links are enabled (i.e. visible) depending on the modules'
// settings.
'enabled' => $this->config_factory
->get('menu_position.settings')
->get('link_display') === 'child',
];
}
$this->derivatives[$menu_position_rule
->id()] = $definition + $base_plugin_definition;
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}