You are here

function HOOK_menu_position_rule_PLUGIN_form in Menu Position 6

Same name and namespace in other branches
  1. 7.2 plugins/menu_position.example_plugin.inc \HOOK_menu_position_rule_PLUGIN_form()
  2. 7 plugins/menu_position.example_plugin.inc \HOOK_menu_position_rule_PLUGIN_form()

Adds form elements for the PLUGIN plugin to the rule configuration form.

If this condition was active in the current rule, the plug-in variables will be available in $form_state['#menu-position-rule']['conditions']['PLUGIN'].

It is the resposibility of this hook to add any necessary form validation and submission handlers.

Parameters

$form: A reference to the "add/edit rule" form array. New form elements should be added directly to this array.

$form_state: A reference to the current form state.

File

plugins/menu_position.example_plugin.inc, line 48
Provides the PLUGIN rule plugin for the Menu Position module.

Code

function HOOK_menu_position_rule_PLUGIN_form(&$form, &$form_state) {

  // If this is an existing rule, load the variables stored in the rule for this plugin.
  $variables = !empty($form_state['#menu-position-rule']['conditions']['PLUGIN']) ? $form_state['#menu-position-rule']['conditions']['PLUGIN'] : array();

  // To ensure that the plugin's form elements are placed inside vertical tabs,
  // all elements should be placed inside a collapsed fielset inside the
  // $form['conditions'] array.
  $form['conditions']['PLUGIN'] = array(
    '#type' => 'fieldset',
    '#title' => t('Lolspeak'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#attached' => array(
      // Ensures a proper summary is added to its vertical tab.
      'js' => array(
        drupal_get_path('module', 'menu_position') . '/plugins/menu_position.example_plugin.js',
      ),
    ),
  );
  $form['conditions']['PLUGIN']['lolspeak'] = array(
    '#type' => 'checkbox',
    '#title' => t('Lolspeak'),
    '#default_value' => !empty($variables['lolspeak']) ? $variables['lolspeak'] : 0,
    '#description' => t('Apply this rule only on pages written in lolspeak.'),
    '#weight' => -20,
  );

  // If we have a validation handler, we can add it this way. Or we could add
  // a per-element validation handler with '#element_validate' above.
  $form['#validate'][] = 'HOOK_menu_position_rule_PLUGIN_form_validate';

  // Add a submit handler.
  $form['#submit'][] = 'HOOK_menu_position_rule_PLUGIN_form_submit';
}