You are here

function metatags_quick_admin_path_based_edit_submit in Meta tags quick 7.2

Same name and namespace in other branches
  1. 8.3 metatags_quick.admin.inc \metatags_quick_admin_path_based_edit_submit()

Updates the metatags entity for a given path after the user has submitted the form. Also updates the path if it has been altered.

_state

Parameters

type $form:

File

./metatags_quick.admin.inc, line 608

Code

function metatags_quick_admin_path_based_edit_submit($form, &$form_state) {

  // abort if there is no valid entity
  if (!$form_state['entity']) {
    form_set_error();
    drupal_set_message(t('Wrong path'), 'error');
    return;
  }

  // Update path if it has been altered
  if ($form_state['values']['path'] != html_entity_decode($form_state['entity']->path) || $form_state['values']['lang'] != $form_state['entity']->lang) {

    // check if there isn't already a path like the new path
    $entity_id = db_select('metatags_quick_path_based', 'm')
      ->fields('m', array(
      'id',
    ))
      ->condition('lang', check_plain($form_state['values']['lang']))
      ->condition('path', check_plain($form_state['values']['path']))
      ->execute()
      ->fetchField();

    // if not continue
    if (!$entity_id) {
      db_update('metatags_quick_path_based')
        ->fields(array(
        'path' => check_plain(trim($form_state['values']['path'])),
        'lang' => $form_state['values']['lang'],
      ))
        ->condition('id', $form_state['entity']->id)
        ->execute();
    }
    else {

      // Otherwise abort with error message
      form_set_error('path', t('Another set of meta tags exists for this path and language'));
      return;
    }
  }

  // update entity fields
  $entity = $form_state['entity'];
  entity_form_submit_build_entity('metatags_path_based', $entity, $form, $form_state);
  field_attach_update('metatags_path_based', $entity);

  // display message and redirect
  drupal_set_message('Meta tags updated', 'status');
}