You are here

function _menu_views_form_submit in Menu Views 7.2

Same name and namespace in other branches
  1. 8.3 menu_views.admin.inc \_menu_views_form_submit()

Submit handler for menu_edit_item form.

1 string reference to '_menu_views_form_submit'
_menu_views_form_alter in ./menu_views.admin.inc
Alters existing forms in preparation for adding Menu Views to it.

File

./menu_views.admin.inc, line 599
Form hooks for the menu_views module.

Code

function _menu_views_form_submit($form, &$form_state) {
  $values =& $form_state['values'];
  if (isset($form['#node'])) {
    $values =& $form_state['values']['menu'];
  }

  // Get view settings from menu item.
  $item = _menu_views_get_item($form, $form_state);

  // Remove this unecessary property from the values.
  if (isset($values['menu_views'])) {
    unset($values['menu_views']);
  }

  // We really only want to intercept the menu edit item submit handle if this is actually a view.
  if ($item['type'] == 'view') {

    // If this is a new menu item, save a quick version of the menu item and return the mlid.
    // The menu item will get updated with the rest of the values again shortly.
    if (!$values['mlid']) {
      $values['hidden'] = (int) (!$values['enabled']);
      $values['options']['attributes']['title'] = $values['description'];
      list($values['menu_name'], $values['plid']) = explode(':', $values['parent']);
      if (!($values['mlid'] = menu_link_save($values))) {
        drupal_set_message(t('There was an error creating the menu item.'), 'error');
      }
    }
    $default = _menu_views_default_values();
    $item = array(
      // The mlid should remain constant, always use the information provided by the menu module and not this one.
      'mlid' => $values['mlid'],
      'type' => $item['type'],
      'original_path' => $item['original_path'],
      'view' => $item['view'],
    );

    // Replace the menu views values in the menu item's options.
    $values['options']['menu_views'] = _menu_views_array_merge_recursive($default, $item);
  }
}