You are here

function template_preprocess_media_add_list in Media entity 8

Prepares variables for list of available media bundles.

Default template: media-add-list.html.twig.

Parameters

array $variables: An associative array containing:

  • content: An array of content types.

File

./media_entity.theme.inc, line 21
Theme functions for the media_entity module.

Code

function template_preprocess_media_add_list(&$variables) {
  $variables['bundles'] = [];
  if (!empty($variables['content'])) {
    foreach ($variables['content'] as $bundle) {

      /** @var \Drupal\media_entity\MediaBundleInterface $bundle */
      $variables['bundles'][$bundle
        ->id()] = [
        'type' => $bundle
          ->id(),
        'add_link' => Link::createFromRoute($bundle
          ->label(), 'media.add', [
          'media_bundle' => $bundle
            ->id(),
        ]),
        'description' => [
          '#markup' => $bundle
            ->getDescription(),
        ],
      ];
    }
  }
}