You are here

protected function EntityProcessorBase::prepareFeedsItemField in Feeds 8.3

Prepares the feeds_item field.

@todo How does ::load() behave for deleted fields?

1 call to EntityProcessorBase::prepareFeedsItemField()
EntityProcessorBase::onFeedTypeSave in src/Feeds/Processor/EntityProcessorBase.php
The feed type is being saved.

File

src/Feeds/Processor/EntityProcessorBase.php, line 728

Class

EntityProcessorBase
Defines a base entity processor.

Namespace

Drupal\feeds\Feeds\Processor

Code

protected function prepareFeedsItemField() {

  // Do not create field when syncing configuration.
  if (\Drupal::isConfigSyncing()) {
    return FALSE;
  }

  // Create field if it doesn't exist.
  if (!FieldStorageConfig::loadByName($this
    ->entityType(), 'feeds_item')) {
    FieldStorageConfig::create([
      'field_name' => 'feeds_item',
      'entity_type' => $this
        ->entityType(),
      'type' => 'feeds_item',
      'translatable' => FALSE,
    ])
      ->save();
  }

  // Create field instance if it doesn't exist.
  if (!FieldConfig::loadByName($this
    ->entityType(), $this
    ->bundle(), 'feeds_item')) {
    FieldConfig::create([
      'label' => 'Feeds item',
      'description' => '',
      'field_name' => 'feeds_item',
      'entity_type' => $this
        ->entityType(),
      'bundle' => $this
        ->bundle(),
    ])
      ->save();
  }
}