You are here

public function TestDifferentDisplays::prepareViewDisplay in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php \Drupal\media_test_source\Plugin\media\Source\TestDifferentDisplays::prepareViewDisplay()
  2. 10 core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php \Drupal\media_test_source\Plugin\media\Source\TestDifferentDisplays::prepareViewDisplay()

Prepares the media type fields for this source in the view display.

This method should normally call \Drupal\Core\Entity\Display\EntityDisplayInterface::setComponent() or \Drupal\Core\Entity\Display\EntityDisplayInterface::removeComponent() to configure the media type fields in the view display.

Parameters

\Drupal\media\MediaTypeInterface $type: The media type which is using this source.

\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The display which should be prepared.

Overrides MediaSourceBase::prepareViewDisplay

See also

\Drupal\Core\Entity\Display\EntityDisplayInterface::setComponent()

\Drupal\Core\Entity\Display\EntityDisplayInterface::removeComponent()

File

core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php, line 24

Class

TestDifferentDisplays
Provides test media source.

Namespace

Drupal\media_test_source\Plugin\media\Source

Code

public function prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display) {
  parent::prepareViewDisplay($type, $display);
  $source_name = $this
    ->getSourceFieldDefinition($type)
    ->getName();
  $source_component = $display
    ->getComponent($source_name) ?: [];
  $source_component['type'] = 'entity_reference_entity_id';
  $display
    ->setComponent($source_name, $source_component);
}