Completed
Pull Request — 8.x-1.x (#11)
by Vijay
02:40
created
media.module 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@  discard block
 block discarded – undo
13 13
  * Implements hook_help().
14 14
  */
15 15
 function media_help($route_name, RouteMatchInterface $route_match) {
16
-  switch ($route_name) {
16
+    switch ($route_name) {
17 17
     // Main module help for the media module.
18 18
     case 'help.page.media':
19 19
       $output = '';
20
-      $output .= '<h3>' . t('About') . '</h3>';
21
-      $output .= '<p>' . t('Media module for Drupal 8') . '</p>';
22
-      return $output;
20
+        $output .= '<h3>' . t('About') . '</h3>';
21
+        $output .= '<p>' . t('Media module for Drupal 8') . '</p>';
22
+        return $output;
23 23
 
24 24
     default:
25 25
   }
@@ -29,29 +29,29 @@  discard block
 block discarded – undo
29 29
  * Implements hook_form_alter().
30 30
  */
31 31
 function media_form_alter(&$form, FormStateInterface &$form_state) {
32
-  if ($form['#form_id'] == 'entity_browser_media_library_form') {
32
+    if ($form['#form_id'] == 'entity_browser_media_library_form') {
33 33
     // Style the submit button.
34 34
     $form['actions']['submit']['#attributes']['class'][] = 'button--primary';
35 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') {
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 39
     unset($form['bundle_1']['#options']['gallery']);
40
-  }
40
+    }
41 41
 }
42 42
 
43 43
 /**
44 44
  * Implements hook_library_info_alter().
45 45
  */
46 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')) {
47
+    // Optionally use the Libraries module to determine our library paths.
48
+    if ($extension == 'media' && \Drupal::moduleHandler()->moduleExists('libraries')) {
49 49
     $imagesloaded_path = libraries_get_path('imagesloaded') . '/imagesloaded.pkgd.min.js';
50 50
     $masonry_path = libraries_get_path('masonry') . '/dist/masonry.pkgd.min.js';
51 51
 
52 52
     $libraries['imagesloaded']['js'] = ['/' . $imagesloaded_path => ['minified' => 'true']];
53 53
     $libraries['masonry']['js'] = ['/' . $masonry_path => ['minified' => 'true']];
54
-  }
54
+    }
55 55
 }
56 56
 
57 57
 /**
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
  * Adds the media.view library to the media views.
61 61
  */
62 62
 function media_views_pre_render(ViewExecutable $view) {
63
-  if (isset($view) && ($view->storage->id() == 'media_library' || $view->storage->id() == 'global_media_library')) {
63
+    if (isset($view) && ($view->storage->id() == 'media_library' || $view->storage->id() == 'global_media_library')) {
64 64
     $view->element['#attached']['library'][] = 'media/view';
65
-  }
65
+    }
66 66
 }
67 67
 
68 68
 /**
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
  * Adds the add media button from media_entity on library pages.
72 72
  */
73 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';
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 76
 }
77 77
 
78 78
 /**
79 79
  * Implements hook_entity_type_alter().
80 80
  */
81 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));
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 84
 }
Please login to merge, or discard this patch.
src/Tests/GalleryBundleTest.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -10,59 +10,59 @@  discard block
 block discarded – undo
10 10
  * @group media
11 11
  */
12 12
 class GalleryBundleTest extends WebTestBase {
13
-  /**
14
-   * Exempt from strict schema checking.
15
-   *
16
-   * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17
-   *
18
-   * @var bool
19
-   */
20
-  protected $strictConfigSchema = FALSE;
21
-
22
-  /**
23
-   * Modules to enable.
24
-   *
25
-   * @var array
26
-   */
27
-  public static $modules = [
13
+    /**
14
+     * Exempt from strict schema checking.
15
+     *
16
+     * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17
+     *
18
+     * @var bool
19
+     */
20
+    protected $strictConfigSchema = FALSE;
21
+
22
+    /**
23
+     * Modules to enable.
24
+     *
25
+     * @var array
26
+     */
27
+    public static $modules = [
28 28
     'media',
29 29
     'media_entity',
30 30
     'media_entity_slideshow',
31 31
     'node',
32
-  ];
33
-
34
-  /**
35
-   * The test media bundle.
36
-   *
37
-   * @var \Drupal\media_entity\MediaBundleInterface
38
-   */
39
-  protected $testBundle;
40
-
41
-  /**
42
-   * {@inheritdoc}
43
-   */
44
-  protected function setUp() {
32
+    ];
33
+
34
+    /**
35
+     * The test media bundle.
36
+     *
37
+     * @var \Drupal\media_entity\MediaBundleInterface
38
+     */
39
+    protected $testBundle;
40
+
41
+    /**
42
+     * {@inheritdoc}
43
+     */
44
+    protected function setUp() {
45 45
     parent::setUp();
46 46
     $this->testBundle = $this->container->get('entity_type.manager')->getStorage('media_bundle')->load('gallery');
47 47
 
48 48
     $adminUser = $this->drupalCreateUser([
49
-      'view media',
50
-      'create media',
51
-      'update media',
52
-      'update any media',
53
-      'delete media',
54
-      'delete any media',
55
-      'access media overview',
49
+        'view media',
50
+        'create media',
51
+        'update media',
52
+        'update any media',
53
+        'delete media',
54
+        'delete any media',
55
+        'access media overview',
56 56
     ]);
57 57
     $this->drupalLogin($adminUser);
58
-  }
58
+    }
59 59
 
60
-  /**
61
-   * Tests gallery media bundle creation from config files.
62
-   */
63
-  public function testMediaBundleCreationFromModule() {
60
+    /**
61
+     * Tests gallery media bundle creation from config files.
62
+     */
63
+    public function testMediaBundleCreationFromModule() {
64 64
     $type_configuration = [
65
-      'source_field' => 'field_slide',
65
+        'source_field' => 'field_slide',
66 66
     ];
67 67
 
68 68
     $this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.');
@@ -71,21 +71,21 @@  discard block
 block discarded – undo
71 71
     $this->assertEqual($this->testBundle->get('type'), 'slideshow', 'Correct plugin ID detected.');
72 72
     $this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.');
73 73
     $this->assertEqual($this->testBundle->get('field_map'), [], 'Correct field map detected.');
74
-  }
74
+    }
75 75
 
76
-  /**
77
-   * Tests thumbnail of the gallery item.
78
-   */
79
-  public function testGalleryItemThumbnail() {
76
+    /**
77
+     * Tests thumbnail of the gallery item.
78
+     */
79
+    public function testGalleryItemThumbnail() {
80 80
     // Let's add one image and one video.
81 81
     $imageItem = $this->addImageItem();
82 82
     $videoItem = $this->addVideoItem();
83 83
     $this->drupalGet('media/add/gallery');
84 84
     $pathValue = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-slide-entity-browser-path"]/@value'));
85 85
     $edit = [
86
-      'name[0][value]' => 'Gallery item',
87
-      'field_slide[target_id]' => $imageItem['id'] . ' ' . $videoItem['id'],
88
-      'field_slide[entity_browser][path]' => $pathValue,
86
+        'name[0][value]' => 'Gallery item',
87
+        'field_slide[target_id]' => $imageItem['id'] . ' ' . $videoItem['id'],
88
+        'field_slide[entity_browser][path]' => $pathValue,
89 89
     ];
90 90
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
91 91
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
     $this->drupalGet('media/add/gallery');
104 104
     $edit = [
105
-      'name[0][value]' => 'Gallery item 2',
106
-      'field_slide[target_id]' => $videoItem['id'] . ' ' . $imageItem['id'] ,
107
-      'field_slide[entity_browser][path]' => $pathValue,
105
+        'name[0][value]' => 'Gallery item 2',
106
+        'field_slide[target_id]' => $videoItem['id'] . ' ' . $imageItem['id'] ,
107
+        'field_slide[entity_browser][path]' => $pathValue,
108 108
     ];
109 109
     $this->drupalPostForm(NULL, $edit, t('Save and publish'));
110 110
 
@@ -113,36 +113,36 @@  discard block
 block discarded – undo
113 113
     $gallery = $this->loadMediaItem(reset($gallery_id));
114 114
     $gallery_thumbnail = $gallery->getType()->thumbnail($gallery);
115 115
     $this->assertEqual($gallery_thumbnail, $video_thumbnail, "Correct thumbnail detected.");
116
-  }
116
+    }
117 117
 
118
-  /**
119
-   * Tests that gallery option isn't available in gallery create bundle filters.
120
-   */
121
-  public function testGalleryOption() {
118
+    /**
119
+     * Tests that gallery option isn't available in gallery create bundle filters.
120
+     */
121
+    public function testGalleryOption() {
122 122
     // Open the gallery create page.
123 123
     $this->drupalGet('media/add/gallery');
124 124
     $pathValue = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-slide-entity-browser-path"]/@value'));
125 125
     $triggeringElement = (string) current($this->xpath('//input[@data-drupal-selector="edit-field-slide-entity-browser-open-modal"]/@name'));
126 126
     $edit = [
127
-      'field_slide[entity_browser][path]' => $pathValue,
127
+        'field_slide[entity_browser][path]' => $pathValue,
128 128
     ];
129 129
     $this->drupalPostAjaxForm(NULL, $edit, $triggeringElement);
130 130
 
131 131
     $this->assertNoOption('edit-bundle-1', 'gallery');
132 132
     $this->assertOption('edit-bundle-1', 'video');
133
-  }
133
+    }
134 134
 
135
-  /**
136
-   * Adds image type item.
137
-   */
138
-  public function addImageItem() {
135
+    /**
136
+     * Adds image type item.
137
+     */
138
+    public function addImageItem() {
139 139
     // Let's add image first.
140 140
     $name = $this->randomMachineName();
141 141
     $testImage = current($this->drupalGetTestFiles('image'));
142 142
     $file_path = $this->container->get('file_system')->realpath($testImage->uri);
143 143
     $edit = [
144
-      'name[0][value]' => $name,
145
-      'files[field_image_0]' => $file_path,
144
+        'name[0][value]' => $name,
145
+        'files[field_image_0]' => $file_path,
146 146
     ];
147 147
     // Save the image.
148 148
     $this->drupalPostForm('media/add/image', $edit, t('Save and publish'));
@@ -153,15 +153,15 @@  discard block
 block discarded – undo
153 153
     $edit['id'] = $media_id;
154 154
 
155 155
     return $edit;
156
-  }
156
+    }
157 157
 
158
-  /**
159
-   * Adds video type item.
160
-   */
161
-  public function addVideoItem() {
158
+    /**
159
+     * Adds video type item.
160
+     */
161
+    public function addVideoItem() {
162 162
     $edit = [
163
-      'name[0][value]' => 'Drupal video!',
164
-      'field_video[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
163
+        'name[0][value]' => 'Drupal video!',
164
+        'field_video[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
165 165
     ];
166 166
     $this->drupalPostForm('media/add/video', $edit, t('Save and publish'));
167 167
     // Obtain the video id.
@@ -170,22 +170,22 @@  discard block
 block discarded – undo
170 170
     $edit['id'] = $media_id;
171 171
 
172 172
     return $edit;
173
-  }
174
-
175
-  /**
176
-   * Loads the media entity item.
177
-   *
178
-   * @param int $id
179
-   *   The id of the item.
180
-   *
181
-   * @return \Drupal\media_entity\MediaInterface
182
-   *   The media entity item.
183
-   */
184
-  public function loadMediaItem($id) {
173
+    }
174
+
175
+    /**
176
+     * Loads the media entity item.
177
+     *
178
+     * @param int $id
179
+     *   The id of the item.
180
+     *
181
+     * @return \Drupal\media_entity\MediaInterface
182
+     *   The media entity item.
183
+     */
184
+    public function loadMediaItem($id) {
185 185
     $item = $this->container->get('entity_type.manager')
186
-      ->getStorage('media')
187
-      ->loadUnchanged($id);
186
+        ->getStorage('media')
187
+        ->loadUnchanged($id);
188 188
     return $item;
189
-  }
189
+    }
190 190
 
191 191
 }
Please login to merge, or discard this patch.