Массовое добавление нод в меню VBO
14 мая 2019
Необходимо проделать следующие операции в папке с модулем VBO
diff --git a/actions/menu.action.inc b/actions/menu.action.inc new file mode 100644 index 0000000..8695564 --- /dev/null +++ b/actions/menu.action.inc @@ -0,0 +1,96 @@ +<?php +/** + * @file Drupal action to create menu items for nodes. + */ + +/** + * Implementation of hook_action_info(). + * Called by VBO on its own hook_action_info(). + */ +function views_bulk_operations_menu_action_info() { + if (!module_exists('menu')) return array(); + + return array('views_bulk_operations_menu_action' => + array( + 'type' => 'node', + 'label' => t('Add node to menu'), + 'configurable' => TRUE, + ) + ); +} + +/** + * Action function. + */ +function views_bulk_operations_menu_action(&$node, $context) { + $parent = explode(":", $context['plid']); + $menu_name = $parent[0]; + $plid = intval($parent[1]); + + if ($plid || $menu_name) { + $item = array( + 'link_path' => 'node/' . $node->nid, + 'link_title' => $node->title, + 'menu_name' => $menu_name, + 'plid' => $plid, + 'hidden' => $context['hidden'] + ); + menu_link_save($item); + menu_cache_clear_all(); + } +} + +/** + * Action form function. + */ +function views_bulk_operations_menu_action_form($context) { + $menu = array_intersect_key(menu_get_menus(), array($context['settings']['menu_id'] => null) ); + + $options = menu_parent_options($menu, array('mlid' => 0)); + $form['plid'] = array( + '#type' => 'select', + '#title' => t('Parent item'), + '#options' => $options, + '#description' => t('The maximum depth for an item and all its children is fixed at !maxdepth. Some menu items may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)), + '#attributes' => array('class' => array('menu-title-select')), + ); + + $form['hidden'] = array( + '#type' => 'checkbox', + '#title' => t('Disable Menu Item'), + '#weight' => 10, + '#default_value' => $context['settings']['hidden'], + '#description' => t('Menu items that are disabled will not be listed in any menu.'), + ); + + return $form; +} + +/** + * Action form submit handler. + */ +function views_bulk_operations_menu_action_submit($form, $form_state) { + return array('plid' => $form_state['values']['plid'], 'hidden' => $form_state['values']['hidden']); +} + +function views_bulk_operations_menu_action_views_bulk_operations_form($options) { + $select_options = menu_get_menus(); + $form['menu_id'] = array( + '#type' => 'select', + '#title' => t('Default Parent item'), + '#default_value' => $options['menu_id'], + '#options' => $select_options, + '#description' => t('The maximum depth for an item and all its children is fixed at !maxdepth. Some menu items may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)), + '#attributes' => array('class' => 'menu-title-select'), + ); + $form['hidden'] = array( + '#type' => 'checkbox', + '#title' => t('Disable Menu Items by Default'), + '#weight' => 10, + '#default_value' => 0, + '#description' => t('Menu items that are disabled will not be listed in any menu.'), + ); + + return $form; +} + diff --git a/views_bulk_operations.module b/views_bulk_operations.module index c049a00..07e6953 100644 --- a/views_bulk_operations.module +++ b/views_bulk_operations.module @@ -47,6 +47,7 @@ function views_bulk_operations_load_action_includes() { 'argument_selector.action.inc', 'delete.action.inc', 'modify.action.inc', + 'menu.action.inc', 'script.action.inc', 'user_roles.action.inc', );