1 layout.admin.inc layout_menu_item_form($form, &$form_state, LayoutMenuItem $menu_item)

Form callback; Configure a layout menu item.

Related topics

File

core/modules/layout/layout.admin.inc, line 2272
Administrative functions for Layout module.

Code

function layout_menu_item_form($form, &$form_state, LayoutMenuItem $menu_item) {
  form_load_include($form_state, 'inc', 'layout', 'layout.admin');

  $form_state['menu_item'] = $menu_item;

  $form['#tree'] = TRUE;
  $form['#attached']['js'][] = backdrop_get_path('module', 'layout') . '/js/layout.admin.js';
  $form['#attached']['css'][] = backdrop_get_path('module', 'layout') . '/css/layout.admin.css';

  $messages = array();
  if ($menu_item->locked) {
    $messages['warning'] = array(
      layout_locked_message($menu_item, 'menu_item'),
    );
  }
  $form['messages'] = array(
    '#theme' => 'status_messages',
    '#messages' => $messages,
    '#weight' => -100,
    // Prefix/suffix used to identify in AJAX requests.
    '#prefix' => '<div id="layout-messages">',
    '#suffix' => '</div>',
  );

  $menu_settings = $menu_item->menu;

  $form['menu']['type'] = array(
    '#title' => t('Type'),
    '#type' => 'radios',
    '#options' => array(
      'none' => t('No menu entry'),
      'normal' => t('Normal menu entry'),
      'tab' => t('Menu tab'),
      'default tab' => t('Default menu tab'),
      'action' => t('Local action'),
    ),
    '#default_value' => $menu_settings['type'],
  );

  $form['menu']['title'] = array(
    '#title' => t('Title'),
    '#type' => 'textfield',
    '#default_value' => $menu_settings['title'],
    '#description' => t('If set to normal or tab, enter the text to use for the menu item.'),
    '#states' => array(
      'invisible' => array(
        ':input[name="menu[type]"]' => array('value' => 'none'),
      ),
    ),
  );

  // Only display the menu selector if menu module is enabled.
  if (module_exists('menu')) {
    $form['menu']['name'] = array(
      '#title' => t('Menu'),
      '#type' => 'select',
      '#options' => menu_get_menus(),
      '#default_value' => $menu_settings['name'],
      '#description' => t('Insert item into an available menu.'),
      '#states' => array(
        'visible' => array(
          ':input[name="menu[type]"]' => array('value' => 'normal'),
        ),
      ),
    );
  }
  else {
    $form['menu']['name'] = array(
      '#type' => 'value',
      '#value' => $menu_settings['name'],
    );
    $form['menu']['markup'] = array(
      '#value' => t('Menu selection requires the activation of menu module.'),
    );
  }
  $form['menu']['weight'] = array(
    '#title' => t('Weight'),
    '#type' => 'number',
    '#default_value' => isset($menu_settings['weight']) ? $menu_settings['weight'] : 0,
    '#description' => t('The lower the weight the higher/further left it will appear.'),
    '#states' => array(
      'invisible' => array(
        ':input[name="menu[type]"]' => array('value' => 'none'),
      ),
    ),
  );

  $form['menu']['parent'] = array(
    '#type' => 'fieldset',
    '#title' => t('Parent menu item'),
    '#states' => array(
      'visible' => array(
        ':input[name="menu[type]"]' => array('value' => 'default tab'),
      ),
    ),
  );
  $form['menu']['parent']['type'] = array(
    '#title' => t('Parent menu item'),
    '#title_display' => 'none',
    '#type' => 'radios',
    '#options' => array('none' => t('No menu entry'), 'normal' => t('Normal menu item'), 'tab' => t('Menu tab')),
    '#default_value' => $menu_settings['parent']['type'],
    '#description' => t('When providing a menu item as a default tab, the parent menu item of that tab must be specified. Sometimes the parent will already exist, but other times you will need to have one created. The path of a parent item will always be the same path with the last part left off. i.e, if the path to this layout is <em>foo/bar/baz</em>, the parent path would be <em>foo/bar</em>.'),
  );
  $form['menu']['parent']['title'] = array(
    '#title' => t('Parent item title'),
    '#type' => 'textfield',
    '#default_value' => $menu_settings['parent']['title'],
    '#description' => t('If creating a parent menu item, enter the title of the item.'),
    '#states' => array(
      'invisible' => array(
        ':input[name="menu[parent][type]"]' => array('value' => 'none'),
      ),
    ),
  );
  // Only display the menu selector if menu module is enabled.
  if (module_exists('menu')) {
    $form['menu']['parent']['name'] = array(
      '#title' => t('Parent item menu'),
      '#type' => 'select',
      '#options' => menu_get_menus(),
      '#default_value' => $menu_settings['parent']['name'],
      '#description' => t('Insert item into an available menu.'),
      '#states' => array(
        'visible' => array(
          ':input[name="menu[parent][type]"]' => array('value' => 'normal'),
        ),
      ),
    );
  }
  else {
    $form['menu']['parent']['name'] = array(
      '#type' => 'value',
      '#value' => $menu_settings['parent']['name'],
    );
  }
  $form['menu']['parent']['weight'] = array(
    '#title' => t('Item weight'),
    '#type' => 'textfield',
    '#default_value' => $menu_settings['parent']['weight'],
    '#size' => 5,
    '#description' => t('Enter the weight of the menu item or tab. The lower the number, the earlier in the list it will be.'),
    '#states' => array(
      'invisible' => array(
        ':input[name="menu[parent][type]"]' => array('value' => 'none'),
      ),
    ),
  );

  $form['conditions'] = array(
    '#title' => t('Access conditions'),
    '#type' => 'item',
    '#description' => t('Conditions set at the menu level will prevent access to the entire page and all layouts configured in it.'),
    '#id' => 'layout-access',
  );
  $form['conditions']['active'] = array(
    '#type' => 'container',
    '#theme' => 'layout_conditions',
    '#attributes' => array('class' => array('layout-access-list')),
  );
  foreach ($menu_item->conditions as $access_key => $menu_access) {
    $form['conditions']['active'][$access_key] = array(
      '#type' => 'container',
      '#attributes' => array('class' => array('layout-condition')),
      '#id' => NULL,
    );
    $form['conditions']['active'][$access_key]['label'] = array(
      '#markup' => $menu_access->summary(),
    );
    $form['conditions']['active'][$access_key]['remove'] = array(
      '#type' => 'submit',
      '#value' => t('Remove'),
      '#attributes' => array('class' => array('layout-link-button', 'layout-access-remove')),
      '#submit' => array(
        'layout_menu_item_form_condition_remove',
      ),
      '#ajax' => array(
        'callback' => 'layout_ajax_form_update',
      ),
      '#name' => 'conditions[' . $access_key . '][remove]',
    );
    $form['conditions']['active'][$access_key]['configure'] = array(
      '#type' => 'submit',
      '#value' => t('Configure'),
      '#attributes' => array('class' => array('layout-link-button', 'layout-access-configure')),
      '#submit' => array(
        'layout_menu_item_form_condition_edit',
      ),
      '#ajax' => array(
        'callback' => 'layout_ajax_form_open_dialog',
      ),
      '#name' => 'conditions[' . $access_key . '][configure]',
    );
  }
  $form['conditions']['add'] = array(
    '#type' => 'submit',
    '#value' => t('Add visibility condition'),
    '#attributes' => array('class' => array('layout-link-button', 'layout-access-add')),
    '#submit' => array(
      'layout_menu_item_form_condition_add'
    ),
    '#ajax' => array(
      'callback' => 'layout_ajax_form_open_dialog',
    ),
    '#prefix' => '<ul class="action-links"><li>',
    '#suffix' => '</li></ul>',
  );

  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save menu settings'),
  );

  if (isset($menu_item->locked)) {
    $form['actions']['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Cancel'),
      '#limit_validation_errors' => array(array('actions', 'reset')),
      '#validate' => array(),
      '#submit' => array(
        'layout_menu_item_form_reset',
      ),
    );
  }

  return $form;
}