5 * Provides media entities.
8 use Drupal\Core\Routing\RouteMatchInterface;
11 * Implements hook_help().
13 function media_entity_help($route_name, RouteMatchInterface $route_match) {
14 switch ($route_name) {
15 case 'help.page.media_entity':
16 $output = '<h3>' . t('About') . '</h3>';
17 $output .= '<p>' . t('The <a href=":media_entity_url">Media Entity</a> module provides a "base" entity for media. This is a very basic entity which can reference to all kinds of media-objects (local files, YouTube videos, Tweets, Instagram photos, ...). Media entity provides a relation between your website and the media resource. You can reference to/use this entity within any other entity on your site. For more information, see the <a href=":media_entity_handbook">online documentation for the Media Entity module</a>.',
19 ':media_entity_url' => 'https://www.drupal.org/project/media_entity',
20 ':media_entity_handbook' => 'https://drupal-media.gitbooks.io/drupal8-guide/content/modules/media_entity/intro.html',
22 $output .= '<h3>' . t('Uses') . '</h3>';
23 $output .= '<p>' . t('For detailed information about the usage of this module please refer to <a href=":media_entity_handbook">the official documentation</a>.',
25 ':media_entity_handbook' => 'https://drupal-media.gitbooks.io/drupal8-guide/content/modules/media_entity/intro.html',
33 * Implements hook_theme().
35 function media_entity_theme() {
38 'render element' => 'elements',
39 'file' => 'media_entity.theme.inc',
40 'template' => 'media',
46 * Implements hook_theme_suggestions_HOOK().
48 function media_entity_theme_suggestions_media(array $variables) {
50 $media = $variables['elements']['#media'];
51 $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
53 $suggestions[] = 'media__' . $sanitized_view_mode;
54 $suggestions[] = 'media__' . $media->bundle();
55 $suggestions[] = 'media__' . $media->bundle() . '__' . $sanitized_view_mode;
56 $suggestions[] = 'media__' . $media->id();
57 $suggestions[] = 'media__' . $media->id() . '__' . $sanitized_view_mode;
63 * Copy the media file icons to files directory for use with image styles.
65 * @param string $source
67 * @param string $destination
72 function media_entity_copy_icons($source, $destination) {
73 if (!file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
74 throw new Exception("Unable to create directory $destination.");
77 $files = file_scan_directory($source, '/.*\.(png|jpg)$/');
78 foreach ($files as $file) {
79 $result = file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_REPLACE);
81 throw new Exception("Unable to copy {$file->uri} to $destination.");