1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Contains media.module. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
use Drupal\Core\Routing\RouteMatchInterface; |
9
|
|
|
use Drupal\Core\Form\FormStateInterface; |
10
|
|
|
use Drupal\views\ViewExecutable; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Implements hook_help(). |
14
|
|
|
*/ |
15
|
|
|
function media_help($route_name, RouteMatchInterface $route_match) { |
|
|
|
|
16
|
|
|
switch ($route_name) { |
17
|
|
|
// Main module help for the media module. |
18
|
|
|
case 'help.page.media': |
19
|
|
|
$output = ''; |
20
|
|
|
$output .= '<h3>' . t('About') . '</h3>'; |
21
|
|
|
$output .= '<p>' . t('Media module for Drupal 8') . '</p>'; |
22
|
|
|
return $output; |
23
|
|
|
|
24
|
|
|
default: |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Implements hook_form_alter(). |
30
|
|
|
*/ |
31
|
|
|
function media_form_alter(&$form, FormStateInterface &$form_state) { |
|
|
|
|
32
|
|
|
if ($form['#form_id'] == 'entity_browser_media_library_form') { |
33
|
|
|
// Style the submit button. |
34
|
|
|
$form['actions']['submit']['#attributes']['class'][] = 'button--primary'; |
35
|
|
|
$form['actions']['submit']['#attributes']['class'][] = 'entity-browser-modal-target'; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Implements hook_library_info_alter(). |
41
|
|
|
*/ |
42
|
|
|
function media_library_info_alter(&$libraries, $extension) { |
43
|
|
|
// Optionally use the Libraries module to determine our library paths. |
44
|
|
|
if ($extension == 'media' && \Drupal::moduleHandler()->moduleExists('libraries')) { |
45
|
|
|
$imagesloaded_path = libraries_get_path('imagesloaded') . '/imagesloaded.pkgd.min.js'; |
46
|
|
|
$masonry_path = libraries_get_path('masonry') . '/dist/masonry.pkgd.min.js'; |
47
|
|
|
|
48
|
|
|
$libraries['imagesloaded']['js'] = ['/' . $imagesloaded_path => ['minified' => 'true']]; |
49
|
|
|
$libraries['masonry']['js'] = ['/' . $masonry_path => ['minified' => 'true']]; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Implements hook_views_pre_render(). |
55
|
|
|
* |
56
|
|
|
* Adds the media.view library to the media views. |
57
|
|
|
*/ |
58
|
|
|
function media_views_pre_render(ViewExecutable $view) { |
59
|
|
|
if (isset($view) && ($view->storage->id() == 'media_library' || $view->storage->id() == 'global_media_library')) { |
60
|
|
|
$view->element['#attached']['library'][] = 'media/view'; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Implements hook_menu_local_actions_alter(). |
66
|
|
|
* |
67
|
|
|
* Adds the add media button from media_entity on library pages. |
68
|
|
|
*/ |
69
|
|
|
function media_menu_local_actions_alter(&$local_actions) { |
70
|
|
|
$local_actions['media.add']['appears_on'][] = 'view.media_library.user_media_library'; |
71
|
|
|
$local_actions['media.add']['appears_on'][] = 'view.media_library.global_media_library_page'; |
72
|
|
|
} |
73
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.