Skip to content
Snippets Groups Projects
Commit c6c18413 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #3034242 by oknate, phenaproxima, Wim Leers, webchick, seanB, larowlan,...

Issue #3034242 by oknate, phenaproxima, Wim Leers, webchick, seanB, larowlan, bnjmnm, jrockowitz, ckrina, benjifisher, andrewmacpherson, dww, jibran: Hide "Save and insert" and "Additional selected media" from users by default
parent f9528c5b
No related branches found
No related tags found
6 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards
Showing
with 803 additions and 13 deletions
advanced_ui: false
......@@ -8,3 +8,11 @@ field.widget.settings.media_library_widget:
sequence:
type: string
label: 'Media type ID'
media_library.settings:
type: config_object
label: 'Media library settings'
mapping:
advanced_ui:
type: boolean
label: 'Enable advanced UI'
......@@ -191,3 +191,14 @@ function media_library_update_8703() {
// items in the 'media' view. It has been converted to a post-update hook.
// @see media_library_post_update_add_buttons_to_page_view()
}
/**
* Creates the media_library.settings config object.
*/
function media_library_update_8704() {
\Drupal::configFactory()
->getEditable('media_library.settings')
// Enable the advanced UI by default, to preserve existing behavior.
->set('advanced_ui', TRUE)
->save();
}
media_library.settings:
title: 'Media Library settings'
parent: system.admin_config_media
description: 'Manage Media Library settings.'
route_name: media_library.settings
......@@ -4,3 +4,11 @@ media_library.ui:
_controller: 'media_library.ui_builder:buildUi'
requirements:
_custom_access: 'media_library.ui_builder:checkAccess'
media_library.settings:
path: '/admin/config/media/media-library'
defaults:
_form: '\Drupal\media_library\Form\SettingsForm'
_title: 'Media Library settings'
requirements:
_permission: 'administer media'
......@@ -379,7 +379,7 @@ protected function buildEntityFormElement(MediaInterface $media, array $form, Fo
protected function buildCurrentSelectionArea(array $form, FormStateInterface $form_state) {
$pre_selected_items = $this->getPreSelectedMediaItems($form_state);
if (!$pre_selected_items) {
if (!$pre_selected_items || !$this->isAdvancedUi()) {
return [];
}
......@@ -461,26 +461,32 @@ protected function buildSelectedItemElement(MediaInterface $media, array $form,
* An actions element containing the actions of the form.
*/
protected function buildActions(array $form, FormStateInterface $form_state) {
return [
$actions = [
'#type' => 'actions',
'save_select' => [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this->t('Save and select'),
'#value' => $this->t('Save'),
'#ajax' => [
'callback' => '::updateLibrary',
'wrapper' => 'media-library-add-form-wrapper',
],
],
'save_insert' => [
'#type' => 'submit',
'#value' => $this->t('Save and insert'),
'#ajax' => [
'callback' => '::updateWidget',
'wrapper' => 'media-library-add-form-wrapper',
],
],
];
if ($this->isAdvancedUi()) {
$actions['save_select']['#value'] = $this->t('Save and select');
$actions['save_insert'] = [
'save_insert' => [
'#type' => 'submit',
'#value' => $this->t('Save and insert'),
'#ajax' => [
'callback' => '::updateWidget',
'wrapper' => 'media-library-add-form-wrapper',
],
],
];
}
return $actions;
}
/**
......@@ -840,4 +846,19 @@ protected function getCurrentMediaItems(FormStateInterface $form_state) {
return array_merge($pre_selected_media, $added_media);
}
/**
* Determines if the "advanced UI" of the Media Library is enabled.
*
* This exposes additional features that are useful to power users.
*
* @return bool
* TRUE if the advanced UI is enabled, FALSE otherwise.
*
* @see ::buildActions()
* @see ::buildCurrentSelectionArea()
*/
protected function isAdvancedUi() {
return (bool) $this->config('media_library.settings')->get('advanced_ui');
}
}
<?php
namespace Drupal\media_library\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Defines a form for configuring the Media Library module.
*/
class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getEditableConfigNames() {
return ['media_library.settings'];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'media_library_settings_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['advanced_ui'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable advanced UI'),
'#default_value' => $this->config('media_library.settings')->get('advanced_ui'),
'#description' => $this->t('If checked, users creating new media items in the media library will see a summary of their selected media items, and they will be able insert their selection directly into the media field or text editor.'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('media_library.settings')
->set('advanced_ui', (bool) $form_state->getValue('advanced_ui'))
->save();
parent::submitForm($form, $form_state);
}
}
<?php
namespace Drupal\Tests\media_library\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the Media Library settings form.
*
* @coversDefaultClass \Drupal\media_library\Form\SettingsForm
* @group media_library
*
* @todo Roll this test into
* https://www.drupal.org/project/drupal/issues/3087227
*/
class SettingsFormTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['media_library'];
/**
* Tests the Media Library settings form.
*/
public function testSettingsForm() {
$account = $this->drupalCreateUser([
'access administration pages',
'administer media',
]);
$this->drupalLogin($account);
$page = $this->getSession()->getPage();
$assert_session = $this->assertSession();
$this->drupalGet('/admin/config');
$page->clickLink('Media Library settings');
$page->checkField('Enable advanced UI');
$page->pressButton('Save configuration');
$assert_session->checkboxChecked('Enable advanced UI');
$page->uncheckField('Enable advanced UI');
$page->pressButton('Save configuration');
$assert_session->checkboxNotChecked('Enable advanced UI');
}
}
<?php
namespace Drupal\Tests\media_library\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests update path to create the media_library.settings config object.
*
* @group media_library
* @group legacy
*
* @covers media_library_update_8704
*/
class MediaLibraryUpdate8704Test 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 creates the media_library.settings config object.
*/
public function testUpdate() {
$this->assertNull($this->config('media_library.settings')->get('advanced_ui'));
$this->runUpdates();
$this->assertTrue($this->config('media_library.settings')->get('advanced_ui'));
}
}
......@@ -69,6 +69,10 @@ protected function setUp() {
])
->save();
$this->config('media_library.settings')
->set('advanced_ui', TRUE)
->save();
$user = $this->drupalCreateUser([
'access content',
'access media overview',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment