You are here

public function JsonFeedFields::validate in JSON Feed 8

Validate that the plugin is correct and can be saved.

Return value

An array of error strings to tell the user what is wrong with this plugin.

Overrides PluginBase::validate

File

src/Plugin/views/row/JsonFeedFields.php, line 184

Class

JsonFeedFields
Plugin which displays fields for a JSON feed.

Namespace

Drupal\json_feed\Plugin\views\row

Code

public function validate() {
  $errors = parent::validate();
  $required_options = [
    'id_field',
    'url_field',
  ];
  foreach ($required_options as $required_option) {
    if (empty($this->options[$required_option])) {
      $errors[] = $this
        ->t('Row style plugin requires specifying which views fields to use for JSON feed item.');
      break;
    }
  }

  // Ensure either content_html_field or content_text_field is set, one or the
  // other is required.
  if (empty($this->options['content_html_field']) && empty($this->options['content_text_field'])) {
    $errors[] = $this
      ->t('Either content_html or content_text must have a value.');
  }
  return $errors;
}