If you have code like this:

drupal_set_message(t('My name is !name.', ['!name' => 'David']));

Drupal will not perform the replacement, and instead will output "My name is !name" to the screen. It will also trigger an error to notify developers about the problem.

However, if you have code like this:

drupal_set_message(t('My name is NAME.', ['NAME' => 'David']));

Drupal will still not perform the replacement (it will output "My name is NAME"). But instead of triggering an error, it will trigger an E_USER_DEPRECATED.

I don't think that makes sense. If it's broken code (not merely deprecated code) it should be an error just like the first case.

This issue is relatively minor, because it turns out Drupal logs/displays E_USER_DEPRECATED as if it were an error or a warning (so even if your development site is only configured to display errors/warnings to the screen, you'll probably still see it). That's presumably a bug though, and we shouldn't rely on it.

Also, my main interest in this issue is that it seems to be what the documentation in https://www.drupal.org/core/deprecation#how-unintended is based on. I think that documentation should be fixed as well as a followup to this issue - E_USER_DEPRECATED should only be used if something is deprecated but still works.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein created an issue. See original summary.

David_Rothstein’s picture

Status: Active » Needs review
FileSize
1.41 KB

Here is a patch.

David_Rothstein’s picture

A small side effect of this patch is that if you have code like this:

drupal_set_message(t('My name is @name.', ['!name' => 'David']));

(which obviously won't lead to @name being replaced), then before the patch, an error is triggered, but after the patch, it isn't.

I think the post-patch behavior makes sense (unlike the examples in the issue summary, this isn't code that ever worked in previous versions of Drupal or that anyone should ever have expected to work - it is just a flat-out typo). But if for some reason we want to preserve that behavior, the patch could be changed to do so.

Status: Needs review » Needs work

The last submitted patch, 2: 2860659-1.patch, failed testing.

David_Rothstein’s picture

Quick fix - some tests needed to be updated for this change too.

GoZ’s picture

Issue tags: +Needs tests
David_Rothstein’s picture

Issue tags: -Needs tests

This functionality already has tests - see above.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

David_Rothstein’s picture

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

The patch still applies (and tests still pass) on the 8.5.x branch.

Reviews?

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.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

I agree, this makes sense! The patch still applies. I ran FormattableMarkupTest locally and it passes.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

We original it was a deprecation - see #2575703: Remove default fall-through from PlaceholderTrait::placeholderFormat() - yes that issue also changed the behaviour so it makes it not really deprecated. I think it should have used E_USER_WARNING rather than deprecated. Like the user thinks the replacement is going to work but it's not. But it did use to work in D7.

+++ b/core/lib/Drupal/Component/Render/FormattableMarkup.php
@@ -225,18 +225,13 @@ protected static function placeholderFormat($string, array $args) {
-          if (!ctype_alpha($key[0])) {
+          if (strpos($string, $key) !== FALSE) {

If we want to make it an E_USER_ERROR for both instances - and that is probably fine I think we should remove the if and always error if we get here.

This code is definitely wonky...

FormattableMarkup('blah blah', ['foo' => 'bar']);

won't error but...

FormattableMarkup('blah foo', ['foo' => 'bar']);

will... I don't really see why. Since we don't to any replacements on default anymore why not just error.

alexpott’s picture

Also drupal_set_message(t('My name is @name.', ['!name' => 'David'])); should error since ! is not supported.

drupal_set_message(t('My name is @name.', [':name' => 'David'])); shouldn't error because : is supported. And it does not now and it doesn't with whatever approach we take.

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

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

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Closed (duplicate)
Issue tags: +Bug Smash Initiative