You are here

public function Image::prepareViewDisplay in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/media/src/Plugin/media/Source/Image.php \Drupal\media\Plugin\media\Source\Image::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/src/Plugin/media/Source/Image.php, line 168

Class

Image
Image entity media source.

Namespace

Drupal\media\Plugin\media\Source

Code

public function prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display) {
  parent::prepareViewDisplay($type, $display);

  // Use the `large` image style and do not link the image to anything.
  // This will prevent the out-of-the-box configuration from outputting very
  // large raw images. If the `large` image style has been deleted, do not
  // set an image style.
  $field_name = $this
    ->getSourceFieldDefinition($type)
    ->getName();
  $component = $display
    ->getComponent($field_name);
  $component['settings']['image_link'] = '';
  $component['settings']['image_style'] = '';
  if ($this->entityTypeManager
    ->getStorage('image_style')
    ->load('large')) {
    $component['settings']['image_style'] = 'large';
  }
  $display
    ->setComponent($field_name, $component);
}