toolbar_menu.install in Toolbar Menu 8
Same filename and directory in other branches
Contains installation and update hooks..
File
toolbar_menu.installView source
<?php
/**
* @file
* Contains installation and update hooks..
*/
/**
* Transform all current toolbar_menu items to toolbar_menu_element entities.
*/
function toolbar_menu_update_8001() {
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = \Drupal::service('config.factory');
/** @var \Drupal\Core\Entity\EntityTypeManager $entity_manager */
$entity_manager = \Drupal::service('entity_type.manager');
// Load old configuration and create a toolbar_menu_element entity
// if is active.
foreach ($config_factory
->get('toolbar_menu.settings')
->get('menus') as $menu_name => $menu_config) {
if ($menu_config['active'] == TRUE && !$entity_manager
->getStorage('toolbar_menu_element')
->load($menu_name)) {
$entity_manager
->getStorage('toolbar_menu_element')
->create([
'id' => $menu_name,
'label' => $menu_name,
'menu' => $menu_name,
'weight' => $menu_config['weight'],
'rewrite_label' => TRUE,
])
->save();
}
}
// Delete old and deprecated configuration.
$config_factory
->getEditable('toolbar_menu.settings')
->delete();
}
Functions
Name | Description |
---|---|
toolbar_menu_update_8001 | Transform all current toolbar_menu items to toolbar_menu_element entities. |