function MenuUiHooks::menuDelete
Implements hook_ENTITY_TYPE_delete().
Attributes
#[Hook('menu_delete')]
File
-
core/
modules/ menu_ui/ src/ Hook/ MenuUiHooks.php, line 298
Class
- MenuUiHooks
- Hook implementations for menu_ui.
Namespace
Drupal\menu_ui\HookCode
public function menuDelete(EntityInterface $entity) : void {
if (!$this->entityTypeManager
->hasDefinition('node_type')) {
return;
}
// Remove the menu from content type third party settings.
$menu_id = $entity->id();
$parent_prefix = $menu_id . ':';
$storage = $this->entityTypeManager
->getStorage('node_type');
foreach ($storage->loadMultiple() as $content_type) {
$third_party_settings = $original_third_party_settings = $content_type->getThirdPartySettings('menu_ui');
if (isset($third_party_settings['available_menus']) && in_array($menu_id, $third_party_settings['available_menus'])) {
$key = array_search($menu_id, $third_party_settings['available_menus']);
if ($key !== FALSE) {
unset($third_party_settings['available_menus'][$key]);
}
$content_type->setThirdPartySetting('menu_ui', 'available_menus', $third_party_settings['available_menus']);
}
if (isset($third_party_settings['parent']) && substr($third_party_settings['parent'], 0, strlen($parent_prefix)) == $parent_prefix) {
$third_party_settings['parent'] = '';
$content_type->setThirdPartySetting('menu_ui', 'parent', $third_party_settings['parent']);
}
if ($third_party_settings != $original_third_party_settings) {
$content_type->save();
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.