Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / media_entity / media_entity.module
1 <?php
2
3 /**
4  * @file
5  * Provides media entities.
6  */
7
8 use Drupal\Core\Routing\RouteMatchInterface;
9
10 /**
11  * Implements hook_help().
12  */
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>.',
18           [
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',
21           ]) . '</p>';
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>.',
24           [
25             ':media_entity_handbook' => 'https://drupal-media.gitbooks.io/drupal8-guide/content/modules/media_entity/intro.html',
26           ]) . '</p>';
27
28       return $output;
29   }
30 }
31
32 /**
33  * Implements hook_theme().
34  */
35 function media_entity_theme() {
36   return [
37     'media' => [
38       'render element' => 'elements',
39       'file' => 'media_entity.theme.inc',
40       'template' => 'media',
41     ],
42   ];
43 }
44
45 /**
46  * Implements hook_theme_suggestions_HOOK().
47  */
48 function media_entity_theme_suggestions_media(array $variables) {
49   $suggestions = [];
50   $media = $variables['elements']['#media'];
51   $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
52
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;
58
59   return $suggestions;
60 }
61
62 /**
63  * Copy the media file icons to files directory for use with image styles.
64  *
65  * @param string $source
66  *   Source folder.
67  * @param string $destination
68  *   Destination folder.
69  *
70  * @throws Exception
71  */
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.");
75   }
76
77   $files = file_scan_directory($source, '/.*\.(png|jpg)$/');
78   foreach ($files as $file) {
79     $result = file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_REPLACE);
80     if (!$result) {
81       throw new Exception("Unable to copy {$file->uri} to $destination.");
82     }
83   }
84 }