3 namespace Drupal\media_test_source\Plugin\media\Source;
5 use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
6 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
7 use Drupal\media\MediaTypeInterface;
10 * Provides test media source.
13 * id = "test_different_displays",
14 * label = @Translation("Test source with different displays"),
15 * description = @Translation("Test source with different displays."),
16 * allowed_field_types = {"entity_reference"},
19 class TestDifferentDisplays extends Test {
24 public function prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display) {
25 parent::prepareViewDisplay($type, $display);
26 $source_name = $this->getSourceFieldDefinition($type)->getName();
27 $source_component = $display->getComponent($source_name) ?: [];
28 $source_component['type'] = 'entity_reference_entity_id';
29 $display->setComponent($source_name, $source_component);
35 public function prepareFormDisplay(MediaTypeInterface $type, EntityFormDisplayInterface $display) {
36 parent::prepareFormDisplay($type, $display);
37 $source_name = $this->getSourceFieldDefinition($type)->getName();
38 $source_component = $display->getComponent($source_name) ?: [];
39 $source_component['type'] = 'entity_reference_autocomplete_tags';
40 $display->setComponent($source_name, $source_component);
46 protected function getSourceFieldName() {
47 return 'field_media_different_display';