Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/menu_ui/menu_ui.module @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children | 12f9dff5fda9 |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
73 ->setLinkTemplate('add-link-form', '/admin/structure/menu/manage/{menu}/add') | 73 ->setLinkTemplate('add-link-form', '/admin/structure/menu/manage/{menu}/add') |
74 ->setLinkTemplate('collection', '/admin/structure/menu'); | 74 ->setLinkTemplate('collection', '/admin/structure/menu'); |
75 | 75 |
76 if (isset($entity_types['node'])) { | 76 if (isset($entity_types['node'])) { |
77 $entity_types['node']->addConstraint('MenuSettings', []); | 77 $entity_types['node']->addConstraint('MenuSettings', []); |
78 } | |
79 } | |
80 | |
81 /** | |
82 * Implements hook_ENTITY_TYPE_insert( for menu entities. | |
83 */ | |
84 function menu_ui_menu_insert(Menu $menu) { | |
85 menu_cache_clear_all(); | |
86 // Invalidate the block cache to update menu-based derivatives. | |
87 if (\Drupal::moduleHandler()->moduleExists('block')) { | |
88 \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); | |
89 } | |
90 } | |
91 | |
92 /** | |
93 * Implements hook_ENTITY_TYPE_update() for menu entities. | |
94 */ | |
95 function menu_ui_menu_update(Menu $menu) { | |
96 menu_cache_clear_all(); | |
97 // Invalidate the block cache to update menu-based derivatives. | |
98 if (\Drupal::moduleHandler()->moduleExists('block')) { | |
99 \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); | |
100 } | |
101 } | |
102 | |
103 /** | |
104 * Implements hook_ENTITY_TYPE_predelete() for menu entities. | |
105 */ | |
106 function menu_ui_menu_predelete(Menu $menu) { | |
107 // Delete all links from the menu. | |
108 /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */ | |
109 $menu_link_manager = \Drupal::service('plugin.manager.menu.link'); | |
110 $menu_link_manager->deleteLinksInMenu($menu->id()); | |
111 } | |
112 | |
113 /** | |
114 * Implements hook_ENTITY_TYPE_delete() for menu entities. | |
115 */ | |
116 function menu_ui_menu_delete(Menu $menu) { | |
117 menu_cache_clear_all(); | |
118 | |
119 // Invalidate the block cache to update menu-based derivatives. | |
120 if (\Drupal::moduleHandler()->moduleExists('block')) { | |
121 \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); | |
122 } | 78 } |
123 } | 79 } |
124 | 80 |
125 /** | 81 /** |
126 * Implements hook_block_view_BASE_BLOCK_ID_alter() for 'system_menu_block'. | 82 * Implements hook_block_view_BASE_BLOCK_ID_alter() for 'system_menu_block'. |
218 'entity_id' => $menu_link->id(), | 174 'entity_id' => $menu_link->id(), |
219 'id' => $menu_link->getPluginId(), | 175 'id' => $menu_link->getPluginId(), |
220 'title' => $menu_link->getTitle(), | 176 'title' => $menu_link->getTitle(), |
221 'title_max_length' => $menu_link->getFieldDefinitions()['title']->getSetting('max_length'), | 177 'title_max_length' => $menu_link->getFieldDefinitions()['title']->getSetting('max_length'), |
222 'description' => $menu_link->getDescription(), | 178 'description' => $menu_link->getDescription(), |
179 'description_max_length' => $menu_link->getFieldDefinitions()['description']->getSetting('max_length'), | |
223 'menu_name' => $menu_link->getMenuName(), | 180 'menu_name' => $menu_link->getMenuName(), |
224 'parent' => $menu_link->getParentId(), | 181 'parent' => $menu_link->getParentId(), |
225 'weight' => $menu_link->getWeight(), | 182 'weight' => $menu_link->getWeight(), |
226 ]; | 183 ]; |
227 } | 184 } |
230 if (!$defaults) { | 187 if (!$defaults) { |
231 // Get the default max_length of a menu link title from the base field | 188 // Get the default max_length of a menu link title from the base field |
232 // definition. | 189 // definition. |
233 $field_definitions = \Drupal::entityManager()->getBaseFieldDefinitions('menu_link_content'); | 190 $field_definitions = \Drupal::entityManager()->getBaseFieldDefinitions('menu_link_content'); |
234 $max_length = $field_definitions['title']->getSetting('max_length'); | 191 $max_length = $field_definitions['title']->getSetting('max_length'); |
192 $description_max_length = $field_definitions['description']->getSetting('max_length'); | |
235 $defaults = [ | 193 $defaults = [ |
236 'entity_id' => 0, | 194 'entity_id' => 0, |
237 'id' => '', | 195 'id' => '', |
238 'title' => '', | 196 'title' => '', |
239 'title_max_length' => $max_length, | 197 'title_max_length' => $max_length, |
240 'description' => '', | 198 'description' => '', |
199 'description_max_length' => $description_max_length, | |
241 'menu_name' => $menu_name, | 200 'menu_name' => $menu_name, |
242 'parent' => '', | 201 'parent' => '', |
243 'weight' => 0, | 202 'weight' => 0, |
244 ]; | 203 ]; |
245 } | 204 } |
260 $defaults = menu_ui_get_menu_link_defaults($node); | 219 $defaults = menu_ui_get_menu_link_defaults($node); |
261 /** @var \Drupal\node\NodeTypeInterface $node_type */ | 220 /** @var \Drupal\node\NodeTypeInterface $node_type */ |
262 $node_type = $node->type->entity; | 221 $node_type = $node->type->entity; |
263 /** @var \Drupal\Core\Menu\MenuParentFormSelectorInterface $menu_parent_selector */ | 222 /** @var \Drupal\Core\Menu\MenuParentFormSelectorInterface $menu_parent_selector */ |
264 $menu_parent_selector = \Drupal::service('menu.parent_form_selector'); | 223 $menu_parent_selector = \Drupal::service('menu.parent_form_selector'); |
265 $menu_names = menu_ui_get_menus(); | 224 $type_menus_ids = $node_type->getThirdPartySetting('menu_ui', 'available_menus', ['main']); |
266 $type_menus = $node_type->getThirdPartySetting('menu_ui', 'available_menus', ['main']); | 225 if (empty($type_menus_ids)) { |
226 return; | |
227 } | |
228 /** @var \Drupal\system\MenuInterface[] $type_menus */ | |
229 $type_menus = Menu::loadMultiple($type_menus_ids); | |
267 $available_menus = []; | 230 $available_menus = []; |
268 foreach ($type_menus as $menu) { | 231 foreach ($type_menus as $menu) { |
269 $available_menus[$menu] = $menu_names[$menu]; | 232 $available_menus[$menu->id()] = $menu->label(); |
270 } | 233 } |
271 if ($defaults['id']) { | 234 if ($defaults['id']) { |
272 $default = $defaults['menu_name'] . ':' . $defaults['parent']; | 235 $default = $defaults['menu_name'] . ':' . $defaults['parent']; |
273 } | 236 } |
274 else { | 237 else { |
319 '#default_value' => $defaults['title'], | 282 '#default_value' => $defaults['title'], |
320 '#maxlength' => $defaults['title_max_length'], | 283 '#maxlength' => $defaults['title_max_length'], |
321 ]; | 284 ]; |
322 | 285 |
323 $form['menu']['link']['description'] = [ | 286 $form['menu']['link']['description'] = [ |
324 '#type' => 'textarea', | 287 '#type' => 'textfield', |
325 '#title' => t('Description'), | 288 '#title' => t('Description'), |
326 '#default_value' => $defaults['description'], | 289 '#default_value' => $defaults['description'], |
327 '#rows' => 1, | |
328 '#description' => t('Shown when hovering over the menu link.'), | 290 '#description' => t('Shown when hovering over the menu link.'), |
291 '#maxlength' => $defaults['description_max_length'], | |
329 ]; | 292 ]; |
330 | 293 |
331 $form['menu']['link']['menu_parent'] = $parent_element; | 294 $form['menu']['link']['menu_parent'] = $parent_element; |
332 $form['menu']['link']['menu_parent']['#title'] = t('Parent item'); | 295 $form['menu']['link']['menu_parent']['#title'] = t('Parent item'); |
333 $form['menu']['link']['menu_parent']['#attributes']['class'][] = 'menu-parent-select'; | 296 $form['menu']['link']['menu_parent']['#attributes']['class'][] = 'menu-parent-select'; |
494 if ($variables['configuration']['provider'] == 'menu_ui') { | 457 if ($variables['configuration']['provider'] == 'menu_ui') { |
495 $variables['attributes']['role'] = 'navigation'; | 458 $variables['attributes']['role'] = 'navigation'; |
496 } | 459 } |
497 } | 460 } |
498 | 461 |
499 | |
500 /** | 462 /** |
501 * Implements hook_system_breadcrumb_alter(). | 463 * Implements hook_system_breadcrumb_alter(). |
502 */ | 464 */ |
503 function menu_ui_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInterface $route_match, array $context) { | 465 function menu_ui_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInterface $route_match, array $context) { |
504 // Custom breadcrumb behavior for editing menu links, we append a link to | 466 // Custom breadcrumb behavior for editing menu links, we append a link to |