You are here

function entityqueue_subqueue_edit_form_validate in Entityqueue 7

Validation callback for the subqueue edit form.

1 string reference to 'entityqueue_subqueue_edit_form_validate'
entityqueue_subqueue_edit_form in includes/entityqueue.admin.inc
Form callback; Displays the subqueue edit form.

File

includes/entityqueue.admin.inc, line 106
Administrative pages for Entity Queue.

Code

function entityqueue_subqueue_edit_form_validate($form, &$form_state) {
  $queue = $form_state['entityqueue_queue'];
  $subqueue = $form_state['entityqueue_subqueue'];

  // Use load multiple to ensure we load fresh without a cache.
  $original_subqueues = entityqueue_subqueue_load_multiple(array(
    $subqueue->name,
  ), array(), TRUE);
  $original_subqueue = reset($original_subqueues);

  // Compare the subqueue that was in form state with the freshly loaded copy,
  // to ensure the queue hasn't been modified in a different user session.
  if ($original_subqueue) {
    $field_name = _entityqueue_get_target_field_name($queue->target_type);
    $lang = $form[$field_name]['#language'];
    $form_items = field_get_items('entityqueue_subqueue', $subqueue, $field_name, $lang);
    $original_items = field_get_items('entityqueue_subqueue', $original_subqueue, $field_name, $lang);
    $target_ids = array_column($form_items, 'target_id');
    $original_target_ids = array_column($original_items, 'target_id');
    if ($target_ids !== $original_target_ids) {
      form_error($form['queue'], t('This queue has been modified in another window or by another user and cannot be saved. Load this page again and remake your changes.'));
    }
  }
  entity_form_field_validate('entityqueue_subqueue', $form, $form_state);
}