Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Image.php

function Image::prepareViewDisplay

Overrides MediaSourceBase::prepareViewDisplay

File

core/modules/media/src/Plugin/media/Source/Image.php, line 170

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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal