You are here

function entityreference_plugin_display::validate in Entity reference 7

Extend the default validation.

Overrides views_plugin_display::validate

File

views/entityreference_plugin_display.inc, line 107
Handler for entityreference_plugin_display.

Class

entityreference_plugin_display
@file Handler for entityreference_plugin_display.

Code

function validate() {
  $errors = parent::validate();

  // Verify that search fields are set up.
  $style_options = $this
    ->get_option('style_options');
  if (!isset($style_options['search_fields'])) {
    $errors[] = t('Display "@display" needs a selected search fields to work properly. See the settings for the Entity Reference list format.', array(
      '@display' => $this->display->display_title,
    ));
  }
  else {

    // Verify that the search fields used actually exist.

    //$fields = array_keys($this->view->get_items('field'));
    $fields = array_keys($this->handlers['field']);
    foreach ($style_options['search_fields'] as $field_alias => $enabled) {
      if ($enabled && !in_array($field_alias, $fields)) {
        $errors[] = t('Display "@display" uses field %field as search field, but the field is no longer present. See the settings for the Entity Reference list format.', array(
          '@display' => $this->display->display_title,
          '%field' => $field_alias,
        ));
      }
    }
  }
  return $errors;
}