You are here

protected function MediaForm::getMediaData in GridStack 8.2

Returns the media data.

2 calls to MediaForm::getMediaData()
Form::massageMetadata in src/Plugin/gridstack/stylizer/Form.php
Massages media metadata.
MediaForm::mediaElement in src/Plugin/gridstack/stylizer/MediaForm.php
Returns Media Library form elements adapted from MediaLibraryWidget.

File

src/Plugin/gridstack/stylizer/MediaForm.php, line 224

Class

MediaForm
Provides the media form for Layout Builder integration.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

protected function getMediaData($media, $mid = '') {
  $data = [];
  if ($mid && is_null($media)) {
    $media = Media::load($mid);
  }
  if ($media) {
    $data['media_id'] = $media
      ->id();
    $data['media_bundle'] = $media
      ->bundle();
    $data['media_source'] = $media
      ->getSource()
      ->getPluginId();
    $data['source_field'] = $media
      ->getSource()
      ->getConfiguration()['source_field'];
    $source = $media
      ->getSource();
    $plugin_definition = $source
      ->getPluginDefinition();
    if ($uri = $source
      ->getMetadata($media, $plugin_definition['thumbnail_uri_metadata_attribute'])) {
      $data['uri'] = $uri;
      $data['image_url'] = \file_url_transform_relative(\file_create_url($uri));
    }
  }
  return $data;
}