Unverified Commit 78a32a4d authored by larowlan's avatar larowlan
Browse files

Issue #2981105 by phenaproxima, JeroenT, seanB, catch: Media Library should...

Issue #2981105 by phenaproxima, JeroenT, seanB, catch: Media Library should not modify the media view
parent 0ec69d3f
......@@ -444,16 +444,7 @@ display:
position: 1
display_options:
display_extenders: { }
path: admin/content/media
menu:
type: tab
title: Media
description: 'Allows users to browse and administer media items'
expanded: false
parent: system.admin_content
weight: 5
context: '0'
menu_name: admin
path: admin/content/media-grid
fields:
media_bulk_form:
id: media_bulk_form
......
......@@ -6,22 +6,11 @@
*/
use Drupal\media\Entity\MediaType;
use Drupal\views\Entity\View;
/**
* Implements hook_install().
*/
function media_library_install() {
// Change the path to the original media view.
/** @var \Drupal\views\Entity\View $view */
if ($view = View::load('media')) {
$display = &$view->getDisplay('media_page_list');
if (!empty($display)) {
$display['display_options']['path'] = 'admin/content/media-table';
unset($display['display_options']['menu']);
$view->trustData()->save();
}
}
if (!\Drupal::isConfigSyncing()) {
foreach (MediaType::loadMultiple() as $type) {
_media_library_configure_form_display($type);
......@@ -30,31 +19,6 @@ function media_library_install() {
}
}
/**
* Implements hook_uninstall().
*/
function media_library_uninstall() {
// Restore the path to the original media view.
/** @var \Drupal\views\Entity\View $view */
if ($view = View::load('media')) {
$display = &$view->getDisplay('media_page_list');
if (!empty($display)) {
$display['display_options']['path'] = 'admin/content/media';
$display['display_options']['menu'] = [
'type' => 'tab',
'title' => 'Media',
'description' => '',
'expanded' => FALSE,
'parent' => '',
'weight' => 0,
'context' => '0',
'menu_name' => 'main',
];
$view->trustData()->save();
}
}
}
/**
* Create the 'media_library' image style.
*/
......
......@@ -2,4 +2,4 @@ media_library.add:
route_name: entity.media.add_page
title: 'Add media'
appears_on:
- view.media.media_page_list
- view.media_library.page
media_library.grid:
title: 'Grid'
media_library.table:
title: 'Table'
parent_id: entity.media.collection
route_name: entity.media.collection
weight: 10
media_library.table:
title: 'Table'
media_library.grid:
title: 'Grid'
parent_id: entity.media.collection
route_name: view.media.media_page_list
route_name: view.media_library.page
weight: 20
......@@ -583,3 +583,33 @@ function media_library_post_update_update_8001_checkbox_classes() {
}
}
}
/**
* Sets /admin/content/media to the table display of the 'media' view.
*/
function media_library_post_update_default_administrative_list_to_table_display() {
$view = Views::getView('media');
if ($view) {
$display = &$view->storage->getDisplay('media_page_list');
if ($display && $display['display_options']['path'] === 'admin/content/media-table') {
$display['display_options']['path'] = 'admin/content/media';
$view->storage->save();
}
}
$view = Views::getView('media_library');
if (!$view) {
return;
}
$display = &$view->storage->getDisplay('page');
if ($display && $display['display_options']['path'] === 'admin/content/media') {
$display['display_options']['path'] .= '-grid';
// Only delete the menu settings if they have not been changed.
if (isset($display['display_options']['menu']) && $display['display_options']['menu']['type'] === 'tab' && $display['display_options']['menu']['title'] === 'Media') {
unset($display['display_options']['menu']);
}
$view->storage->save();
}
}
<?php
namespace Drupal\Tests\media_library\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\views\Entity\View;
/**
* Tests update to set 'media' view's table display as the administrative page.
*
* @group media_library
* @group legacy
*/
class MediaLibrarySetAdministrativePageToTableDisplayTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
public function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.4.0.bare.standard.php.gz',
__DIR__ . '/../../../../../media/tests/fixtures/update/drupal-8.4.0-media_installed.php',
__DIR__ . '/../../../fixtures/update/drupal-8.7.2-media_library_installed.php',
];
}
/**
* Tests that the update alters uncustomized path and menu settings.
*/
public function testUpdateWithoutCustomizations() {
/** @var \Drupal\views\ViewEntityInterface $view */
$view = View::load('media');
$display = $view->getDisplay('media_page_list');
$this->assertSame('admin/content/media-table', $display['display_options']['path']);
$this->assertArrayNotHasKey('menu', $display['display_options']);
$view = View::load('media_library');
$display = $view->getDisplay('page');
$this->assertSame('admin/content/media', $display['display_options']['path']);
$this->assertSame('tab', $display['display_options']['menu']['type']);
$this->assertSame('Media', $display['display_options']['menu']['title']);
$this->runUpdates();
$view = View::load('media');
$display = $view->getDisplay('media_page_list');
$this->assertSame('admin/content/media', $display['display_options']['path']);
$this->assertArrayNotHasKey('menu', $display['display_options']);
$view = View::load('media_library');
$display = $view->getDisplay('page');
$this->assertSame('admin/content/media-grid', $display['display_options']['path']);
$this->assertArrayNotHasKey('menu', $display['display_options']);
}
/**
* Tests that the update does not alter a custom 'media' view path.
*/
public function testUpdateWithCustomizedMediaViewPath() {
/** @var \Drupal\views\ViewEntityInterface $view */
$view = View::load('media');
$display = &$view->getDisplay('media_page_list');
$display['display_options']['path'] = 'admin/content/all-media';
$view->save();
$this->runUpdates();
// The update should not have modified the path.
$view = View::load('media');
$display = $view->getDisplay('media_page_list');
$this->assertSame('admin/content/all-media', $display['display_options']['path']);
$view = View::load('media_library');
$display = $view->getDisplay('page');
$this->assertSame('admin/content/media-grid', $display['display_options']['path']);
$this->assertArrayNotHasKey('menu', $display['display_options']);
}
/**
* Tests that the update does not alter custom 'media' view menu settings.
*/
public function testUpdateWithCustomizedMediaViewMenuSettings() {
/** @var \Drupal\views\ViewEntityInterface $view */
$view = View::load('media');
$display = &$view->getDisplay('media_page_list');
$display['display_options']['menu'] = [
'type' => 'normal',
'title' => 'All media',
'parent' => 'system.admin_structure',
];
$view->save();
$this->runUpdates();
// The update should not have modified the path.
$view = View::load('media');
$display = $view->getDisplay('media_page_list');
$this->assertSame('admin/content/media', $display['display_options']['path']);
$this->assertSame('normal', $display['display_options']['menu']['type']);
$this->assertSame('All media', $display['display_options']['menu']['title']);
$this->assertSame('system.admin_structure', $display['display_options']['menu']['parent']);
$view = View::load('media_library');
$display = $view->getDisplay('page');
$this->assertSame('admin/content/media-grid', $display['display_options']['path']);
$this->assertArrayNotHasKey('menu', $display['display_options']);
}
/**
* Tests that the update does not alter custom 'media' path and menu settings.
*/
public function testUpdateWithCustomizedMediaLibraryViewPath() {
/** @var \Drupal\views\ViewEntityInterface $view */
$view = View::load('media_library');
$display = &$view->getDisplay('page');
$display['display_options']['path'] = 'admin/content/media-pretty';
$view->save();
$this->runUpdates();
// The update should not have modified the path or menu settings.
$view = View::load('media_library');
$display = $view->getDisplay('page');
$this->assertSame('admin/content/media-pretty', $display['display_options']['path']);
$this->assertSame('tab', $display['display_options']['menu']['type']);
$this->assertSame('Media', $display['display_options']['menu']['title']);
}
/**
* Tests that the update preserves custom 'media_library' menu settings.
*/
public function testUpdateWithCustomizedMediaLibraryMenuSettings() {
/** @var \Drupal\views\ViewEntityInterface $view */
$view = View::load('media_library');
$display = &$view->getDisplay('page');
$display['display_options']['menu'] = [
'type' => 'normal',
'title' => 'A treasure trove of interesting pictures',
'parent' => 'system.admin_structure',
];
$view->save();
$this->runUpdates();
// The update should have changed the path but preserved the menu settings.
$view = View::load('media_library');
$display = $view->getDisplay('page');
$this->assertSame('admin/content/media-grid', $display['display_options']['path']);
$this->assertSame('normal', $display['display_options']['menu']['type']);
$this->assertSame('A treasure trove of interesting pictures', $display['display_options']['menu']['title']);
$this->assertSame('system.admin_structure', $display['display_options']['menu']['parent']);
}
}
......@@ -100,6 +100,18 @@ public function testAdministrationPage() {
// Visit the administration page.
$this->drupalGet('admin/content/media');
// There should be links to both the grid and table displays.
$assert_session->linkExists('Grid');
$assert_session->linkExists('Table');
// We should see the table view and a link to add media.
$assert_session->elementExists('css', '.view-media .views-table');
$assert_session->linkExists('Add media');
// Go to the grid display for the rest of the test.
$page->clickLink('Grid');
$assert_session->addressEquals('admin/content/media-grid');
// Verify that the "Add media" link is present.
$assert_session->linkExists('Add media');
......@@ -157,13 +169,6 @@ public function testAdministrationPage() {
// Test empty text.
$assert_session->pageTextContains('No media available.');
// Verify that the "Table" link is present, click it and check address.
$assert_session->linkExists('Table');
$page->clickLink('Table');
$assert_session->addressEquals('admin/content/media-table');
// Verify that the "Add media" link is present.
$assert_session->linkExists('Add media');
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment