You are here

function menu_position_rule_form in Menu Position 7.2

Same name and namespace in other branches
  1. 6 menu_position.admin.inc \menu_position_rule_form()
  2. 7 menu_position.admin.inc \menu_position_rule_form()

Returns form to add or edit a menu position rule.

2 calls to menu_position_rule_form()
menu_position_add_rule_form in ./menu_position.admin.inc
Menu callback; Adds rules.
menu_position_edit_rule_form in ./menu_position.admin.inc
Menu callback; Edits rules.

File

./menu_position.admin.inc, line 329
Provides infrequently used functions and hooks for menu_position.

Code

function menu_position_rule_form($form, &$form_state) {

  // Set the default values.
  $rid = !empty($form_state['#menu-position-rule']['rid']) ? $form_state['#menu-position-rule']['rid'] : '';
  $admin_title = !empty($form_state['#menu-position-rule']['admin_title']) ? $form_state['#menu-position-rule']['admin_title'] : '';
  $menu_name = !empty($form_state['#menu-position-rule']['menu_name']) ? $form_state['#menu-position-rule']['menu_name'] : '';
  $plid = !empty($form_state['#menu-position-rule']['plid']) ? $form_state['#menu-position-rule']['plid'] : NULL;
  $mlid = !empty($form_state['#menu-position-rule']['mlid']) ? $form_state['#menu-position-rule']['mlid'] : NULL;
  $form['rid'] = array(
    '#type' => 'hidden',
    '#value' => $rid,
  );
  $form['admin_title'] = array(
    '#type' => 'textfield',
    '#default_value' => $admin_title,
    '#title' => t('Administrative title'),
    '#description' => t('This title will be used administratively to identify this rule.'),
    '#required' => TRUE,
  );

  // Parent menu item.
  if ($mlid) {
    $options = menu_parent_options(menu_get_menus(), menu_link_load($mlid));
    $default = $menu_name . ':' . $plid;
  }
  else {
    $options = menu_parent_options(menu_get_menus(), array(
      'mlid' => 0,
    ));
    $default = 'main-menu:0';
  }
  $form['plid'] = array(
    '#type' => 'select',
    '#title' => t('Parent menu item'),
    '#required' => TRUE,
    '#options' => $options,
    '#default_value' => $default,
    '#description' => t('Select the place in the menu where the rule should position its menu links.'),
  );

  // Place holder for all condition plug-ins.
  // Visibility settings.
  $form['conditions_title'] = array(
    '#type' => 'item',
    '#title' => t('Conditions'),
    '#description' => t('All the conditions must be met before a rule is applied.'),
  );
  $form['conditions'] = array(
    '#type' => 'vertical_tabs',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if ($rid) {
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
    );
  }

  // Add conditions.
  foreach (menu_position_get_plugins() as $plugin) {

    // Load the required include file.
    if (!empty($plugin['file'])) {
      $file = pathinfo($plugin['file']);

      // Allow plugins to be in a sub-directory.
      if ($file['dirname']) {
        $file['filename'] = $file['dirname'] . '/' . $file['filename'];
      }
      module_load_include($file['extension'], $plugin['module'], $file['filename']);
    }

    // Call form callback to add additional form elements.
    $function = $plugin['form_callback'];
    if (function_exists($function)) {
      $function($form, $form_state);
    }
  }

  // Form validation and submission.
  $form['#validate'][] = 'menu_position_rule_form_validate';
  $form['#submit'][] = 'menu_position_rule_form_submit';
  return $form;
}