- <?php
- * @file
- * Allows administrators to customize the site's menus.
- *
- * A menu (in this context) is a hierarchical collection of links, generally
- * used for navigation. This is not to be confused with the
- * @link menu Menu system @endlink of menu.inc and hook_menu(), which defines
- * page routing requests for Backdrop. The menu system also allows the defined
- * page routing URLs to be added to these menus.
- */
-
- * Maximum length of menu name as entered by the user. Database length is 32
- * and we add a menu- prefix.
- */
- define('MENU_MAX_MENU_NAME_LENGTH_UI', 27);
-
- * Implements hook_permission().
- */
- function menu_permission() {
- return array(
- 'administer menu' => array(
- 'title' => t('Administer menus and menu items'),
- ),
- );
- }
-
- * Implements hook_menu().
- */
- function menu_menu() {
- $items['admin/structure/menu'] = array(
- 'title' => 'Menus',
- 'description' => 'Add new menus to your site, edit existing menus, and rename and reorganize menu links.',
- 'page callback' => 'menu_overview_page',
- 'access arguments' => array('administer menu'),
- 'file' => 'menu.admin.inc',
- );
- $items['admin/structure/menu/parents'] = array(
- 'title' => 'Parent menu items',
- 'page callback' => 'menu_parent_options_js',
- 'delivery callback' => 'backdrop_json_deliver',
- 'type' => MENU_CALLBACK,
- 'access arguments' => array('administer menu'),
- );
- $items['admin/structure/menu/list'] = array(
- 'title' => 'List menus',
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => -10,
- );
- $items['admin/structure/menu/add'] = array(
- 'title' => 'Add menu',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('menu_edit_menu', 'add'),
- 'access arguments' => array('administer menu'),
- 'type' => MENU_LOCAL_ACTION,
- 'file' => 'menu.admin.inc',
- );
- $items['admin/structure/menu/manage/%menu'] = array(
- 'title' => 'Edit links',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('menu_overview_form', 4),
- 'title callback' => 'menu_overview_title',
- 'title arguments' => array(4),
- 'access arguments' => array('administer menu'),
- 'file' => 'menu.admin.inc',
- );
- $items['admin/structure/menu/manage/%menu/list'] = array(
- 'title' => 'Edit links',
- 'weight' => -10,
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
- );
- $items['admin/structure/menu/manage/%menu/add'] = array(
- 'title' => 'Add link',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('menu_edit_item', 'add', NULL, 4),
- 'access arguments' => array('administer menu'),
- 'type' => MENU_LOCAL_ACTION,
- 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
- 'file' => 'menu.admin.inc',
- );
- $items['admin/structure/menu/manage/%menu/configure'] = array(
- 'title' => 'Configure menu',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('menu_edit_menu', 'configure', 4),
- 'access arguments' => array('administer menu'),
- 'type' => MENU_LOCAL_TASK,
- 'context' => MENU_CONTEXT_PAGE,
- 'file' => 'menu.admin.inc',
- );
- $items['admin/structure/menu/manage/%menu/delete'] = array(
- 'title' => 'Delete menu',
- 'page callback' => 'menu_delete_menu_page',
- 'page arguments' => array(4),
- 'access arguments' => array('administer menu'),
- 'file' => 'menu.admin.inc',
- );
- $items['admin/structure/menu/item/%menu_link/edit'] = array(
- 'title' => 'Edit link',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('menu_edit_item', 'edit', 4, NULL),
- 'access arguments' => array('administer menu'),
- 'file' => 'menu.admin.inc',
- );
- $items['admin/structure/menu/item/%menu_link/reset'] = array(
- 'title' => 'Reset menu link',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('menu_reset_item_confirm', 4),
- 'access arguments' => array('administer menu'),
- 'file' => 'menu.admin.inc',
- );
- $items['admin/structure/menu/item/%menu_link/delete'] = array(
- 'title' => 'Delete menu link',
- 'page callback' => 'menu_item_delete_page',
- 'page arguments' => array(4),
- 'access arguments' => array('administer menu'),
- 'file' => 'menu.admin.inc',
- );
- $items['admin/structure/menu/settings'] = array(
- 'title' => 'Menu settings',
- 'description' => 'Configure global settings for menus.',
- 'page callback' => 'backdrop_get_form',
- 'page arguments' => array('menu_settings_form'),
- 'access arguments' => array('administer menu'),
- 'type' => MENU_LOCAL_TASK,
- 'file' => 'menu.admin.inc',
- 'weight' => 99,
- );
- return $items;
- }
-
- * Implements hook_theme().
- */
- function menu_theme() {
- $base = array(
- 'file' => 'menu.theme.inc',
- );
-
- return array(
- 'menu_overview_form' => array(
- 'render element' => 'form',
- ) + $base,
- 'menu_admin_overview' => array(
- 'variables' => array('title' => NULL, 'name' => NULL, 'description' => NULL),
- ) + $base,
- );
- }
-
- * Implements hook_config_info().
- */
- function menu_config_info() {
- $prefixes['menu.menu'] = array(
- 'name_key' => 'menu_name',
- 'label_key' => 'title',
- 'group' => t('Menus'),
- );
- $prefixes['menu.settings'] = array(
- 'label' => t('Menu settings'),
- 'group' => t('Menus'),
- );
- return $prefixes;
- }
-
- * Implements hook_enable().
- *
- * Add a link for each custom menu.
- */
- function menu_enable() {
- menu_rebuild();
- $base_link = db_query("SELECT mlid AS plid, menu_name FROM {menu_links} WHERE link_path = 'admin/structure/menu' AND module = 'system'")->fetchAssoc();
- $base_link['router_path'] = 'admin/structure/menu/manage/%';
- $base_link['module'] = 'menu';
- $menus = menu_load_all();
- foreach ($menus as $menu) {
-
- $link = $base_link;
- $link['mlid'] = 0;
- $link['link_title'] = $menu['title'];
- $link['link_path'] = 'admin/structure/menu/manage/' . $menu['menu_name'];
- $menu_link = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND plid = :plid", array(
- ':path' => $link['link_path'],
- ':plid' => $link['plid']
- ))
- ->fetchField();
- if (!$menu_link) {
- menu_link_save($link);
- }
- }
- menu_cache_clear_all();
- }
-
- * Title callback for the menu overview page and links.
- */
- function menu_overview_title($menu) {
- return $menu['title'];
- }
-
- * Load the data for a single custom menu.
- *
- * @param $menu_name
- * The unique name of a custom menu to load.
- * @return
- * Array defining the custom menu, or FALSE if the menu doesn't exist.
- */
- function menu_load($menu_name) {
- $all_menus = menu_load_all();
- return isset($all_menus[$menu_name]) ? $all_menus[$menu_name] : FALSE;
- }
-
- * Load all custom menu data.
- *
- * @return
- * Array of custom menu data.
- */
- function menu_load_all() {
- $custom_menus = &backdrop_static(__FUNCTION__);
- if (!isset($custom_menus)) {
- if ($cached = cache('menu')->get('menu_configs')) {
- $custom_menus = $cached->data;
- }
- else {
- $config_names = config_get_names_with_prefix('menu.menu.');
- foreach ($config_names as $config_name) {
- $menu = config_get($config_name);
- $custom_menus[$menu['menu_name']] = $menu;
- }
- cache('menu')->set('menu_configs', $custom_menus);
- }
- }
- return $custom_menus;
- }
-
- * Save a custom menu.
- *
- * @param $menu
- * An array representing a custom menu:
- * - menu_name: The unique name of the custom menu (composed of lowercase
- * letters, numbers, and hyphens).
- * - title: The human readable menu title.
- * - description: The custom menu description.
- *
- * Modules should always pass a fully populated $menu when saving a custom
- * menu, so other modules are able to output proper status or watchdog messages.
- *
- * @see menu_load()
- */
- function menu_save($menu) {
- $menu_defaults = array(
- 'menu_name' => '',
- 'title' => '',
- 'description' => '',
- );
- $menu += $menu_defaults;
- $menu = array_intersect_key($menu, $menu_defaults);
-
- $config = config('menu.menu.' . $menu['menu_name']);
- $status = $config->isNew() ? SAVED_NEW : SAVED_UPDATED;
- $config->setData($menu);
- $config->save();
- menu_cache_clear_all();
-
- switch ($status) {
- case SAVED_NEW:
-
-
-
- $config = config('system.core');
-
- $active_menus = $config->get('active_menus_default') ?: array_keys(menu_get_menus());
- if (!in_array($menu['menu_name'], $active_menus)) {
- $active_menus[] = $menu['menu_name'];
- $config->set('active_menus_default', $active_menus)->save();
- }
-
- module_invoke_all('menu_insert', $menu);
- break;
-
- case SAVED_UPDATED:
- module_invoke_all('menu_update', $menu);
- break;
- }
- }
-
- * Delete a custom menu and all contained links.
- *
- * Note that this function deletes all menu links in a custom menu. While menu
- * links derived from router paths may be restored by rebuilding the menu, all
- * customized and custom links will be irreversibly gone. Therefore, this
- * function should usually be called from a user interface (form submit) handler
- * only, which allows the user to confirm the action.
- *
- * @param $menu
- * An array representing a custom menu:
- * - menu_name: The unique name of the custom menu.
- * - title: The human readable menu title.
- * - description: The custom menu description.
- *
- * Modules should always pass a fully populated $menu when deleting a custom
- * menu, so other modules are able to output proper status or watchdog messages.
- *
- * @see menu_load()
- *
- * menu_delete_links() will take care of clearing the page cache. Other modules
- * should take care of their menu-related data by implementing
- * hook_menu_delete().
- */
- function menu_delete($menu) {
- $config = config('system.core');
-
-
- menu_delete_links($menu['menu_name']);
-
-
- $active_menus = $config->get('active_menus_default') ?: array_keys(menu_get_menus());
- foreach ($active_menus as $i => $menu_name) {
- if ($menu['menu_name'] == $menu_name) {
- unset($active_menus[$i]);
- $config->set('active_menus_default', $active_menus)->save();
- }
- }
-
-
- config('menu.menu.' . $menu['menu_name'])->delete();
-
- menu_cache_clear_all();
- module_invoke_all('menu_delete', $menu);
- }
-
- * Return a list of menu items that are valid possible parents for the given menu item.
- *
- * @param $menus
- * An array of menu names and titles, such as from menu_get_menus().
- * @param $item
- * The menu item or the node type for which to generate a list of parents.
- * If $item['mlid'] == 0 then the complete tree is returned.
- * @param $type
- * The node type for which to generate a list of parents.
- * If $item itself is a node type then $type is ignored.
- * @return
- * An array of menu link titles keyed on the a string containing the menu name
- * and mlid. The list excludes the given item and its children.
- */
- function menu_parent_options($menus, $item, $type = '') {
- $available_menus = array();
- if (!is_array($item)) {
-
-
- $type = $item;
- $item = array('mlid' => 0);
- }
- if (empty($type)) {
-
- $available_menus = $menus;
- }
- else {
-
- $node_type = node_type_load($type);
- foreach ($node_type->settings['menu_options'] as $menu) {
- $available_menus[$menu] = $menu;
- }
- }
-
- return _menu_get_options($menus, $available_menus, $item);
- }
-
- * Page callback.
- * Get all the available menus and menu items as a JavaScript array.
- */
- function menu_parent_options_js() {
- $available_menus = array();
- if (isset($_POST['menus']) && count($_POST['menus'])) {
- foreach ($_POST['menus'] as $menu) {
- $available_menus[$menu] = $menu;
- }
- }
- $options = _menu_get_options(menu_get_menus(), $available_menus, array('mlid' => 0));
-
-
- return $options;
- }
-
- * Ajax callback to replace the menu item parent options.
- *
- * Whenever the item language changes, the available parents also have to get
- * updated.
- *
- * @see menu_edit_item().
- * @see menu_form_node_form_alter().
- */
- function menu_update_parent_options_ajax($form, $form_state) {
- if ($form['#form_id'] == 'menu_edit_item') {
- $item = $form['original_item']['#value'];
- if (isset($form_state['values']['langcode'])) {
- $item['langcode'] = $form_state['values']['langcode'];
- $form['parent']['#options'] = menu_parent_options(menu_get_menus(), $item);
- }
- return $form['parent'];
- }
- elseif (isset($form['#node'])) {
- $item = $form['#node']->menu;
- if (isset($form_state['values']['langcode'])) {
- $item['langcode'] = $form_state['values']['langcode'];
- $form['menu']['link']['parent']['#options'] = menu_parent_options(menu_get_menus(), $item, $form['#node']->type);
- }
- return $form['menu']['link']['parent'];
- }
- }
-
- * Helper function to get the items of the given menu.
- */
- function _menu_get_options($menus, $available_menus, $item) {
-
- if (isset($item['parent_depth_limit'])) {
- $limit = $item['parent_depth_limit'];
- }
- else {
- $limit = _menu_parent_depth_limit($item);
- }
-
- $options = array();
- $langcode = NULL;
- if (module_exists('language') && isset($item['langcode'])) {
- $langcode = $item['langcode'];
- }
- foreach ($menus as $menu_name => $title) {
- if (isset($available_menus[$menu_name])) {
- $tree = menu_tree_all_data($menu_name, NULL, NULL, $langcode);
- $options[$menu_name . ':0'] = $title;
- _menu_parents_recurse($tree, $menu_name, '· ', $options, $item['mlid'], $limit);
- }
- }
- return $options;
- }
-
- * Recursive helper function for menu_parent_options().
- */
- function _menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, $depth_limit) {
- foreach ($tree as $data) {
- if ($data['link']['depth'] > $depth_limit) {
-
- break;
- }
- if ($data['link']['mlid'] != $exclude && $data['link']['hidden'] >= 0) {
- $title = $indent . ' ' . truncate_utf8($data['link']['title'], 30, TRUE, FALSE);
- if ($data['link']['hidden']) {
- $title .= ' (' . t('disabled') . ')';
- }
- $options[$menu_name . ':' . $data['link']['mlid']] = $title;
- if ($data['below']) {
- _menu_parents_recurse($data['below'], $menu_name, $indent . '· ', $options, $exclude, $depth_limit);
- }
- }
- }
- }
-
- * Reset a system-defined menu link.
- */
- function menu_reset_item($link) {
-
-
-
-
-
- $menu = menu_get_router();
- $router_item = $menu[$link['router_path']];
- $new_link = _menu_link_build($router_item);
-
- foreach (array('mlid', 'has_children') as $key) {
- $new_link[$key] = $link[$key];
- }
- menu_link_save($new_link);
- return $new_link;
- }
-
- * Implements hook_block_info().
- */
- function menu_block_info() {
- $menus = menu_get_menus(FALSE);
-
- $blocks = array();
- foreach ($menus as $name => $title) {
- $blocks[$name] = array(
-
-
- 'info' => check_plain($title),
- 'description' => t('A list of links for the menu: %title.', array('%title' => $title)),
-
-
- 'cache' => BACKDROP_NO_CACHE,
- );
- }
- return $blocks;
- }
-
- * Implements hook_block_view().
- */
- function menu_block_view($delta = '', $settings = array()) {
- module_load_include('inc', 'system', 'system.menu');
- $settings += system_menu_block_defaults($delta);
- $data = system_menu_block_build($settings);
- $block['subject'] = $data['subject'];
- $block['content'] = $data['content'];
-
- if (!empty($block['content'])) {
- $block['content']['#contextual_links']['menu'] = array('admin/structure/menu/manage', array($delta));
- }
- return $block;
- }
-
- * Implements hook_block_configure().
- */
- function menu_block_configure($delta, $settings) {
- foreach (menu_get_menus(FALSE) as $menu_name => $title) {
- if ($delta === $menu_name) {
- module_load_include('inc', 'system', 'system.menu');
- return _system_block_configure($delta, $settings);
- }
- }
- }
-
- * Implements hook_block_view_alter().
- */
- function menu_block_view_alter(&$data, $block) {
-
- if ($block->module == 'system' && !empty($data['content'])) {
- $system_menus = menu_list_system_menus();
- if (isset($system_menus[$block->delta])) {
- $data['content']['#contextual_links']['menu'] = array('admin/structure/menu/manage', array($block->delta));
- }
- }
- }
-
- * Implements hook_menu_local_tasks_alter().
- */
- function menu_menu_local_tasks_alter(&$data, $router_item, $root_path) {
-
-
- if ($root_path == 'admin/structure/menu/manage/%') {
- foreach ($data['actions']['output'] as $key => $action_link) {
- if ($action_link['#link']['path'] === 'admin/structure/menu/manage/%/add') {
- $default_langcode = isset($_GET['langcode']) ? $_GET['langcode'] : LANGUAGE_NONE;
- $query['langcode'] = $default_langcode;
- $data['actions']['output'][$key]['#link']['localized_options'] = array('query' => $query);
- }
- }
- }
- }
-
- * Implements hook_node_insert().
- */
- function menu_node_insert(Node $node) {
- menu_node_save($node);
- }
-
- * Implements hook_node_update().
- */
- function menu_node_update(Node $node) {
- menu_node_save($node);
- }
-
- * Helper for hook_node_insert() and hook_node_update().
- */
- function menu_node_save(Node $node) {
- if (isset($node->menu)) {
- $link = &$node->menu;
- if (isset($link['enabled']) && !$link['enabled']) {
- if (!empty($link['mlid'])) {
- menu_link_delete($link['mlid']);
- }
- }
- elseif (trim($link['link_title'])) {
- $link['link_title'] = trim($link['link_title']);
- $link['link_path'] = "node/$node->nid";
- $link['langcode'] = $node->langcode;
- if (trim($link['description'])) {
- $link['options']['attributes']['title'] = trim($link['description']);
- }
- else {
-
-
- unset($link['options']['attributes']['title']);
- }
- if (!menu_link_save($link)) {
- backdrop_set_message(t('There was an error saving the menu link.'), 'error');
- }
- }
- }
- }
-
- * Implements hook_node_predelete().
- */
- function menu_node_predelete(Node $node) {
-
- $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu'", array(':path' => 'node/' . $node->nid), array('fetch' => PDO::FETCH_ASSOC));
- foreach ($result as $m) {
- menu_link_delete($m['mlid']);
- }
- }
-
- * Implements hook_node_prepare().
- */
- function menu_node_prepare(Node $node) {
- if (empty($node->menu)) {
- $node_type = node_type_load($node->type);
-
-
- $menu_name = strtok($node_type->settings['menu_parent'], ':');
- $item = array();
- if (isset($node->nid)) {
- $mlid = FALSE;
-
- $type_menus = $node_type->settings['menu_options'];
- if (in_array($menu_name, $type_menus)) {
- $mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", 0, 1, array(
- ':path' => 'node/' . $node->nid,
- ':menu_name' => $menu_name,
- ))->fetchField();
- }
-
- if (!$mlid && !empty($type_menus)) {
- $mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' AND menu_name IN (:type_menus) ORDER BY mlid ASC", 0, 1, array(
- ':path' => 'node/' . $node->nid,
- ':type_menus' => array_values($type_menus),
- ))->fetchField();
- }
- if ($mlid) {
- $item = menu_link_load($mlid);
- }
- }
-
- if (module_exists('language') && empty($item)) {
- $item['langcode'] = $node->langcode;
- }
-
- $node->menu = $item + array(
- 'link_title' => '',
- 'mlid' => 0,
- 'plid' => 0,
- 'menu_name' => $menu_name,
- 'weight' => 0,
- 'options' => array(),
- 'module' => 'menu',
- 'expanded' => 0,
- 'hidden' => 0,
- 'has_children' => 0,
- 'customized' => 0,
- );
- }
-
- if (!isset($node->menu['parent_depth_limit'])) {
- $node->menu['parent_depth_limit'] = _menu_parent_depth_limit($node->menu);
- }
- }
-
- * Find the depth limit for items in the parent select.
- */
- function _menu_parent_depth_limit($item) {
- return MENU_MAX_DEPTH - 1 - (($item['mlid'] && $item['has_children']) ? menu_link_children_relative_depth($item) : 0);
- }
-
- * Implements hook_form_BASE_FORM_ID_alter().
- *
- * Adds menu item fields to the node form.
- *
- * @see menu_node_submit()
- */
- function menu_form_node_form_alter(&$form, $form_state) {
-
-
- $link = $form['#node']->menu;
- $type = $form['#node']->type;
- $node_type = node_type_load($type);
-
-
- $options = menu_parent_options(menu_get_menus(), $link, $type);
-
- if (empty($options)) {
- return;
- }
-
- if (module_exists('language')) {
- $form['langcode']['#ajax'] = array(
- 'callback' => 'menu_update_parent_options_ajax',
- 'wrapper' => 'menu-parent-select-wrapper',
- );
- }
-
- $form['menu'] = array(
- '#type' => 'fieldset',
- '#title' => t('Menu settings'),
- '#access' => user_access('administer menu'),
- '#collapsible' => TRUE,
- '#collapsed' => !$link['link_title'],
- '#group' => 'additional_settings',
- '#attached' => array(
- 'js' => array(backdrop_get_path('module', 'menu') . '/js/menu.js'),
- ),
- '#tree' => TRUE,
- '#weight' => 40,
- '#attributes' => array('class' => array('menu-link-form')),
- );
- $form['menu']['enabled'] = array(
- '#type' => 'checkbox',
- '#title' => t('Provide a menu link'),
- '#default_value' => empty($form['#node']->nid) ? $node_type->settings['menu_default'] : (int) (bool) $link['mlid'],
- );
- $form['menu']['link'] = array(
- '#type' => 'container',
- '#parents' => array('menu'),
- '#states' => array(
- 'invisible' => array(
- 'input[name="menu[enabled]"]' => array('checked' => FALSE),
- ),
- ),
- );
-
-
- foreach (array('mlid', 'module', 'hidden', 'has_children', 'customized', 'options', 'expanded', 'hidden', 'parent_depth_limit') as $key) {
- $form['menu']['link'][$key] = array('#type' => 'value', '#value' => $link[$key]);
- }
-
- $form['menu']['link']['link_title'] = array(
- '#type' => 'textfield',
- '#title' => t('Menu link title'),
- '#maxlength' => 255,
- '#default_value' => $link['mlid'] ? $link['link_title'] : '',
- );
-
- $form['menu']['link']['description'] = array(
- '#type' => 'textarea',
- '#title' => t('Description'),
- '#default_value' => isset($link['options']['attributes']['title']) ? $link['options']['attributes']['title'] : '',
- '#rows' => 1,
- '#description' => t('Shown when hovering over the menu link.'),
- );
-
- $default = ($link['mlid'] ? $link['menu_name'] . ':' . $link['plid'] : $node_type->settings['menu_parent']);
-
-
-
-
- if (!isset($options[$default])) {
- $array = array_keys($options);
- $default = reset($array);
- }
- $form['menu']['link']['parent'] = array(
- '#type' => 'select',
- '#title' => t('Parent item'),
- '#default_value' => $default,
- '#options' => $options,
- '#attributes' => array('class' => array('menu-parent-select')),
- '#prefix' => '<div id="menu-parent-select-wrapper">',
- '#suffix' => '</div>',
- );
- $form['menu']['link']['weight'] = array(
- '#type' => 'weight',
- '#title' => t('Weight'),
- '#delta' => 50,
- '#default_value' => $link['weight'],
- '#description' => t('Menu links with smaller weights are displayed before links with larger weights.'),
- );
- }
-
- * Implements hook_node_submit().
- *
- * @see menu_form_node_form_alter()
- */
- function menu_node_submit(Node $node, $form, $form_state) {
-
-
- if (!empty($form_state['values']['menu']['parent'])) {
- list($node->menu['menu_name'], $node->menu['plid']) = explode(':', $form_state['values']['menu']['parent']);
- }
- }
-
- * Implements hook_form_FORM_ID_alter().
- *
- * Adds menu options to the node type form.
- */
- function menu_form_node_type_form_alter(&$form, $form_state) {
- $menu_options = menu_get_menus();
- $node_type = $form['#node_type'];
- $form['menu'] = array(
- '#type' => 'fieldset',
- '#title' => t('Menu settings'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#attached' => array(
- 'js' => array(backdrop_get_path('module', 'menu') . '/js/menu.admin.js'),
- ),
- '#group' => 'additional_settings',
- '#weight' => 15,
- );
- $form['menu']['menu_default'] = array(
- '#type' => 'checkbox',
- '#title' => t('Add a link into the menu for new content of this type'),
- '#default_value' => $node_type->settings['menu_default'],
- );
- $form['menu']['menu_options'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Menus where this content may be placed'),
- '#default_value' => $node_type->settings['menu_options'],
- '#options' => $menu_options,
- );
-
-
-
-
- $options = menu_parent_options(menu_get_menus(), array('mlid' => 0));
- $form['menu']['menu_parent'] = array(
- '#type' => 'select',
- '#title' => t('Default parent item'),
- '#default_value' => $node_type->settings['menu_parent'],
- '#options' => $options,
- '#description' => t('Links to content will be placed below this item in the menu.'),
- '#attributes' => array('class' => array('menu-title-select')),
- );
-
-
-
- backdrop_add_js(
- '(function ($) { Backdrop.menu_update_parent_list(); })(jQuery);',
- array('scope' => 'footer', 'type' => 'inline')
- );
- }
-
- * Implements hook_node_type_load()
- */
- function menu_node_type_load(&$types) {
- foreach ($types as $type_name => $type) {
- $types[$type_name]->settings += array(
- 'menu_default' => FALSE,
- 'menu_options' => array(),
- 'menu_parent' => 'main-menu:0',
- );
- }
- }
-
- * Return an associative array of the custom menus names.
- *
- * @param $all
- * If FALSE return only user-added menus, or if TRUE also include
- * the menus defined by the system.
- * @return
- * An array with the machine-readable names as the keys, and human-readable
- * titles as the values.
- */
- function menu_get_menus($all = TRUE) {
- if ($custom_menus = menu_load_all()) {
- if (!$all) {
- $custom_menus = array_diff_key($custom_menus, menu_list_system_menus());
- }
- foreach ($custom_menus as $menu_name => $menu) {
- $custom_menus[$menu_name] = t($menu['title']);
- }
- asort($custom_menus);
- }
- return $custom_menus;
- }
-
- * Implements hook_preprocess_block().
- */
- function menu_preprocess_block(&$variables) {
- if ($variables['block']->module == 'menu') {
- $variables['attributes']['role'] = 'navigation';
- }
- }