Commit e6726151 authored by Bevan  Wishart's avatar Bevan Wishart Committed by Youri van Koppen
Browse files

Issue #2938505 by MegaChriz, thursday_bw, irinaz, vchen, jwineichen,...

Issue #2938505 by MegaChriz, thursday_bw, irinaz, vchen, jwineichen, jamesdixon, mattshoaf: Added UI for editing and removing custom sources, introducing custom sources types "CSV" and "Blank".
parent 804cb107
Loading
Loading
Loading
Loading
+14 −8
Changes for config/schema/feeds.schema.yml: 14 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -38,14 +38,7 @@ feeds.feed_type.*:
    custom_sources:
      type: sequence
      sequence:
        type: mapping
        mapping:
          value:
            type: string
          label:
            type: string
          machine_name:
            type: string
        type: feeds.custom_source.[type]
    mappings:
      type: sequence
      sequence:
@@ -204,3 +197,16 @@ feeds.processor.entity:

feeds.processor.entity:*:
  type: feeds.processor.entity

# Custom source configurations.
feeds.custom_source.*:
  type: mapping
  mapping:
    value:
      type: string
    label:
      type: string
    machine_name:
      type: string
    type:
      type: string
+6 −0
Changes for feeds.links.task.yml: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -31,6 +31,12 @@ entity.feeds_feed_type.mapping:
  base_route: entity.feeds_feed_type.edit_form
  weight: 0

entity.feeds_feed_type.sources:
  route_name: entity.feeds_feed_type.sources
  title: Custom sources
  base_route: entity.feeds_feed_type.edit_form
  weight: 1

feeds.admin:
  route_name: feeds.admin
  title: Feeds
+6 −3
Changes for feeds.module: 6 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -28,14 +28,14 @@ function feeds_help($route_name, RouteMatchInterface $route_match) {
    case 'entity.feeds_feed_type.mapping':
      $doc_link = [
        '#type' => 'link',
        '#url' => Url::fromUri('https://www.drupal.org/docs/8/modules/feeds/creating-and-editing-import-feeds#mapping'),
        '#url' => Url::fromUri('https://www.drupal.org/docs/contributed-modules/feeds/creating-and-editing-import-feeds#mapping'),
        '#title' => t('Mapping documentation'),
        '#attributes' => [
          'target' => '_new',
        ],
      ];

      return new FormattableMarkup('<p>@help1</p><p>@help2</p><p>@help3</p>', [
      return new FormattableMarkup('<p>@help1</p><p>@help2 @help3</p><p>@help4</p>', [
        '@help1' => t('Define which elements of a single item of a feed (= %sources_label) map to which content pieces in Drupal (= %targets_label). To avoid importing duplicates, make sure that at least one definition has an %unique_target_label. An unique target means that a value for a target can only occur once. For example, only one item with the URL %example_url can exist.', [
          '%sources_label' => t('Sources'),
          '%targets_label' => t('Targets'),
@@ -45,7 +45,10 @@ function feeds_help($route_name, RouteMatchInterface $route_match) {
        '@help2' => t('On %read_only_label targets a value can only be set the first time.', [
          '%read_only_label' => t('Read only'),
        ]),
        '@help3' => t('See the @doc_link for more information.', [
        '@help3' => t('Blank sources can be used for tampering: see the <a href=":link" target="_blank">documentation</a>.', [
          ':link' => 'https://www.drupal.org/docs/contributed-modules/feeds/feeds-howtos/how-to-use-blank-sources',
        ]),
        '@help4' => t('See the @doc_link for more information.', [
          '@doc_link' => \Drupal::service('renderer')->renderRoot($doc_link),
        ]),
      ]);
+27 −0
Changes for feeds.post_update.php: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@

use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\feeds\FeedTypeInterface;
use Drupal\feeds\Feeds\Parser\CsvParser;

/**
 * Replace deprecated action ID's for 'update_non_existent' setting.
@@ -35,3 +36,29 @@ function feeds_post_update_actions_update_non_existent(&$sandbox = NULL) {
      return FALSE;
    });
}

/**
 * Add types to existing custom sources on feeds parsers.
 */
function feeds_post_update_custom_sources(&$sandbox = NULL) {
  \Drupal::classResolver(ConfigEntityUpdater::class)
    ->update($sandbox, 'feeds_feed_type', function (FeedTypeInterface $feed_type) {
      $parser = $feed_type->getParser();
      if ($parser instanceof CsvParser) {
        $custom_source_type = 'csv';
      }
      else {
        return FALSE;
      }

      // Add type to custom sources to those that don't have it yet.
      foreach ($feed_type->getCustomSources() as $name => $custom_source) {
        if (empty($custom_source['type'])) {
          $custom_source['type'] = $custom_source_type;
          $feed_type->addCustomSource($name, $custom_source);
        }
      }

      return TRUE;
    });
}
+23 −0
Changes for feeds.routing.yml: 23 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -96,3 +96,26 @@ entity.feeds_feed_type.mapping:
    _title_callback: '\Drupal\feeds\Form\MappingForm::mappingTitle'
  requirements:
    _entity_access: 'feeds_feed_type.mapping'

entity.feeds_feed_type.sources:
  path: '/admin/structure/feeds/manage/{feeds_feed_type}/sources'
  defaults:
    _controller: 'Drupal\feeds\Controller\CustomSourceListController::page'
    _title_callback: '\Drupal\feeds\Controller\CustomSourceListController::title'
  requirements:
    _entity_access: 'feeds_feed_type.mapping'

entity.feeds_feed_type.source_edit:
  path: '/admin/structure/feeds/manage/{feeds_feed_type}/sources/{key}'
  defaults:
    _form: '\Drupal\feeds\Form\CustomSourceEditForm'
    _title_callback: '\Drupal\feeds\Form\CustomSourceEditForm::title'
  requirements:
    _entity_access: 'feeds_feed_type.mapping'

entity.feeds_feed_type.source_delete:
  path: '/admin/structure/feeds/manage/{feeds_feed_type}/sources/{key}/delete'
  defaults:
    _form: '\Drupal\feeds\Form\CustomSourceDeleteForm'
  requirements:
    _entity_access: 'feeds_feed_type.mapping'
Loading