You are here

public function MediaSourceBase::prepareFormDisplay in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::prepareFormDisplay()

Prepares the media type fields for this source in the form 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 form display.

Parameters

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

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

Overrides MediaSourceInterface::prepareFormDisplay

See also

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

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

2 calls to MediaSourceBase::prepareFormDisplay()
OEmbed::prepareFormDisplay in core/modules/media/src/Plugin/media/Source/OEmbed.php
Prepares the media type fields for this source in the form display.
TestDifferentDisplays::prepareFormDisplay in core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php
Prepares the media type fields for this source in the form display.
3 methods override MediaSourceBase::prepareFormDisplay()
OEmbed::prepareFormDisplay in core/modules/media/src/Plugin/media/Source/OEmbed.php
Prepares the media type fields for this source in the form display.
TestDifferentDisplays::prepareFormDisplay in core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php
Prepares the media type fields for this source in the form display.
TestWithHiddenSourceField::prepareFormDisplay in core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestWithHiddenSourceField.php
Prepares the media type fields for this source in the form display.

File

core/modules/media/src/MediaSourceBase.php, line 354

Class

MediaSourceBase
Base implementation of media source plugin.

Namespace

Drupal\media

Code

public function prepareFormDisplay(MediaTypeInterface $type, EntityFormDisplayInterface $display) {

  // Make sure the source field is placed just after the "name" basefield.
  $name_component = $display
    ->getComponent('name');
  $source_field_weight = $name_component && isset($name_component['weight']) ? $name_component['weight'] + 5 : -50;
  $display
    ->setComponent($this
    ->getSourceFieldDefinition($type)
    ->getName(), [
    'weight' => $source_field_weight,
  ]);
}