Part of #2924538: [META] Remove all usages of drupal_set_message and drupal_get_messages
grep -inr -e "drupal_set_message" -e "drupal_get_message" core/modules/[a-f]

CommentFileSizeAuthor
#46 interdiff-43-46.txt640 bytesjofitz
#46 2935256-46.patch311.35 KBjofitz
#43 interdiff-40-42.txt4.13 KBjofitz
#43 2935256-42.patch311.35 KBjofitz
#40 interdiff-38-40.txt1.42 KBjofitz
#40 2935256-40.patch307.21 KBjofitz
#38 interdiff-34-38.txt691 bytesjofitz
#38 2935256-38.patch306.53 KBjofitz
#34 2935256-33-34.txt60.19 KBvoleger
#34 remove_all_usages_of_dsm-2935256-34-8.6.x.patch307.25 KBvoleger
#33 2935256-32-33.txt63.58 KBvoleger
#33 remove_all_usages_of_dsm-2935256-33-8.6.x.patch367.57 KBvoleger
#32 interdiff-2935256-32.txt1.16 KBibustos
#32 remove_all_usages_of_dsm-2935256-32-8.6.x.patch308.33 KBibustos
#31 interfiff-31.txt2.25 KBibustos
#31 remove_all_usages_of_dsm-2935256-31-8.6.x.patch308.33 KBibustos
#28 remove_all_usages_of_dsm-2935256-28-8.6.x.patch305.35 KByogeshmpawar
#27 remove_all_usages_of_dsm-2935256-27-8.6.x.patch277.22 KByogeshmpawar
#22 remove_all_usages_of_dsm-2935256-22-8.6.x.patch99.51 KBvoleger
#22 interdiff-2935256-20-22.txt8.87 KBvoleger
#20 remove_all_usages_of_dsm-2935256-20-8.6.x.patch90.94 KBvoleger
#9 2935256-9-interdiff.txt1.85 KBkim.pepper
#9 2935256-9.patch97.23 KBkim.pepper
#7 2935256-7-interdiff.txt8.88 KBkim.pepper
#7 2935256-7.patch96.24 KBkim.pepper
#5 2935256-5.patch90.82 KBkim.pepper
#2 2935256-2.patch100.45 KBkim.pepper
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kim.pepper created an issue. See original summary.

kim.pepper’s picture

Title: Remove all usages of drupal_get_message and drupal_set_message in modules A-F » [PP-1] Remove all usages of drupal_get_message and drupal_set_message in modules A-F
Status: Active » Postponed
FileSize
100.45 KB

Initial patch split from parent issue. Blocked on messenger trait in #2935255: Remove all usages of drupal_set_message and drupal_get_messages in core lib

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

kim.pepper’s picture

Title: [PP-1] Remove all usages of drupal_get_message and drupal_set_message in modules A-F » Remove all usages of drupal_get_message and drupal_set_message in modules A-F
Status: Postponed » Active
Issue tags: +Needs reroll

Unblocked as messenger trait was added in #2937945: Add messenger to ControllerBase and FormBase

kim.pepper’s picture

Status: Active » Needs review
Issue tags: -Needs reroll
FileSize
90.82 KB

Reroll

Status: Needs review » Needs work

The last submitted patch, 5: 2935256-5.patch, failed testing. View results

kim.pepper’s picture

Status: Needs work » Needs review
Issue tags: +messenger
FileSize
96.24 KB
8.88 KB

Adds missing messenger.

Status: Needs review » Needs work

The last submitted patch, 7: 2935256-7.patch, failed testing. View results

kim.pepper’s picture

Status: Needs work » Needs review
FileSize
97.23 KB
1.85 KB

Fixing test fails.

bhanuprakashnani’s picture

Status: Needs review » Reviewed & tested by the community

Patch applies cleanly. The requirements needed are satisfied.

bhanuprakashnani’s picture

Status: Reviewed & tested by the community » Needs review

Patch applies cleanly. The requirements needed are satisfied.

The last submitted patch, 2: 2935256-2.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 9: 2935256-9.patch, failed testing. View results

shubhangi1995’s picture

Assigned: Unassigned » shubhangi1995
kim.pepper’s picture

Title: Remove all usages of drupal_get_message and drupal_set_message in modules A-F » [PP-1] Remove all usages of drupal_get_message and drupal_set_message in modules A-F
Status: Needs work » Postponed
jibran’s picture

Issue summary: View changes
grep -inr -e "drupal_set_message" -e "drupal_set_message" core/modules/[a-f]*
core/modules/big_pipe/src/Render/BigPipe.php:733:    // change the way drupal_set_message() works in the Drupal 8 cycle. So we
core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php:20:    // Output all attached placeholders trough drupal_set_message(), so we can
core/modules/content_moderation/src/Plugin/Action/ModerationOptOutPublish.php:77:      drupal_set_message($this->t("@bundle @label were skipped as they are under moderation and may not be directly published.", ['@bundle' => $bundle_label, '@label' => $entity->getEntityType()->getPluralLabel()]), 'warning');
core/modules/content_moderation/src/Plugin/Action/ModerationOptOutUnpublish.php:77:      drupal_set_message($this->t("@bundle @label were skipped as they are under moderation and may not be directly unpublished.", ['@bundle' => $bundle_label, '@label' => $entity->getEntityType()->getPluralLabel()]), 'warning');
core/modules/file/file.module:1013:      // @todo Add support for render arrays in drupal_set_message()? See
jibran’s picture

Issue summary: View changes
shubhangi1995’s picture

Assigned: shubhangi1995 » Unassigned
voleger’s picture

Title: [PP-1] Remove all usages of drupal_get_message and drupal_set_message in modules A-F » Remove all usages of drupal_get_message and drupal_set_message in modules A-F
Status: Postponed » Needs work
voleger’s picture

Status: Needs work » Needs review
FileSize
90.94 KB

Rerolled regarding last changes.
core/modules/file/tests/file_test/src/Form/FileTestSaveUploadFromForm.php - calls already replaced. Removed changes from the patch.
core/modules/content_moderation/src/EntityTypeInfo.php - content moderation changes had removed single usage of DSM. So, removed changes from the patch for this file.
core/modules/field/tests/modules/field_test/field_test.module - rerolled regarding #2940201: hook_field_widget_form_alter() can no longer affect the whole widget for multi-value fields

kim.pepper’s picture

Status: Needs review » Needs work

Thanks @voleger. I ran  grep -inr -e "drupal_set_message" -e "drupal_get_message" core/modules/[a-f]*

and found a few missing converstions and comments:

core/modules/big_pipe/src/Render/BigPipe.php:733:    // change the way drupal_set_message() works in the Drupal 8 cycle. So we
core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php:20:    // Output all attached placeholders trough drupal_set_message(), so we can
core/modules/content_moderation/src/Plugin/Action/ModerationOptOutUnpublish.php:77:      drupal_set_message($this->t("@bundle @label were skipped as they are under moderation and may not be directly unpublished.", ['@bundle' => $bundle_label, '@label' => $entity->getEntityType()->getPluralLabel()]), 'warning');
core/modules/content_moderation/src/Plugin/Action/ModerationOptOutPublish.php:77:      drupal_set_message($this->t("@bundle @label were skipped as they are under moderation and may not be directly published.", ['@bundle' => $bundle_label, '@label' => $entity->getEntityType()->getPluralLabel()]), 'warning');
core/modules/file/file.module:1013:      // @todo Add support for render arrays in drupal_set_message()? See
voleger’s picture

Thank's @kim.pepper for review.
Added missing replacements.

kim.pepper’s picture

Status: Needs review » Reviewed & tested by the community

Addresses all feedback to RTBC

catch’s picture

Status: Reviewed & tested by the community » Needs work

Please combine the patches in #2935258: Remove all usages of drupal_get_message and drupal_set_message in modules M-R and #2935259: Remove all usages of drupal_get_message and drupal_set_message in modules S-Z into this one so all the module changes can be reviewed together. I think it's fine to do core/lib separately.

catch’s picture

Title: Remove all usages of drupal_get_message and drupal_set_message in modules A-F » Remove all usages of drupal_get_message and drupal_set_message in modules
yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar

@catch - i will combine all three patches

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
277.22 KB

@catch - I have combined all three patches & removed the core/lib separately as mentioned in #24 but i think few usages #2935257: [PP-1] Remove all usages of drupal_get_message and drupal_set_message in modules G-L are still there.

yogeshmpawar’s picture

As discussed with @catch, here is the latest updated patch to remove all usage of drupal_get_message & drupal_set_message in modules, only two occurrences left when we check with grep -inr -e "drupal_set_message" -e "drupal_get_message" core/modules/* as mentioned in #16.
Hopefully it pass all the test cases.

The last submitted patch, 27: remove_all_usages_of_dsm-2935256-27-8.6.x.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 28: remove_all_usages_of_dsm-2935256-28-8.6.x.patch, failed testing. View results

ibustos’s picture

ibustos’s picture

voleger’s picture

Status: Needs work » Needs review
FileSize
367.57 KB
63.58 KB
voleger’s picture

The last submitted patch, 33: remove_all_usages_of_dsm-2935256-33-8.6.x.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 34: remove_all_usages_of_dsm-2935256-34-8.6.x.patch, failed testing. View results

Girish-jerk’s picture

Assigned: Unassigned » Girish-jerk
jofitz’s picture

Assigned: Girish-jerk » Unassigned
Status: Needs work » Needs review
FileSize
306.53 KB
691 bytes

@Girish-jerk hasn't touched this for 3 weeks so I'll have a go.

Corrected the failing test (after a minor re-roll).

kim.pepper’s picture

Status: Needs review » Needs work

Thanks for picking this up again @Jo Fitzgerald

It's not great having to review a 306K patch, but here we are!

I've reviewed this a few times in the sub-issues that were merged into this one, so scanning through, I could only find one obvious issue.

+++ b/core/lib/Drupal/Core/Form/FormErrorHandler.php
@@ -166,7 +168,7 @@ protected function setElementErrorsFromFormState(array &$form, FormStateInterfac
   protected function drupalSetMessage($message = NULL, $type = 'status', $repeat = FALSE) {
-    drupal_set_message($message, $type, $repeat);
+    $this->messenger()->addMessage($message, $type, $repeat);

This method and usages are not necessary if we use messenger directly.

jofitz’s picture

Status: Needs work » Needs review
FileSize
307.21 KB
1.42 KB

Resolved the issue that @kim.pepper raised in #39.

A quick search suggests there are plenty of instances of drupal_set_message() remaining in the codebase (e.g. Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber::drupalSetMessage) - do any of these have reason to remain? I'm fast going off this ticket!

Status: Needs review » Needs work

The last submitted patch, 40: 2935256-40.patch, failed testing. View results

voleger’s picture

I guess this method should not be removed for now. Maybe better mark that method internal or deprecated?

jofitz’s picture

Status: Needs work » Needs review
FileSize
311.35 KB
4.13 KB

Update tests to reflect removal of drupalSetMessage().

kim.pepper’s picture

Looking great.

I ran a check for instances of drupal_set_message and drupal_get_message in the core/modules directory.

grep -inr -e "drupal_set_message" -e "drupal_get_message" core/modules
core/modules/system/tests/modules/system_test/system_test.routing.yml:16:system_test.drupal_set_message:
core/modules/system/tests/modules/system_test/system_test.routing.yml:19:    _title: 'Set messages with drupal_set_message()'
core/modules/system/tests/src/Functional/Bootstrap/DrupalSetMessageTest.php:8: * Tests drupal_set_message() and related functions.
core/modules/system/tests/src/Functional/Bootstrap/DrupalSetMessageTest.php:22:   * Tests drupal_set_message().

Those are all valid instances and can remain.

+++ b/core/modules/views/src/Analyzer.php
@@ -52,7 +52,8 @@ public function getMessages(ViewExecutable $view) {
-   * This is based upon the format of drupal_set_message which uses separate
+   * This is based upon the format of
+   * \Drupal\Core\Messenger\MessengerInterface::addStatus() which uses separate
    * boxes for "ok", "warning" and "error".

Nit: Should really be ::addMessage().

Other than that, I think this is ready.

voleger’s picture

#44: +1

jofitz’s picture

Corrected the nit from #44.

Let's push this one across the line and forget this huge patch forever!

kim.pepper’s picture

Status: Needs review » Reviewed & tested by the community
voleger’s picture

+1 for RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 46: 2935256-46.patch, failed testing. View results

kim.pepper’s picture

Drupal\Tests\system\FunctionalJavascript\ThemeFormSettingsTest failed. Retesting.

kim.pepper’s picture

Status: Needs work » Reviewed & tested by the community

Random bot fail. Setting back to RTBC

alexpott’s picture

Crediting @jibran and @catch for reviewing this and the other patches that have been merged into this one.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed b84b827 and pushed to 8.6.x. Thanks!

  • alexpott committed b84b827 on 8.6.x
    Issue #2935256 by Jo Fitzgerald, voleger, kim.pepper, ibustos, Yogesh...

  • alexpott committed 2e8be78 on 8.6.x
    Issue #2935256 follow-up by alexpott: Remove all usages of...
alexpott’s picture

This broke PHP 5.5 testing. I hotfixed because it is the 8.6.x branch and committing this patch once is enough disruption.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.