Skip to content
Permalink
Browse files

Replate deprecated drupal_set_message (#3867)

  • Loading branch information...
bahuma20 authored and jmolivas committed May 9, 2018
1 parent bd35d15 commit f69efe5ccd775fa05cd3166ddcd6576e5511461b
@@ -6,7 +6,7 @@
* Implements hook_post_update_NAME() on Module {{ module }} Post Update {{ post_update_name }}.
*/
function {{ module }}_post_update_{{ post_update_name }}(&$sandbox) {
drupal_set_message('Module {{ module }} Post Update # {{ post_update_name }} () was executed successfully.');
\Drupal::messenger()->addMessage('Module {{ module }} Post Update # {{ post_update_name }} () was executed successfully.');
}

{% endblock %}
@@ -116,7 +116,7 @@ class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock %
$this->{{ entity_class }}Storage->deleteRevision($this->revision->getRevisionId());

$this->logger('content')->notice('{{ label }}: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
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()]));
\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()]));
$form_state->setRedirect(
'entity.{{ entity_name }}.canonical',
['{{ entity_name }}' => $this->revision->id()]
@@ -129,7 +129,7 @@ class {{ entity_class }}RevisionRevertForm extends ConfirmFormBase {% endblock %
$this->revision->save();

$this->logger('content')->notice('{{ label }}: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
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)]));
\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)]));
$form_state->setRedirect(
'entity.{{ entity_name }}.version_history',
['{{ entity_name }}' => $this->revision->id()]
@@ -68,13 +68,13 @@ class {{ entity_class }}Form extends ContentEntityForm {% endblock %}

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

default:
drupal_set_message($this->t('Saved the %label {{ label }}.', [
\Drupal::messenger()->addMessage($this->t('Saved the %label {{ label }}.', [
'%label' => $entity->label(),
]));
}
@@ -47,7 +47,7 @@ class {{ entity_class }}DeleteForm extends EntityConfirmFormBase {% endblock %}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();

drupal_set_message(
\Drupal::messenger()->addMessage(
$this->t('content @type: deleted @label.',
[
'@type' => $this->entity->bundle(),
@@ -58,13 +58,13 @@ class {{ entity_class }}Form extends EntityForm {% endblock %}

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

default:
drupal_set_message($this->t('Saved the %label {{ label }}.', [
\Drupal::messenger()->addMessage($this->t('Saved the %label {{ label }}.', [
'%label' => ${{ entity_name | machine_name }}->label(),
]));
}
@@ -12,15 +12,15 @@ use Drupal\Core\Form\FormStateInterface;
{% endif %}
*/
function {{ module }}_form_{{ form_id }}_alter(&$form, FormStateInterface $form_state) {
drupal_set_message('{{ module }}_form_{{ form_id }}_alter() executed.');
\Drupal::messenger()->addMessage('{{ module }}_form_{{ form_id }}_alter() executed.');
{% else %}
/**
* Implements hook_form_alter() on behalf of {{ module }}.module.
*/
function {{ module }}_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Change form id here
if ($form_id == 'form_test_alter_form') {
drupal_set_message('form_test_form_alter() executed.');
\Drupal::messenger()->addMessage('form_test_form_alter() executed.');
{% endif %}

{%- if metadata.unset -%}
@@ -108,7 +108,7 @@ class {{ class_name }} extends FormBase {% endblock %}
public function submitForm(array &$form, FormStateInterface $form_state) {
// Display result.
foreach ($form_state->getValues() as $key => $value) {
drupal_set_message($key . ': ' . $value);
\Drupal::messenger()->addMessage($key . ': ' . $value);
}

}
@@ -35,7 +35,7 @@ class {{ class }} implements CacheContextInterface {% endblock %}
* {@inheritdoc}
*/
public static function getLabel() {
drupal_set_message('Lable of cache context');
\Drupal::messenger()->addMessage('Lable of cache context');
}

/**
@@ -50,7 +50,7 @@ class {{ class }} implements EventSubscriberInterface {% endblock %}
* @param GetResponseEvent $event
*/
public function {{ callback }}(Event $event) {
drupal_set_message('Event {{ event_name }} thrown by Subscriber in module {{ module }}.', 'status', TRUE);
\Drupal::messenger()->addMessage('Event {{ event_name }} thrown by Subscriber in module {{ module }}.', 'status', TRUE);
}
{% endfor %}
{% endblock %}
@@ -6,7 +6,7 @@
* Implements hook_update_N() on Module {{ module }} Update # {{ update_number }}.
*/
function {{ module }}_update_{{ update_number }}(&$sandbox) {
drupal_set_message('Module {{ module }} Update # {{ update_number }} () was executed successfully.');
\Drupal::messenger()->addMessage('Module {{ module }} Update # {{ update_number }} () was executed successfully.');
}

{% endblock %}

0 comments on commit f69efe5

Please sign in to comment.
You can’t perform that action at this time.