TestDifferentDisplays.php

Same filename in other branches
  1. 9 core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php
  2. 8.9.x core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php
  3. 11.x core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php

Namespace

Drupal\media_test_source\Plugin\media\Source

File

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

View source
<?php

namespace Drupal\media_test_source\Plugin\media\Source;

use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\media\Attribute\MediaSource;
use Drupal\media\MediaTypeInterface;

/**
 * Provides test media source.
 */
class TestDifferentDisplays extends Test {
    
    /**
     * {@inheritdoc}
     */
    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);
    }
    
    /**
     * {@inheritdoc}
     */
    public function prepareFormDisplay(MediaTypeInterface $type, EntityFormDisplayInterface $display) {
        parent::prepareFormDisplay($type, $display);
        $source_name = $this->getSourceFieldDefinition($type)
            ->getName();
        $source_component = $display->getComponent($source_name) ?: [];
        $source_component['type'] = 'entity_reference_autocomplete_tags';
        $display->setComponent($source_name, $source_component);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getSourceFieldName() {
        return 'field_media_different_display';
    }

}

Classes

Title Deprecated Summary
TestDifferentDisplays Provides test media source.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.