You are here

protected function FeedCreationTrait::createFeedTypeForCsv in Feeds 8.3

Creates a feed type for the CSV parser.

Parameters

array $columns: The CSV columns, keyed by machine name.

array $settings: (optional) An associative array of settings for the feed type entity. The following defaults are provided:

  • label: Random string.
  • ID: Random string.
  • import_period: never.
  • processor_configuration: authorize off and article bundle.
  • mappings: mapping to guid and title.

Return value

\Drupal\feeds\FeedTypeInterface The created feed type entity.

40 calls to FeedCreationTrait::createFeedTypeForCsv()
ConfigEntityReferenceTest::testImportById in tests/src/Kernel/Feeds/Target/ConfigEntityReferenceTest.php
Tests importing config entity references by ID.
ConfigEntityReferenceTest::testImportByLabel in tests/src/Kernel/Feeds/Target/ConfigEntityReferenceTest.php
Tests importing config entity references by label.
ConfigEntityReferenceTest::testImportByUuid in tests/src/Kernel/Feeds/Target/ConfigEntityReferenceTest.php
Tests importing config entity references by UUID.
CronTest::testImportSourceWithMultipleCronRuns in tests/src/Functional/CronTest.php
Tests importing a source that needs multiple cron runs to complete.
CsvParserFeedFormTest::setUp in tests/src/Functional/Feeds/Parser/Form/CsvParserFeedFormTest.php

... See full list

File

tests/src/Traits/FeedCreationTrait.php, line 70

Class

FeedCreationTrait
Provides methods to create feeds and feed types with default settings.

Namespace

Drupal\Tests\feeds\Traits

Code

protected function createFeedTypeForCsv(array $columns, array $settings = []) {
  $sources = [];
  foreach ($columns as $machine_name => $column) {
    $sources[$machine_name] = [
      'label' => $column,
      'value' => $column,
      'machine_name' => $machine_name,
    ];
  }
  if (!isset($settings['custom_sources'])) {
    $settings['custom_sources'] = $sources;
  }
  else {
    $settings['custom_sources'] += $sources;
  }
  $settings += [
    'fetcher' => 'directory',
    'fetcher_configuration' => [
      'allowed_extensions' => 'csv',
    ],
    'parser' => 'csv',
  ];
  return $this
    ->createFeedType($settings);
}