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

Breadcrumb

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

function File::getMetadata

Overrides MediaSourceBase::getMetadata

2 calls to File::getMetadata()
Image::getMetadata in core/modules/media/src/Plugin/media/Source/Image.php
Gets the value for a metadata attribute for a given media item.
Image::getMetadata in core/modules/media/src/Plugin/media/Source/Image.php
Gets the value for a metadata attribute for a given media item.
1 method overrides File::getMetadata()
Image::getMetadata in core/modules/media/src/Plugin/media/Source/Image.php
Gets the value for a metadata attribute for a given media item.

File

core/modules/media/src/Plugin/media/Source/File.php, line 60

Class

File
File entity media source.

Namespace

Drupal\media\Plugin\media\Source

Code

public function getMetadata(MediaInterface $media, $attribute_name) {
    
    /** @var \Drupal\file\FileInterface $file */
    $file = $media->get($this->configuration['source_field'])->entity;
    // If the source field is not required, it may be empty.
    if (!$file) {
        return parent::getMetadata($media, $attribute_name);
    }
    switch ($attribute_name) {
        case static::METADATA_ATTRIBUTE_NAME:
        case 'default_name':
            return $file->getFilename();
        case static::METADATA_ATTRIBUTE_MIME:
            return $file->getMimeType();
        case static::METADATA_ATTRIBUTE_SIZE:
            return $file->getSize();
        case 'thumbnail_uri':
            return $this->getThumbnail($file) ?: parent::getMetadata($media, $attribute_name);
        default:
            return parent::getMetadata($media, $attribute_name);
    }
}

API Navigation

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