You are here

function menu_token_form_menu_edit_item_submit in Menu Token 7

Same name and namespace in other branches
  1. 6 menu_token.admin.inc \menu_token_form_menu_edit_item_submit()

Custom submit for form menu_edit_item.

1 string reference to 'menu_token_form_menu_edit_item_submit'
menu_token_form_menu_edit_item_alter in ./menu_token.module
Implementation of hook_form_FORM_ID_alter().

File

./menu_token.module, line 541
Main module file for the Menu Token module.

Code

function menu_token_form_menu_edit_item_submit($form, &$form_state) {
  $values =& $form_state['values'];

  // If token replacing is enabled and this is a custom menu item
  if (in_array($values['module'], array(
    'menu',
    'system',
  )) && !empty($values['menu_token_enabled'])) {

    // Store the actual path in the options array.
    form_set_value(array(
      '#parents' => array(
        'options',
        'menu_token_data',
      ),
    ), array(), $form_state);
    form_set_value(array(
      '#parents' => array(
        'options',
        'menu_token_options',
        'clear',
      ),
    ), $values['menu_token_clear'], $form_state);
    form_set_value(array(
      '#parents' => array(
        'options',
        'menu_token_options',
        'title_localize',
      ),
    ), $values['menu_token_title_localize'], $form_state);
    foreach (array_keys(menu_token_get_plugin_types()) as $type) {
      if (!empty($values['menu_token_type_' . $type]) && $values['menu_token_type_' . $type] != '_none') {
        $plugin = $values['menu_token_type_' . $type];
        if ($handler = menu_token_get_handler($plugin)) {
          form_set_value(array(
            '#parents' => array(
              'options',
              'menu_token_data',
              $type,
            ),
          ), array(
            'type' => $type,
            'plugin' => $plugin,
            'options' => array(),
          ), $form_state);

          // Validate the form via the handler.
          if ($output = $handler
            ->form_submit($form, $form_state)) {
            $output = $values['options']['menu_token_data'][$type]['options'] + $output;
            form_set_value(array(
              '#parents' => array(
                'options',
                'menu_token_data',
                $type,
                'options',
              ),
            ), $output, $form_state);
          }
        }
      }
    }
  }
  else {
    foreach (array(
      'menu_token_link_path',
      'menu_token_data',
      'menu_token_options',
    ) as $key) {
      unset($values['options'][$key]);
    }
  }
}