These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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) { |
||
0 ignored issues
–
show
|
|||
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) { |
||
0 ignored issues
–
show
|
|||
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 | // Remove the Gallery option from create gallery view's bundle filters. |
||
38 | if ($form['#id'] == 'views-exposed-form-media-library-gallery-media-select-modal' || $form['#id'] == 'views-exposed-form-media-library-gallery-user-media-select-modal') { |
||
39 | unset($form['bundle_1']['#options']['gallery']); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Implements hook_library_info_alter(). |
||
45 | */ |
||
46 | function media_library_info_alter(&$libraries, $extension) { |
||
47 | // Optionally use the Libraries module to determine our library paths. |
||
48 | if ($extension == 'media' && \Drupal::moduleHandler()->moduleExists('libraries')) { |
||
49 | $imagesloaded_path = libraries_get_path('imagesloaded') . '/imagesloaded.pkgd.min.js'; |
||
50 | $masonry_path = libraries_get_path('masonry') . '/dist/masonry.pkgd.min.js'; |
||
51 | |||
52 | $libraries['imagesloaded']['js'] = ['/' . $imagesloaded_path => ['minified' => 'true']]; |
||
53 | $libraries['masonry']['js'] = ['/' . $masonry_path => ['minified' => 'true']]; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Implements hook_views_pre_render(). |
||
59 | * |
||
60 | * Adds the media.view library to the media views. |
||
61 | */ |
||
62 | function media_views_pre_render(ViewExecutable $view) { |
||
63 | if (isset($view) && ($view->storage->id() == 'media_library' || $view->storage->id() == 'global_media_library')) { |
||
64 | $view->element['#attached']['library'][] = 'media/view'; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Implements hook_menu_local_actions_alter(). |
||
70 | * |
||
71 | * Adds the add media button from media_entity on library pages. |
||
72 | */ |
||
73 | function media_menu_local_actions_alter(&$local_actions) { |
||
74 | $local_actions['media.add']['appears_on'][] = 'view.media_library.user_media_library'; |
||
75 | $local_actions['media.add']['appears_on'][] = 'view.media_library.global_media_library_page'; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Implements hook_entity_type_alter(). |
||
80 | */ |
||
81 | function media_entity_type_alter(array &$entity_types) { |
||
82 | $field_name = \Drupal::config('media_entity.bundle.gallery')->get('type_configuration.source_field'); |
||
83 | $entity_types['media']->addConstraint('GalleryMediaBundle', array('sourceFieldName' => $field_name)); |
||
84 | } |
||
85 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.