summaryrefslogtreecommitdiffstats
path: root/core/modules/block
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/block')
-rw-r--r--core/modules/block/block.module6
-rw-r--r--core/modules/block/src/BlockForm.php2
-rw-r--r--core/modules/block/src/BlockListBuilder.php16
-rw-r--r--core/modules/block/src/Controller/BlockController.php2
-rw-r--r--core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php5
-rw-r--r--core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php2
-rw-r--r--core/modules/block/tests/modules/block_test/src/Form/TestForm.php2
-rw-r--r--core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php5
-rw-r--r--core/modules/block/tests/src/Kernel/BlockRebuildTest.php9
9 files changed, 35 insertions, 14 deletions
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index ee6a4a1..28fd7b3 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -145,7 +145,11 @@ function block_rebuild() {
// Disable blocks in invalid regions.
if (!isset($regions[$block->getRegion()])) {
if ($block->status()) {
- drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block_id, '%region' => $block->getRegion()]), 'warning');
+ \Drupal::messenger()
+ ->addWarning(t('The block %info was assigned to the invalid region %region and has been disabled.', [
+ '%info' => $block_id,
+ '%region' => $block->getRegion(),
+ ]));
}
$block
->setRegion(system_default_region($theme))
diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php
index b409c53..64f1aad 100644
--- a/core/modules/block/src/BlockForm.php
+++ b/core/modules/block/src/BlockForm.php
@@ -360,7 +360,7 @@ class BlockForm extends EntityForm {
// Save the settings of the plugin.
$entity->save();
- drupal_set_message($this->t('The block configuration has been saved.'));
+ $this->messenger()->addStatus($this->t('The block configuration has been saved.'));
$form_state->setRedirect(
'block.admin_display_theme',
[
diff --git a/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php
index 37b2e8b..facd024 100644
--- a/core/modules/block/src/BlockListBuilder.php
+++ b/core/modules/block/src/BlockListBuilder.php
@@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Theme\ThemeManagerInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -57,6 +58,13 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
protected $limit = FALSE;
/**
+ * The messenger.
+ *
+ * @var \Drupal\Core\Messenger\MessengerInterface
+ */
+ protected $messenger;
+
+ /**
* Constructs a new BlockListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
@@ -68,11 +76,12 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
*/
- public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ThemeManagerInterface $theme_manager, FormBuilderInterface $form_builder) {
+ public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ThemeManagerInterface $theme_manager, FormBuilderInterface $form_builder, MessengerInterface $messenger) {
parent::__construct($entity_type, $storage);
$this->themeManager = $theme_manager;
$this->formBuilder = $form_builder;
+ $this->messenger = $messenger;
}
/**
@@ -83,7 +92,8 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
$entity_type,
$container->get('entity.manager')->getStorage($entity_type->id()),
$container->get('theme.manager'),
- $container->get('form_builder')
+ $container->get('form_builder'),
+ $container->get('messenger')
);
}
@@ -367,7 +377,7 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
$entity->setRegion($entity_values['region']);
$entity->save();
}
- drupal_set_message(t('The block settings have been updated.'));
+ $this->messenger->addStatus($this->t('The block settings have been updated.'));
// Remove any previously set block placement.
$this->request->query->remove('block-placement');
diff --git a/core/modules/block/src/Controller/BlockController.php b/core/modules/block/src/Controller/BlockController.php
index 7398ff9..543ce59 100644
--- a/core/modules/block/src/Controller/BlockController.php
+++ b/core/modules/block/src/Controller/BlockController.php
@@ -53,7 +53,7 @@ class BlockController extends ControllerBase {
*/
public function performOperation(BlockInterface $block, $op) {
$block->$op()->save();
- drupal_set_message($this->t('The block settings have been updated.'));
+ $this->messenger()->addStatus($this->t('The block settings have been updated.'));
return $this->redirect('block.admin_display');
}
diff --git a/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
index e7aac65..246bcea 100644
--- a/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
+++ b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
@@ -17,7 +17,8 @@ class TestMultipleFormController extends ControllerBase {
'form2' => $this->formBuilder()->buildForm('\Drupal\block_test\Form\FavoriteAnimalTestForm', $form_state),
];
- // Output all attached placeholders trough drupal_set_message(), so we can
+ // Output all attached placeholders trough
+ // \Drupal\Core\Messenger\MessengerInterface::addMessage(), so we can
// see if there's only one in the tests.
$post_render_callable = function ($elements) {
$matches = [];
@@ -26,7 +27,7 @@ class TestMultipleFormController extends ControllerBase {
$action_values = $matches[2];
foreach ($action_values as $action_value) {
- drupal_set_message('Form action: ' . $action_value);
+ $this->messenger()->addStatus('Form action: ' . $action_value);
}
return $elements;
};
diff --git a/core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php b/core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php
index 3ad55ed..a86db68 100644
--- a/core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php
+++ b/core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php
@@ -40,7 +40,7 @@ class FavoriteAnimalTestForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
- drupal_set_message($this->t('Your favorite animal is: @favorite_animal', ['@favorite_animal' => $form['favorite_animal']['#value']]));
+ $this->messenger()->addStatus($this->t('Your favorite animal is: @favorite_animal', ['@favorite_animal' => $form['favorite_animal']['#value']]));
}
}
diff --git a/core/modules/block/tests/modules/block_test/src/Form/TestForm.php b/core/modules/block/tests/modules/block_test/src/Form/TestForm.php
index 7fa645d..7619d84 100644
--- a/core/modules/block/tests/modules/block_test/src/Form/TestForm.php
+++ b/core/modules/block/tests/modules/block_test/src/Form/TestForm.php
@@ -49,7 +49,7 @@ class TestForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
- drupal_set_message($this->t('Your email address is @email', ['@email' => $form['email']['#value']]));
+ $this->messenger()->addStatus($this->t('Your email address is @email', ['@email' => $form['email']['#value']]));
}
}
diff --git a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php
index 7db350d..70afd54 100644
--- a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php
+++ b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php
@@ -3,6 +3,7 @@
namespace Drupal\block_test\Plugin\Block;
use Drupal\Core\Block\BlockBase;
+use Drupal\Core\Messenger\MessengerTrait;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\UserInterface;
@@ -19,6 +20,8 @@ use Drupal\user\UserInterface;
*/
class TestContextAwareBlock extends BlockBase {
+ use MessengerTrait;
+
/**
* {@inheritdoc}
*/
@@ -37,7 +40,7 @@ class TestContextAwareBlock extends BlockBase {
*/
protected function blockAccess(AccountInterface $account) {
if ($this->getContextValue('user') instanceof UserInterface) {
- drupal_set_message('User context found.');
+ $this->messenger()->addStatus('User context found.');
}
return parent::blockAccess($account);
diff --git a/core/modules/block/tests/src/Kernel/BlockRebuildTest.php b/core/modules/block/tests/src/Kernel/BlockRebuildTest.php
index 33de12c..2443c21 100644
--- a/core/modules/block/tests/src/Kernel/BlockRebuildTest.php
+++ b/core/modules/block/tests/src/Kernel/BlockRebuildTest.php
@@ -47,7 +47,8 @@ class BlockRebuildTest extends KernelTestBase {
*/
public function testRebuildNoBlocks() {
block_rebuild();
- $messages = drupal_get_messages();
+ $messages = \Drupal::messenger()->all();
+ \Drupal::messenger()->deleteAll();
$this->assertEquals([], $messages);
}
@@ -58,7 +59,8 @@ class BlockRebuildTest extends KernelTestBase {
$this->placeBlock('system_powered_by_block', ['region' => 'content']);
block_rebuild();
- $messages = drupal_get_messages();
+ $messages = \Drupal::messenger()->all();
+ \Drupal::messenger()->deleteAll();
$this->assertEquals([], $messages);
}
@@ -89,7 +91,8 @@ class BlockRebuildTest extends KernelTestBase {
$block1 = Block::load($block1->id());
$block2 = Block::load($block2->id());
- $messages = drupal_get_messages();
+ $messages = \Drupal::messenger()->all();
+ \Drupal::messenger()->deleteAll();
$expected = ['warning' => [new TranslatableMarkup('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block1->id(), '%region' => 'INVALID'])]];
$this->assertEquals($expected, $messages);