class MiconStaticMenuLinkOverrides in Micon 8
Same name and namespace in other branches
- 2.x micon_menu/src/MiconStaticMenuLinkOverrides.php \Drupal\micon_menu\MiconStaticMenuLinkOverrides
Defines an implementation of the menu link override using a config file.
Hierarchy
- class \Drupal\Core\Menu\StaticMenuLinkOverrides implements StaticMenuLinkOverridesInterface
- class \Drupal\micon_menu\MiconStaticMenuLinkOverrides
Expanded class hierarchy of MiconStaticMenuLinkOverrides
File
- micon_menu/
src/ MiconStaticMenuLinkOverrides.php, line 10
Namespace
Drupal\micon_menuView source
class MiconStaticMenuLinkOverrides extends StaticMenuLinkOverrides {
/**
* {@inheritdoc}
*/
public function saveOverride($id, array $definition) {
// Only allow to override a specific subset of the keys.
$expected = [
'menu_name' => '',
'parent' => '',
'weight' => 0,
'expanded' => FALSE,
'enabled' => FALSE,
// Micon: options are allowed.
'options' => [],
];
// Filter the overrides to only those that are expected.
$definition = array_intersect_key($definition, $expected);
// Ensure all values are set.
$definition = $definition + $expected;
if ($definition) {
// Cast keys to avoid config schema during save.
$definition['menu_name'] = (string) $definition['menu_name'];
$definition['parent'] = (string) $definition['parent'];
$definition['weight'] = (int) $definition['weight'];
$definition['expanded'] = (bool) $definition['expanded'];
$definition['enabled'] = (bool) $definition['enabled'];
// Micon: options are allowed.
$definition['options'] = $definition['options'];
$id = static::encodeId($id);
$all_overrides = $this
->getConfig()
->get('definitions');
// Combine with any existing data.
$all_overrides[$id] = $definition + $this
->loadOverride($id);
$this
->getConfig()
->set('definitions', $all_overrides)
->save(TRUE);
}
return array_keys($definition);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MiconStaticMenuLinkOverrides:: |
public | function |
Saves the override. Overrides StaticMenuLinkOverrides:: |
|
StaticMenuLinkOverrides:: |
protected | property | The menu link overrides config object. | |
StaticMenuLinkOverrides:: |
protected | property | The config factory object. | |
StaticMenuLinkOverrides:: |
protected | property | The config name used to store the overrides. | |
StaticMenuLinkOverrides:: |
public | function |
Deletes multiple overrides to definitions of static (YAML-defined) links. Overrides StaticMenuLinkOverridesInterface:: |
|
StaticMenuLinkOverrides:: |
public | function |
Deletes any overrides to the definition of a static (YAML-defined) link. Overrides StaticMenuLinkOverridesInterface:: |
|
StaticMenuLinkOverrides:: |
protected static | function | Encodes the ID by replacing dots with double underscores. | |
StaticMenuLinkOverrides:: |
public | function |
The unique cache tag associated with this menu link override. Overrides StaticMenuLinkOverridesInterface:: |
|
StaticMenuLinkOverrides:: |
protected | function | Gets the configuration object when needed. | |
StaticMenuLinkOverrides:: |
public | function |
Loads overrides to multiple definitions of a static (YAML-defined) link. Overrides StaticMenuLinkOverridesInterface:: |
|
StaticMenuLinkOverrides:: |
public | function |
Loads any overrides to the definition of a static (YAML-defined) link. Overrides StaticMenuLinkOverridesInterface:: |
|
StaticMenuLinkOverrides:: |
public | function |
Reloads the overrides from config. Overrides StaticMenuLinkOverridesInterface:: |
|
StaticMenuLinkOverrides:: |
public | function | Constructs a StaticMenuLinkOverrides object. |