You are here

public function FeedsImporter::validateConfig in Feeds 7.2

Validates the configuration.

Overrides FeedsConfigurable::validateConfig

File

includes/FeedsImporter.inc, line 212
FeedsImporter class and related.

Class

FeedsImporter
Class for a Feeds importer.

Code

public function validateConfig() {
  $errors = parent::validateConfig();
  $config = $this
    ->getConfig();

  // Check if "Attach to content type" setting is the same as content type on
  // node processor.
  if ($this->processor instanceof FeedsNodeProcessor) {
    $processor_config = $this->processor
      ->getConfig();
    if (!empty($config['content_type']) && $processor_config['bundle'] == $config['content_type']) {
      $message = t('The importer is attached to the same content type as the content type selected on the node processor. Unless you have a very advanced use case, these two should never be the same.');
      if (!module_exists('feeds_news')) {
        $message .= ' ' . t('Enable the Feeds News module for an example of how the "@content_type" setting can be used.', array(
          '@content_type' => t('Attach to content type'),
        ));
      }
      elseif ($this->id != 'feed') {
        $message .= ' ' . t('See the importer !importer_name (provided by the Feeds News module) for an example of how the "@content_type" setting can be used.', array(
          '!importer_name' => l(check_plain(feeds_importer('feed')->config['name']), 'admin/structure/feeds/feed'),
          '@content_type' => t('Attach to content type'),
        ));
      }
      $errors[] = $message;
    }
  }

  // Check for a combination of incompatible settings.
  if (!$config['import_on_create'] && empty($config['content_type'])) {
    if ($config['import_period'] == FEEDS_SCHEDULE_NEVER) {
      $errors[] = t('"@import_period" and "@import_on_create" are both turned off and the importer is not attached to a content type. Unless you have alternative methods of running imports for this importer, Feeds will not import anything for this importer.', array(
        '@import_period' => t('Periodic import'),
        '@import_on_create' => t('Import on submission'),
      ));
    }
    elseif ($config['process_in_background']) {
      $errors[] = t('Since "@import_on_create" is turned off and the importer is not attached to a content type, the "@process_in_background" setting may have no effect. When submitting the standalone form with the "@import_on_create" setting turned off, the feed is only scheduled for periodic import.', array(
        '@import_on_create' => t('Import on submission'),
        '@process_in_background' => t('Process in background'),
      ));
    }
  }

  // Validate errors of each plugin as well.
  $plugin_types = array(
    'fetcher' => t('Fetcher'),
    'parser' => t('Parser'),
    'processor' => t('Processor'),
  );
  foreach ($plugin_types as $type => $plugin_label) {

    // Check if plugin exists.
    $plugin = feeds_plugin($this->config[$type]['plugin_key'], $this->id);
    if ($plugin instanceof FeedsMissingPlugin) {
      $errors[] = t('The plugin %plugin is unavailable.', array(
        '%plugin' => $this->config[$type]['plugin_key'],
      ));
      continue;
    }
    $plugin_errors = $this->{$type}
      ->validateConfig();
    foreach ($plugin_errors as $key => $error) {
      $errors[] = t('@plugin: !error', array(
        '@plugin' => $plugin_label,
        '!error' => $error,
      ));
    }
  }
  return $errors;
}