1.20.x layout_menu_item.class.inc | LayoutMenuItem::reassign() |
Rename this menu item to match the most appropriate layout at the same path.
If this menu item's parent layouts have been edited, reordered, or deleted the menu item may need to be reassigned to a different layout. This checks all of the layouts that match this menu item's path, and renames this menu item to match the highest weighted layout (which is usually the fallback layout at a particular path). If no layouts are associated with this particular path any more, this menu item will be deleted.
File
- modules/
layout/ includes/ layout_menu_item.class.inc, line 208 - Class for storing information about menu item entries.
Class
- LayoutMenuItem
- @file Class for storing information about menu item entries.
Code
function reassign() {
// Before reassigning, clear caches so that our layout list is up-to-date.
layout_reset_caches();
$layout_names = layout_get_path_layout_names($this->path);
// If affiliated with layouts, take the last one and match its name.
if (count($layout_names)) {
$layout_name = array_pop($layout_names);
if ($this->name != $layout_name) {
$this->delete();
$this->name = $layout_name;
$this->save();
}
}
// If no longer affiliated with any layouts, delete this menu item.
else {
$this->delete();
}
layout_reset_caches();
menu_rebuild();
}