Commit 8353d873 authored by oknate's avatar oknate Committed by oknate

Issue #3038292 by oknate: Adding confirmation message after saving config form

parent 3c65efec
......@@ -149,7 +149,7 @@ function entity_browser_file_validate_image_resolution(FileInterface $file, $max
if (!$file->isPermanent() && $image->scale($width, $height)) {
$image->save();
$file->filesize = $image->getFileSize();
drupal_set_message(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', ['%dimensions' => $maximum_dimensions]));
\Drupal::messenger()->addMessage(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', ['%dimensions' => $maximum_dimensions]));
}
else {
$errors[] = t('The image exceeds the maximum allowed dimensions.');
......
......@@ -10,6 +10,7 @@ use Drupal\entity_browser\WidgetManager;
use Drupal\entity_browser\WidgetSelectorManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\SubformState;
use Drupal\Core\Messenger\MessengerInterface;
/**
* Class EntityBrowserEditForm.
......@@ -55,12 +56,15 @@ class EntityBrowserEditForm extends EntityForm {
* Entity browser selection display plugin manager.
* @param \Drupal\entity_browser\WidgetManager $widget_manager
* Entity browser widget plugin manager.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(DisplayManager $display_manager, WidgetSelectorManager $widget_selector_manager, SelectionDisplayManager $selection_display_manager, WidgetManager $widget_manager) {
public function __construct(DisplayManager $display_manager, WidgetSelectorManager $widget_selector_manager, SelectionDisplayManager $selection_display_manager, WidgetManager $widget_manager, MessengerInterface $messenger) {
$this->displayManager = $display_manager;
$this->selectionDisplayManager = $selection_display_manager;
$this->widgetSelectorManager = $widget_selector_manager;
$this->widgetManager = $widget_manager;
$this->messenger = $messenger;
}
/**
......@@ -71,7 +75,8 @@ class EntityBrowserEditForm extends EntityForm {
$container->get('plugin.manager.entity_browser.display'),
$container->get('plugin.manager.entity_browser.widget_selector'),
$container->get('plugin.manager.entity_browser.selection_display'),
$container->get('plugin.manager.entity_browser.widget')
$container->get('plugin.manager.entity_browser.widget'),
$container->get('messenger')
);
}
......@@ -450,4 +455,18 @@ class EntityBrowserEditForm extends EntityForm {
}
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$status = $this->entity->save();
if ($status == SAVED_UPDATED) {
$this->messenger->addMessage($this->t('The entity browser %name has been updated.', ['%name' => $this->entity->label()]));
}
elseif ($status == SAVED_NEW) {
$this->messenger->addMessage($this->t('The entity browser %name has been added. Now you may configure the widgets you would like to use.', ['%name' => $this->entity->label()]));
}
}
}
......@@ -7,6 +7,7 @@ use Drupal\Core\Config\ConfigException;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\entity_browser\DisplayAjaxInterface;
use Drupal\entity_browser\EntityBrowserFormInterface;
use Drupal\entity_browser\EntityBrowserInterface;
......@@ -55,11 +56,14 @@ class EntityBrowserForm extends FormBase implements EntityBrowserFormInterface {
* Selection storage.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(UuidInterface $uuid_generator, KeyValueStoreExpirableInterface $selection_storage, RendererInterface $renderer) {
public function __construct(UuidInterface $uuid_generator, KeyValueStoreExpirableInterface $selection_storage, RendererInterface $renderer, MessengerInterface $messenger) {
$this->uuidGenerator = $uuid_generator;
$this->selectionStorage = $selection_storage;
$this->renderer = $renderer;
$this->messenger = $messenger;
}
/**
......@@ -69,7 +73,8 @@ class EntityBrowserForm extends FormBase implements EntityBrowserFormInterface {
return new static(
$container->get('uuid'),
$container->get('entity_browser.selection_storage'),
$container->get('renderer')
$container->get('renderer'),
$container->get('messenger')
);
}
......@@ -145,7 +150,7 @@ class EntityBrowserForm extends FormBase implements EntityBrowserFormInterface {
];
if (!($current_widget_id = $this->getCurrentWidget($form_state))) {
drupal_set_message($this->t('No widgets are available.'), 'warning');
$this->messenger->addWarning($this->t('No widgets are available.'));
return $form;
}
......@@ -161,7 +166,7 @@ class EntityBrowserForm extends FormBase implements EntityBrowserFormInterface {
$form[$form['#browser_parts']['widget']] = $widget->getForm($form, $form_state, $this->entityBrowser->getAdditionalWidgetParameters());
}
else {
drupal_set_message($this->t('Access to the widget forbidden.'), 'warning');
$this->messenger->addWarning($this->t('Access to the widget forbidden.'));
}
// Add cache access cache metadata from the widgets to the form directly as
......
......@@ -4,6 +4,7 @@ namespace Drupal\entity_browser\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\entity_browser\WidgetManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -12,7 +13,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class WidgetsConfig extends EntityForm {
/**
* Entity browser widget plugin manager.
*
......@@ -25,9 +25,12 @@ class WidgetsConfig extends EntityForm {
*
* @param \Drupal\entity_browser\WidgetManager $widget_manager
* Entity browser widget plugin manager.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(WidgetManager $widget_manager) {
public function __construct(WidgetManager $widget_manager, MessengerInterface $messenger) {
$this->widgetManager = $widget_manager;
$this->messenger = $messenger;
}
/**
......@@ -35,7 +38,8 @@ class WidgetsConfig extends EntityForm {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.entity_browser.widget')
$container->get('plugin.manager.entity_browser.widget'),
$container->get('messenger')
);
}
......@@ -220,7 +224,11 @@ class WidgetsConfig extends EntityForm {
$widget->setWeight($table[$uuid]['weight']);
$widget->setLabel($table[$uuid]['label']);
}
$entity_browser->save();
$status = $entity_browser->save();
if ($status == SAVED_UPDATED) {
$this->messenger->addMessage($this->t('The entity browser %name has been updated.', ['%name' => $this->entity->label()]));
}
}
}
......@@ -22,6 +22,7 @@ use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Messenger\MessengerInterface;
/**
* Plugin implementation of the 'entity_reference' widget for entity browser.
......@@ -96,13 +97,16 @@ class EntityReferenceBrowserWidget extends WidgetBase implements ContainerFactor
* The module handler service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager, FieldWidgetDisplayManager $field_display_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user) {
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager, FieldWidgetDisplayManager $field_display_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user, MessengerInterface $messenger) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
$this->entityTypeManager = $entity_type_manager;
$this->fieldDisplayManager = $field_display_manager;
$this->moduleHandler = $module_handler;
$this->currentUser = $current_user;
$this->messenger = $messenger;
}
/**
......@@ -118,7 +122,8 @@ class EntityReferenceBrowserWidget extends WidgetBase implements ContainerFactor
$container->get('entity_type.manager'),
$container->get('plugin.manager.entity_browser.field_widget_display'),
$container->get('module_handler'),
$container->get('current_user')
$container->get('current_user'),
$container->get('messenger')
);
}
......@@ -658,7 +663,7 @@ class EntityReferenceBrowserWidget extends WidgetBase implements ContainerFactor
$summary[] = $this->t('Entity browser: @browser', ['@browser' => $browser->label()]);
}
else {
drupal_set_message($this->t('Missing entity browser!'), 'error');
$this->messenger->addError($this->t('Missing entity browser!'));
return [$this->t('Missing entity browser!')];
}
}
......
......@@ -11,6 +11,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Url;
use Drupal\entity_browser\FieldWidgetDisplayManager;
use Drupal\image\Entity\ImageStyle;
......@@ -94,11 +95,13 @@ class FileBrowserWidget extends EntityReferenceBrowserWidget {
* The module handler service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
* @param \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $mime_type_guesser
* The mime type guesser service.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager, FieldWidgetDisplayManager $field_display_manager, ConfigFactoryInterface $config_factory, EntityDisplayRepositoryInterface $display_repository, ModuleHandlerInterface $module_handler, AccountInterface $current_user, MimeTypeGuesserInterface $mime_type_guesser) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings, $entity_type_manager, $field_display_manager, $module_handler, $current_user);
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager, FieldWidgetDisplayManager $field_display_manager, ConfigFactoryInterface $config_factory, EntityDisplayRepositoryInterface $display_repository, ModuleHandlerInterface $module_handler, AccountInterface $current_user, MimeTypeGuesserInterface $mime_type_guesser, MessengerInterface $messenger) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings, $entity_type_manager, $field_display_manager, $module_handler, $current_user, $messenger);
$this->entityTypeManager = $entity_type_manager;
$this->fieldDisplayManager = $field_display_manager;
$this->configFactory = $config_factory;
......@@ -122,7 +125,8 @@ class FileBrowserWidget extends EntityReferenceBrowserWidget {
$container->get('entity_display.repository'),
$container->get('module_handler'),
$container->get('current_user'),
$container->get('file.mime_type.guesser')
$container->get('file.mime_type.guesser'),
$container->get('messenger')
);
}
......
......@@ -5,6 +5,7 @@ namespace Drupal\entity_browser_test\Form;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerTrait;
use Drupal\entity_browser\Element\EntityBrowserElement;
/**
......@@ -12,6 +13,8 @@ use Drupal\entity_browser\Element\EntityBrowserElement;
*/
class FormElementTest extends FormBase {
use MessengerTrait;
/**
* {@inheritdoc}
*/
......@@ -59,7 +62,7 @@ class FormElementTest extends FormBase {
},
$entities
));
drupal_set_message($message);
$this->messenger()->addMessage($message);
}
}
......@@ -77,6 +77,7 @@ class ConfigurationTest extends WebDriverTestBase {
$this->assertSession()->selectExists('widget_selector')->selectOption('tabs');
$this->assertSession()->selectExists('selection_display')->selectOption('no_display');
$this->drupalPostForm(NULL, [], 'Save');
$this->assertSession()->pageTextContains('The entity browser Test entity browser has been added. Now you may configure the widgets you would like to use.');
$this->assertSession()->addressEquals('/admin/config/content/entity_browser/test_entity_browser/widgets');
$this->assertSession()->selectExists('widget');
......@@ -108,6 +109,7 @@ class ConfigurationTest extends WebDriverTestBase {
$this->assertSession()->fieldExists('display_configuration[link_text]')->setValue('All animals are created equal');
$this->drupalPostForm(NULL, [], 'Save');
$this->assertSession()->addressEquals('/admin/config/content/entity_browser/test_entity_browser/edit');
$this->assertSession()->pageTextContains('The entity browser Test entity browser has been updated.');
$entity_browser = EntityBrowser::load('test_entity_browser');
......@@ -132,6 +134,7 @@ class ConfigurationTest extends WebDriverTestBase {
$this->assertSession()->fieldExists('display_configuration[path]')->setValue('/all-animals');
$this->drupalPostForm(NULL, [], 'Save');
$this->assertSession()->addressEquals('/admin/config/content/entity_browser/test_entity_browser/edit');
$this->assertSession()->pageTextContains('The entity browser Test entity browser has been updated.');
$this->clickLink('General Settings');
$this->assertSession()->addressEquals('/admin/config/content/entity_browser/test_entity_browser/edit');
$this->getSession()->executeScript("jQuery('details').attr('open', 'open');");
......@@ -151,6 +154,7 @@ class ConfigurationTest extends WebDriverTestBase {
$this->assertSession()->responseContains('The Path field must begin with a forward slash.');
$this->assertSession()->fieldExists('display_configuration[path]')->setValue('/all-animals');
$this->drupalPostForm(NULL, [], 'Save');
$this->assertSession()->pageTextContains('The entity browser Test entity browser has been updated.');
$this->getSession()->executeScript("jQuery('details').attr('open', 'open');");
// Test ajax update of display settings.
......@@ -222,6 +226,7 @@ class ConfigurationTest extends WebDriverTestBase {
// Use defaults and save to go to WidgetsConfig form.
$this->drupalPostForm(NULL, [], 'Save');
$this->assertSession()->addressEquals('/admin/config/content/entity_browser/test_entity_browser/widgets');
$this->assertSession()->pageTextContains('The entity browser Test entity browser has been added. Now you may configure the widgets you would like to use.');
$widgetSelect = $this->assertSession()->selectExists('widget');
$this->assertSession()->responseContains('The available plugins are:');
......@@ -243,6 +248,7 @@ class ConfigurationTest extends WebDriverTestBase {
$this->assertSession()->selectExists("table[$uuid][form][form_mode][form_select]");
$this->drupalPostForm(NULL, [], 'Save');
$this->assertSession()->addressEquals('/admin/config/content/entity_browser/test_entity_browser/widgets');
$this->assertSession()->pageTextContains('The entity browser Test entity browser has been updated.');
$entity_browser = EntityBrowser::load('test_entity_browser');
$widget = $entity_browser->getWidget($uuid);
......@@ -273,6 +279,7 @@ class ConfigurationTest extends WebDriverTestBase {
$this->assertSession()->selectExists("table[$uuid][form][view]")->selectOption('nodes_entity_browser.entity_browser_1');
$this->drupalPostForm(NULL, [], 'Save');
$this->assertSession()->addressEquals('/admin/config/content/entity_browser/test_entity_browser/widgets');
$this->assertSession()->pageTextContains('The entity browser Test entity browser has been updated.');
$entity_browser = EntityBrowser::load('test_entity_browser');
$widget = $entity_browser->getWidget($uuid);
......@@ -305,6 +312,7 @@ class ConfigurationTest extends WebDriverTestBase {
$this->assertSession()->elementExists('css', 'a.token-dialog.use-ajax');
$this->drupalPostForm(NULL, [], 'Save');
$this->assertSession()->addressEquals('/admin/config/content/entity_browser/test_entity_browser/widgets');
$this->assertSession()->pageTextContains('The entity browser Test entity browser has been updated.');
$entity_browser = EntityBrowser::load('test_entity_browser');
$widget = $entity_browser->getWidget($uuid);
......
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