Skip to content

Commit f69efe5

Browse files
bahuma20jmolivas
authored andcommitted
Replate deprecated drupal_set_message (#3867)
1 parent bd35d15 commit f69efe5

11 files changed

+14
-14
lines changed

templates/module/post-update.php.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Implements hook_post_update_NAME() on Module {{ module }} Post Update {{ post_update_name }}.
77
*/
88
function {{ module }}_post_update_{{ post_update_name }}(&$sandbox) {
9-
drupal_set_message('Module {{ module }} Post Update # {{ post_update_name }} () was executed successfully.');
9+
\Drupal::messenger()->addMessage('Module {{ module }} Post Update # {{ post_update_name }} () was executed successfully.');
1010
}
1111

1212
{% endblock %}

templates/module/src/Entity/Form/entity-content-revision-delete.php.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock %
116116
$this->{{ entity_class }}Storage->deleteRevision($this->revision->getRevisionId());
117117

118118
$this->logger('content')->notice('{{ label }}: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
119-
drupal_set_message(t('Revision from %revision-date of {{ label }} %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
119+
\Drupal::messenger()->addMessage(t('Revision from %revision-date of {{ label }} %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
120120
$form_state->setRedirect(
121121
'entity.{{ entity_name }}.canonical',
122122
['{{ entity_name }}' => $this->revision->id()]

templates/module/src/Entity/Form/entity-content-revision-revert.php.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class {{ entity_class }}RevisionRevertForm extends ConfirmFormBase {% endblock %
129129
$this->revision->save();
130130

131131
$this->logger('content')->notice('{{ label }}: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
132-
drupal_set_message(t('{{ label }} %title has been reverted to the revision from %revision-date.', ['%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)]));
132+
\Drupal::messenger()->addMessage(t('{{ label }} %title has been reverted to the revision from %revision-date.', ['%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)]));
133133
$form_state->setRedirect(
134134
'entity.{{ entity_name }}.version_history',
135135
['{{ entity_name }}' => $this->revision->id()]

templates/module/src/Entity/Form/entity-content.php.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ class {{ entity_class }}Form extends ContentEntityForm {% endblock %}
6868

6969
switch ($status) {
7070
case SAVED_NEW:
71-
drupal_set_message($this->t('Created the %label {{ label }}.', [
71+
\Drupal::messenger()->addMessage($this->t('Created the %label {{ label }}.', [
7272
'%label' => $entity->label(),
7373
]));
7474
break;
7575

7676
default:
77-
drupal_set_message($this->t('Saved the %label {{ label }}.', [
77+
\Drupal::messenger()->addMessage($this->t('Saved the %label {{ label }}.', [
7878
'%label' => $entity->label(),
7979
]));
8080
}

templates/module/src/Form/entity-delete.php.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class {{ entity_class }}DeleteForm extends EntityConfirmFormBase {% endblock %}
4747
public function submitForm(array &$form, FormStateInterface $form_state) {
4848
$this->entity->delete();
4949

50-
drupal_set_message(
50+
\Drupal::messenger()->addMessage(
5151
$this->t('content @type: deleted @label.',
5252
[
5353
'@type' => $this->entity->bundle(),

templates/module/src/Form/entity.php.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ class {{ entity_class }}Form extends EntityForm {% endblock %}
5858

5959
switch ($status) {
6060
case SAVED_NEW:
61-
drupal_set_message($this->t('Created the %label {{ label }}.', [
61+
\Drupal::messenger()->addMessage($this->t('Created the %label {{ label }}.', [
6262
'%label' => ${{ entity_name | machine_name }}->label(),
6363
]));
6464
break;
6565

6666
default:
67-
drupal_set_message($this->t('Saved the %label {{ label }}.', [
67+
\Drupal::messenger()->addMessage($this->t('Saved the %label {{ label }}.', [
6868
'%label' => ${{ entity_name | machine_name }}->label(),
6969
]));
7070
}

templates/module/src/Form/form-alter.php.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ use Drupal\Core\Form\FormStateInterface;
1212
{% endif %}
1313
*/
1414
function {{ module }}_form_{{ form_id }}_alter(&$form, FormStateInterface $form_state) {
15-
drupal_set_message('{{ module }}_form_{{ form_id }}_alter() executed.');
15+
\Drupal::messenger()->addMessage('{{ module }}_form_{{ form_id }}_alter() executed.');
1616
{% else %}
1717
/**
1818
* Implements hook_form_alter() on behalf of {{ module }}.module.
1919
*/
2020
function {{ module }}_form_alter(&$form, FormStateInterface $form_state, $form_id) {
2121
// Change form id here
2222
if ($form_id == 'form_test_alter_form') {
23-
drupal_set_message('form_test_form_alter() executed.');
23+
\Drupal::messenger()->addMessage('form_test_form_alter() executed.');
2424
{% endif %}
2525

2626
{%- if metadata.unset -%}

templates/module/src/Form/form.php.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class {{ class_name }} extends FormBase {% endblock %}
108108
public function submitForm(array &$form, FormStateInterface $form_state) {
109109
// Display result.
110110
foreach ($form_state->getValues() as $key => $value) {
111-
drupal_set_message($key . ': ' . $value);
111+
\Drupal::messenger()->addMessage($key . ': ' . $value);
112112
}
113113

114114
}

templates/module/src/cache-context.php.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class {{ class }} implements CacheContextInterface {% endblock %}
3535
* {@inheritdoc}
3636
*/
3737
public static function getLabel() {
38-
drupal_set_message('Lable of cache context');
38+
\Drupal::messenger()->addMessage('Lable of cache context');
3939
}
4040

4141
/**

templates/module/src/event-subscriber.php.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class {{ class }} implements EventSubscriberInterface {% endblock %}
5050
* @param GetResponseEvent $event
5151
*/
5252
public function {{ callback }}(Event $event) {
53-
drupal_set_message('Event {{ event_name }} thrown by Subscriber in module {{ module }}.', 'status', TRUE);
53+
\Drupal::messenger()->addMessage('Event {{ event_name }} thrown by Subscriber in module {{ module }}.', 'status', TRUE);
5454
}
5555
{% endfor %}
5656
{% endblock %}

0 commit comments

Comments
 (0)