Follow-up to #2544318: Remove #type => html_tag usages

Problem/Motivation

As part of #2296101: Remove SafeMarkup::set() use in \Drupal\Core\Render\Element\HtmlTag::preRenderHtmlTag(), we identified the potential improvement of removing #type => 'html_tag' (including dawehner in #4 and catch in #7.

From #38:

[T]he non-test uses [of #type => 'html_tag'] in core can be grouped into 2 categories: <head> elements such as <meta>, <link>, and <script>, and simple combinations where SafeMarkup::format could be used instead.

_drupal_add_html_head() is listed as deprecated (#2477223: Refactor _drupal_add_html_head, drupal_get_html_head, _drupal_add_html_head_link into the attachments processor, remove from common.inc.), so we may need to postpone on that. In the meantime, we could work on the 6 places where non-head-type tags are using this #type? (One of those places is FilterCaption.php, which has its own use of SafeMarkup).

Proposed resolution

remove the 6 places where non-head-type tags are using #type => 'html_tag'
and
Remove \Drupal\Core\Render\Element\HtmlTag

Remaining tasks

User interface changes

?

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Status: Active » Needs review
FileSize
7.98 KB

Here's the patch that extends html_tag for a type meta.

Status: Needs review » Needs work

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

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

joelpittet’s picture

Status: Needs work » Needs review
FileSize
7.42 KB

Left some thing in there about buttons that wasn't supposed to be there.

poornima.n’s picture

Status: Needs review » Needs work

The last submitted patch, 6: 2821292_6.patch, failed testing.

joelpittet’s picture

@poornima.n What is the patch in #6 supposed to help with?

Prashant.c’s picture

Status: Needs work » Needs review
FileSize
4.12 KB

Replacing the occurrences of #tag => meta with #type => meta wherever found.

Not replaced the concurrences of

'#type' => 'html_tag',     
 '#tag' => 'meta'

not sure what needs to be done in this case.

Status: Needs review » Needs work

The last submitted patch, 9: replace-tag-with-type-2821292-9-8.3.x-dev.patch, failed testing.

poornima.n’s picture

@joelpittet Patch #6 was for Replacement of #tag => meta with #type => meta

joelpittet’s picture

@Prashant.c and @poornima.n the patch I had put in #5 should have actually done all that was needed. Could you explain what further changes you are making to the patch?

Manuel Garcia’s picture

joelpittet’s picture

Status: Needs work » Needs review

Thank you @Manuel Garcia

20th’s picture

#5 is the correct patch.

#6 is not quite right because the code in system.module looks like this after applying it (notice the double #type key):

    'system_meta_generator' => array(
      '#type' => 'html_tag',
      '#type' => 'meta',
      '#attributes' => array(
        'name' => 'Generator',
        'content' => 'Drupal ' . $version . ' (https://www.drupal.org)',
      ),
    ),

The issue is quite trivial, and in my opinion, #5 can be accepted as is but I have still changed a couple of things:

  • added tests to specifically check the rendering of meta element;
  • removed description of #noscript property from documentation of Meta class (because meta tag cannot have a value);
  • removed meta tag from $voidElements list in HtmlTag class, so that its ability to render meta does not look like an undocumented feature.

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

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

joelpittet’s picture

Thanks for the tests and cleanup in #15 @20th , here's a reroll.

Status: Needs review » Needs work

The last submitted patch, 17: 2821292-15-reroll.patch, failed testing.

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
FileSize
9.07 KB

Updated patch because previous patch failed to apply to 8.4.x branch.

yogeshmpawar’s picture

Any Update on this issue ?

Manuel Garcia’s picture

Status: Needs review » Reviewed & tested by the community

Patch #20 still applies cleanly, and it makes sense. Can't think of anything else to do here so RTBCing.

star-szr’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

This is doing more than replacing usages so should probably be retitled (and issue summary updated) accordingly.

  1. +++ b/core/lib/Drupal/Core/Render/Element/HtmlTag.php
    @@ -40,7 +40,7 @@ class HtmlTag extends RenderElement {
    -    'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr',
    +    'keygen', 'link', 'param', 'source', 'track', 'wbr',
    

    Not sure about this change for backwards compatibility. What about people that would still be using #tag => meta? If we want to deprecate that, can we trigger an error when they use #tag => meta so that we can remove it in 9.x?

  2. +++ b/core/lib/Drupal/Core/Render/Element/Meta.php
    @@ -0,0 +1,40 @@
    + * Properties:
    + * - #attributes: (array, optional) HTML attributes to apply to the tag. The
    + *   attributes are escaped, see \Drupal\Core\Template\Attribute.
    

    Since we're extending HtmlTag, the properties should also include #noscript.

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

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.

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.

shaktik’s picture

Status: Needs work » Needs review
FileSize
9.32 KB
4.25 KB

Created Patch for D9.1 kindly check.

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.

tanubansal’s picture

Patch #30 works fine on 9.1
RTBC + 1

Abhijith S’s picture

FileSize
94.71 KB

Applied patch #30 and its applies cleanly.The #tag => meta is removed with #type => meta ,and also updated in test cases.

applied

Abhijith S’s picture

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

Status: Reviewed & tested by the community » Needs work
FileSize
24.51 KB

#30 giving 1 CS issues.

In lib/Drupal/Core/Render/Element/Meta.php, I think it should be

  protected static $voidElements = ['meta'];

instead of

 static protected $voidElements = ['meta'];
adityasingh’s picture

yes it should be
protected static $voidElements = ['meta'];

adityasingh’s picture

Status: Needs work » Needs review
FileSize
9.2 KB
377 bytes

Updated patch. Please review.

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.

vikashsoni’s picture

Applied patch #30 applied successfully
Thanks for the patch

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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.