class TestDifferentDisplays
Provides test media source.
Plugin annotation
@MediaSource(
id = "test_different_displays",
label = @Translation("Test source with different displays"),
description = @Translation("Test source with different displays."),
allowed_field_types = {"entity_reference"},
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\media\MediaSourceBase implements \Drupal\media\MediaSourceInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\media_test_source\Plugin\media\Source\Test extends \Drupal\media\MediaSourceBase
- class \Drupal\media_test_source\Plugin\media\Source\TestDifferentDisplays extends \Drupal\media_test_source\Plugin\media\Source\Test
- class \Drupal\media_test_source\Plugin\media\Source\Test extends \Drupal\media\MediaSourceBase
- class \Drupal\media\MediaSourceBase implements \Drupal\media\MediaSourceInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of TestDifferentDisplays
File
-
core/
modules/ media/ tests/ modules/ media_test_source/ src/ Plugin/ media/ Source/ TestDifferentDisplays.php, line 19
Namespace
Drupal\media_test_source\Plugin\media\SourceView 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';
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.