You are here

public function FeedsItemFormatterTestBase::addFieldToFeed in Feeds 8.3

Creates a field for the feed item and set its value.

Parameters

\Drupal\feeds\FeedInterface $feed: The feed to add a field to.

Return value

\Drupal\feeds\FeedInterface The updated feed entity.

3 calls to FeedsItemFormatterTestBase::addFieldToFeed()
FeedsItemTargetEntityFormatterTest::testFeedsItemTargetEntityFormatter in tests/src/Functional/Plugin/Field/FieldFormatter/FeedsItemTargetEntityFormatterTest.php
Tests the feeds target entity view formatter.
FeedsItemTargetLabelFormatterTest::testFeedsItemTargetLabelFormatterLink in tests/src/Functional/Plugin/Field/FieldFormatter/FeedsItemTargetLabelFormatterTest.php
Tests the feeds target label formatter as a link.
FeedsItemTargetLabelFormatterTest::testFeedsItemTargetLabelFormatterPlain in tests/src/Functional/Plugin/Field/FieldFormatter/FeedsItemTargetLabelFormatterTest.php
Tests the feeds target label formatter in plain text.

File

tests/src/Functional/Plugin/Field/FieldFormatter/FeedsItemFormatterTestBase.php, line 96

Class

FeedsItemFormatterTestBase
Base class for the feeds item field formatter tests.

Namespace

Drupal\Tests\feeds\Functional\Plugin\Field\FieldFormatter

Code

public function addFieldToFeed(FeedInterface $feed) {
  $feed_type_id = $feed
    ->getType()
    ->id();
  $this
    ->createFieldWithStorage('oneliner', [
    'entity_type' => 'feeds_feed',
    'bundle' => $feed_type_id,
    'type' => 'text',
    'label' => 'Witty one liner label',
  ]);
  $this->container
    ->get('entity_display.repository')
    ->getViewDisplay('feeds_feed', $feed_type_id, 'default')
    ->setComponent('oneliner', [
    'type' => 'text_default',
    'settings' => [
      'label' => 'Witty one liner',
    ],
  ])
    ->save();
  $feed = $this
    ->reloadEntity($feed);
  $feed->oneliner = [
    'value' => 'He is not only from medieval Japan, but also from an alternate universe, so naturally he speaks English!',
    'format' => 'plain_text',
  ];
  $feed
    ->save();
  return $feed;
}