public StaticMenuLinkOverrides::saveOverride($id, array $definition)
Saves the override.
Parameters
string $id: A menu link plugin ID.
array $definition: The definition values to override. Supported keys:
- menu_name
- parent
- weight
- expanded
- enabled
Return value
array A list of properties which got saved.
Overrides StaticMenuLinkOverridesInterface::saveOverride
File
- core/lib/Drupal/Core/Menu/StaticMenuLinkOverrides.php, line 125
Class
- StaticMenuLinkOverrides
- Defines an implementation of the menu link override using a config file.
Namespace
Drupal\Core\Menu
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | public function saveOverride( $id , array $definition ) { // Only allow to override a specific subset of the keys. $expected = array ( 'menu_name' => '' , 'parent' => '' , 'weight' => 0, 'expanded' => FALSE, 'enabled' => FALSE, ); // 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' ]; $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 ); } |
Please login to continue.