You are here

function lightning_media_entity_extra_field_info in Lightning Media 8

Same name and namespace in other branches
  1. 8.4 lightning_media.module \lightning_media_entity_extra_field_info()
  2. 8.2 lightning_media.module \lightning_media_entity_extra_field_info()
  3. 8.3 lightning_media.module \lightning_media_entity_extra_field_info()

Implements hook_entity_extra_field_info().

File

./lightning_media.module, line 208
Core media asset support for Lightning.

Code

function lightning_media_entity_extra_field_info() {
  $extra_fields = [];
  if (\Drupal::moduleHandler()
    ->moduleExists('media')) {

    /** @var \Drupal\media\MediaTypeInterface $media_type */
    foreach (MediaType::loadMultiple() as $id => $media_type) {
      $plugin_definition = $media_type
        ->getSource()
        ->getPluginDefinition();
      if (isset($plugin_definition['preview'])) {
        $extra_fields['media'][$id]['form']['preview'] = [
          'label' => t('Preview'),
          'description' => t('A live preview of the @media_type.', [
            '@media_type' => $media_type
              ->label(),
          ]),
          'weight' => 0,
        ];
      }
    }
  }
  return $extra_fields;
}