You are here

function safeword_value_collides in Safeword 8

Same name and namespace in other branches
  1. 7 safeword.module \safeword_value_collides()

Uniqueness callback for safeword fields.

1 string reference to 'safeword_value_collides'
safeword_field_widget_form in ./safeword.module
Implements hook_field_widget_form().

File

./safeword.module, line 507
Provides a FieldAPI field type, widget, and several formatters for a combined human readable/machine name pair of values. Possible uses include automatic generation of editable pathauto segments, handy Views argument values, and impressing friends.

Code

function safeword_value_collides($name, array $element = NULL, $form_state) {

  // This should never be the case, but it doesn't hurt to check.
  if (empty($element) && empty($element['#exists_params'])) {
    return FALSE;
  }
  else {
    $settings = $element['#exists_params'];
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', $settings['entity_type'], '=')
      ->fieldCondition($settings['field_name'], 'machine', $name, '=')
      ->count();
    if (!empty($settings['bundle'])) {
      $query
        ->entityCondition('bundle', $settings['bundle'], '=');
    }
    return $query
      ->execute() > 0 ? TRUE : FALSE;
  }
}