Problem/Motivation

Currently the methods hide($element) and show($element) reside in the include file core/includes/common.inc.

Proposed resolution

- Deprecate both methods without replacement, suggesting to inline #printed property flip.
- Document in renderer interface how control flow of render depends on the #printed semaphore

Remaining tasks

- patch
- review/commit

User interface changes

no

API changes

Functions show() and hide() are deprecated

Data model changes

no

Release notes snippet

CommentFileSizeAuthor
#110 2258355-110.patch7.47 KBandypost
#110 interdiff.txt4.79 KBandypost
#103 2258355-103.patch7.72 KBandypost
#103 interdiff.txt583 bytesandypost
#99 2258355-99.patch7.74 KBandypost
#90 Screenshot After Element.php_.jpg206.19 KBRinku Jacob 13
#90 Screenshot After common.inc_.jpg310.47 KBRinku Jacob 13
#90 Screenshot Before common.inc_.jpg335.73 KBRinku Jacob 13
#88 2258355-nr-bot.txt150 bytesneeds-review-queue-bot
#71 interdiff-2258355-56-70.txt11.23 KBBhanu951
#58 interdiff_54-56.txt2.61 KBnnevill
#58 2258355-56.patch9.34 KBnnevill
#54 interdiff_52-54.txt4.09 KBnnevill
#54 2258355-54.patch9.18 KBnnevill
#52 2258355-52.patch8.18 KBnnevill
#47 2258355-47.patch7.27 KBkarishmaamin
#37 2258355-37.patch7.28 KBMerryHamster
#27 move_hide_and_show_to-2258355-27.patch7.75 KBArnion
#22 move_hide_and_show_to-2258355-20.patch10.15 KBArnion
#19 move_hide_and_show_to-2258355-19.patch9.81 KBArnion
#16 move_hide_and_show_to-2258355-15.patch9.93 KBArnion
#14 move_hide_and_show_to-2258355-14.patch10.35 KBNitesh Sethia
#10 2258355-psr4-reroll.patch8.86 KBxjm
#6 issue-2258355.patch8.97 KBmarcingy
#3 issue-2258355.patch8.97 KBmarcingy
#1 issue-2258355.patch8.95 KBmarcingy

Issue fork drupal-2258355

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marcingy’s picture

Title: Move hide and show to render/element calss » Move hide and show to render/element class
Status: Active » Needs review
FileSize
8.95 KB

Moves show() and hide() into a more sensible place. This will have a follow up to remove the actual functions themselves.

Status: Needs review » Needs work

The last submitted patch, 1: issue-2258355.patch, failed testing.

marcingy’s picture

Status: Needs work » Needs review
FileSize
8.97 KB
slashrsm’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

This is fairly pedantic, but in most cases OO functions are "Capitalized::thing()" (only exceptions being internal objects like self:: or parent::) so it's weird in this instance to see "element" vs. "Element." Could we get a quick re-roll to fix that?

marcingy’s picture

Status: Needs work » Needs review
FileSize
8.97 KB

Changing case!

slashrsm’s picture

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

We need an issue summary to explain at least why we are doing this.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: issue-2258355.patch, failed testing.

xjm’s picture

Status: Needs work » Needs review
FileSize
8.86 KB

Reroll for #2247991: [May 27] Move all module code from …/lib/Drupal/… to …/src/… for PSR-4. However, we still need that issue summary update.

Mile23’s picture

Is this still a thing?

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21... Element still doesn't have a show() or hide(), but it was a year ago.

Mile23’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Needs a reroll.

$ git apply 2258355-psr4-reroll.patch 
error: patch failed: core/includes/common.inc:3512
error: core/includes/common.inc: patch does not apply
error: patch failed: core/lib/Drupal/Core/Render/Element.php:162
error: core/lib/Drupal/Core/Render/Element.php: patch does not apply
error: patch failed: core/modules/comment/src/Plugin/views/row/Rss.php:8
error: core/modules/comment/src/Plugin/views/row/Rss.php: patch does not apply
error: patch failed: core/modules/node/src/Plugin/views/row/Rss.php:8
error: core/modules/node/src/Plugin/views/row/Rss.php: patch does not apply
error: patch failed: core/modules/views_ui/views_ui.theme.inc:172
error: core/modules/views_ui/views_ui.theme.inc: patch does not apply
Nitesh Sethia’s picture

Assigned: marcingy » Nitesh Sethia
Nitesh Sethia’s picture

Assigned: Nitesh Sethia » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
10.35 KB

Rerolled the patch successfully as per the latest release.

Status: Needs review » Needs work

The last submitted patch, 14: move_hide_and_show_to-2258355-14.patch, failed testing.

Arnion’s picture

Recover method isEmpty i Drupal\Core\Render\Element.
Corrected reference to Drupal\views\Plugin\views\row\RssPluginBase.

Arnion’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 16: move_hide_and_show_to-2258355-15.patch, failed testing.

Arnion’s picture

Replace drupal_render($element, TRUE) by \Drupal::service('renderer')->render($element) in render().

andypost’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: move_hide_and_show_to-2258355-19.patch, failed testing.

Arnion’s picture

Status: Needs work » Needs review
FileSize
10.15 KB

Rerolled the patch.

andypost’s picture

At this point we probably need to just deprecate this wrappers.
Patch should just replace usage of old functions with new ones and deprecate them

+++ b/core/modules/comment/src/Plugin/views/row/Rss.php
@@ -106,15 +107,21 @@ public function render($row) {
-    $build = comment_view($comment, 'rss');
+    $build = \Drupal::entityManager()->getViewBuilder('comment')->view($comment, 'rss');
...
+    // Hide the links if desired.
+    if (!$this->options['links']) {
+      Element::hide($build['links']);
...
-      // We render comment contents.
+      // We render comment contents and force links to be last.
+      $build['links']['#weight'] = 1000;

+++ b/core/modules/node/src/Plugin/views/row/Rss.php
@@ -152,6 +151,11 @@ public function render($row) {
+    // Hide the links if desired.
+    if (!$this->options['links']) {
+      Element::hide($build['links']);

looks unneeded changes

Status: Needs review » Needs work

The last submitted patch, 22: move_hide_and_show_to-2258355-20.patch, failed testing.

The last submitted patch, 22: move_hide_and_show_to-2258355-20.patch, failed testing.

andypost’s picture

There's separate issue to manage "position of comment links"

Arnion’s picture

Removed the modifications made to /core/modules/comment/src/Plugin/views/row/Rss.php and /core/modules/node/src/Plugin/views/row/Rss.php

marcingy’s picture

Status: Needs work » Needs review
andypost’s picture

  1. +++ b/core/includes/common.inc
    @@ -1104,19 +1104,17 @@ function drupal_render_children(&$element, $children_keys = NULL) {
    + * element is shown with Element::show() before rendering, so it will always be
    + * rendered even if Element::hide() had been previously used on it.
    
    @@ -1145,22 +1143,23 @@ function render(&$element) {
    + * element, be sure to call Element::hide() on the element before its parent
    
    @@ -1174,22 +1173,23 @@ function hide(&$element) {
    + * element, be sure to call Element::show() on the element before its parent
    

    "Element" should fully qualified class pass

  2. +++ b/core/includes/common.inc
    @@ -1104,19 +1104,17 @@ function drupal_render_children(&$element, $children_keys = NULL) {
    - * @see \Drupal\Core\Render\RendererInterface
    ...
    + * @see drupal_render()
    

    not sure this change, interface more descriptive

  3. +++ b/core/includes/common.inc
    @@ -1145,22 +1143,23 @@ function render(&$element) {
    + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
    
    @@ -1174,22 +1173,23 @@ function hide(&$element) {
    + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
    

    @xjm probably 9.x?

Mile23’s picture

Status: Needs review » Needs work

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.

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.

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

MerryHamster’s picture

Version: 8.5.x-dev » 8.6.x-dev
MerryHamster’s picture

Element still doesn't have methods 'show()' and 'hide()'.
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...

I tried to make reroll patch for 8.6.x


MerryHamster’s picture

Status: Needs work » Needs review

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.

andypost’s picture

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.

andypost’s picture

Status: Needs review » Needs work
Parent issue: » #3015538: [META] Deprecate contents of common.inc

Needs work for 9.3.x and collision with #2794261: Deprecate render() function in common.inc

karishmaamin’s picture

Re-rolled patch for 9.3.x. Please review

karishmaamin’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Needs work

The deprecation message needs updating to mention 9.3.x as the deprecation version and to match our standards, see https://www.drupal.org/pift-ci-job/2159191 for the codesniffer output.

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.

nnevill’s picture

Assigned: Unassigned » nnevill
nnevill’s picture

Status: Needs work » Needs review
FileSize
8.18 KB
andypost’s picture

Status: Needs review » Needs work
  1. +++ b/core/includes/common.inc
    @@ -376,23 +377,21 @@ function drupal_attach_tabledrag(&$element, array $options) {
    - * @param $element
    + * @param array $element
    ...
    - * @return
    + * @return array
    ...
    - * @see \Drupal\Core\Render\RendererInterface
    - * @see show()
    - * @see hide()
    + * @see drupal_render()
    

    this changes are unrelated to deprecation

  2. +++ b/core/includes/common.inc
    @@ -422,23 +421,25 @@ function render(&$element) {
    + * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use
    
    @@ -452,23 +453,25 @@ function hide(&$element) {
    + * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use
    

    it should point to 9.4.0

  3. +++ b/core/lib/Drupal/Core/Render/Element.php
    @@ -200,4 +200,53 @@ public static function isEmpty(array $elements) {
    +  public static function hide(&$element) {
    ...
    +  public static function show(&$element) {
    

    needs deprecation test and new issue to remove deprecated functions like #3260778: Remove deprecated code from bootstrap.inc

nnevill’s picture

Status: Needs work » Needs review
FileSize
9.18 KB
4.09 KB

Points 1,2,3 from previous comment have been fixed.

Thanks for such a quick review!

andypost’s picture

Thank you! looks mostly ready

+++ b/core/includes/common.inc
@@ -432,13 +433,17 @@ function render(&$element) {
+  @trigger_error('hide() function is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Render\Element::hide() instead.', E_USER_DEPRECATED);

@@ -462,13 +467,17 @@ function hide(&$element) {
+  @trigger_error('show() function is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Render\Element::show() instead.', E_USER_DEPRECATED);

+++ b/core/tests/Drupal/Tests/Core/Render/Element/ElementDeprecationTest.php
@@ -0,0 +1,41 @@
+    $this->expectDeprecation('show() function is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Render\Element::show() instead.');
...
+    $this->expectDeprecation('hide() function is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Render\Element::hide() instead.');

Deprecation messages should include link to https://www.drupal.org/node/3261271

So when it will be found in logs users can navigate to the link

andypost’s picture

andypost’s picture

nnevill’s picture

Status: Needs work » Needs review
Issue tags: +LutskGCW22
FileSize
9.34 KB
2.61 KB

Done. Hope this will be the last iteration :)

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Yay! looks ready for commiters' eyes

voleger’s picture

Bump, 3 weeks - no response. Patch still applying over 9.4.x branch.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 58: 2258355-56.patch, failed testing. View results

voleger’s picture

Status: Needs work » Needs review
voleger’s picture

Status: Needs review » Reviewed & tested by the community

Wrong status

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record updates

The change record is empty, so is the issue summary.. Would be great if someone could update those with necessary information.

voleger’s picture

Status: Needs work » Needs review

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.

nod_’s picture

Assigned: nnevill » Unassigned
Status: Needs review » Needs work

Patch or MR doesn't apply anymore
The last patch or MR doesn't apply to the target branch, please reroll the code so that it can be reviewed by the automated testbot.

D10 version needed
At this time we would need a D10.1.x patch or MR for this issue.

Also the issue summary could still use some text, at least a few sentences.

Bhanu951’s picture

Assigned: Unassigned » Bhanu951
Issue tags: +Needs reroll

Bhanu951’s picture

Assigned: Bhanu951 » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
11.23 KB
Spokje’s picture

Random test failure, ordered retest.
Also updated CR to 10.1.x/10.1.0.

Spokje’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated IS.

andypost’s picture

Test should make sure that functions returns same result

Spokje’s picture

Thanks @andypost, tests changed.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Added some comments on the MR. Also if we are changing the documentation to show and hide - then we need to re-flow it to 80 chars. There are some short lines now.

Bhanu951’s picture

Status: Needs work » Needs review

Addressed review comments by @alexpott

Spokje’s picture

Status: Needs review » Needs work

One PHPCS error

Bhanu951’s picture

Status: Needs work » Needs review

Fixed PHPCS error.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Thank you! looks ready again

xjm’s picture

I left some comments are the MR that shoukd help move forward.

xjm’s picture

Status: Reviewed & tested by the community » Needs review

I added several suggestions on the MR to improve the new APIs, the deprecations, and the documentation.

If you're unable to accept suggestions in the UI even with push access, respond to the thread with 👍 and I or the original PR author can accept the suggestions on your behalf.

Thanks everyone!

Bhanu951’s picture

@xjm
Thanks for the review and suggestions.
I have applied the suggests. Ready for review again.

voleger’s picture

Added few suggestions

Bhanu951’s picture

@voleger Thanks. Committed them.

xjm’s picture

Merged HEAD so that retesting will work.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
150 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.

voleger’s picture

Status: Needs work » Needs review

Rerolled against 10.1.x branch. Addressed last review comment.

Rinku Jacob 13’s picture

Hi @volger, Reviewed your patch on drupal version -10.1.x.It was successfully applied and after the patch both methods moved to class \Drupal\Core\Render\Element. Adding Screenshots for the reference . Need RTBC +1

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Reviewing MR 3011

Deprecation tests are there
Change record makes sense and offers the alternative to use.
The 1 open thread has been resolved by renaming to ProceduralApiDeprecationTest

Think this is good to go.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Couple of minor comments on the MR.

andypost’s picture

Status: Needs work » Needs review

Fixed both nits

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems comments in the MR have addressed so moving to RTBC.

longwave’s picture

Status: Reviewed & tested by the community » Needs review

I am wondering now if we should just deprecate these with no replacement. These were first introduced in #455844: Allow more granular theming of drupal_render'ed elements to simplify life for PHPTemplate themers so they could exclude parts of render arrays directly from a template.

Now we are using Twig, I am not sure we need these at all? We have the without() filter in Twig to serve this purpose already. template_preprocess_file_widget_multiple() could be refactored so it doesn't use them. I can't find any uses in contrib either - http://grep.xnddx.ru/search?text=hide%28&filename= only finds false positives in JavaScript files.

VladimirAus made their first commit to this issue’s fork.

VladimirAus’s picture

Good point by @longwave.
Should we keep methods for backwards compatibility even if not in use?

andypost’s picture

Pushed commit which inlining usage without replacement, moved documentation to \Drupal\Core\Render\RendererInterface::render() as it still explains how elements and children are traversed using #printed semaphore.

CR needs update and +1 to deprecate without replacement

andypost’s picture

To prevent collisions with @VladimirAus here's a patch I suppose, maybe it needs better wording instead of #printed=TRUE in deprecation message

longwave’s picture

Title: Move hide and show to render/element class » Deprecate hide() and show()
Issue tags: +Needs frontend framework manager review

Tagging for FEFM review.

longwave’s picture

andypost’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated IS and CR

andypost’s picture

Status: Needs review » Needs work

The last submitted patch, 103: 2258355-103.patch, failed testing. View results

andypost’s picture

Status: Needs work » Needs review

unrelated failures in head

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All code changes look good to me.
Deprecation message testing has been added.
For me it is RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 103: 2258355-103.patch, failed testing. View results

andypost’s picture

Status: Needs work » Reviewed & tested by the community

known failure Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLibraryTest

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Looks good, just some nits on the comments and deprecation:

  1. +++ b/core/includes/common.inc
    @@ -348,14 +348,8 @@ function drupal_attach_tabledrag(&$element, array $options) {
    + * Refer to Drupal\core\lib\Drupal\Core\Render\RendererInterface::render()
    + * for additional documentation.
    

    "Drupal\core\lib" is incorrect, and not even sure we need this comment, given we are removing it anyway and there is a change record. This needs changing in two places.

  2. +++ b/core/includes/common.inc
    @@ -363,11 +357,14 @@ function drupal_attach_tabledrag(&$element, array $options) {
    +  @trigger_error('The global hide() function is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use to inline #printed=TRUE instead. See https://www.drupal.org/node/3261271', E_USER_DEPRECATED);
    

    "Set the #printed element property to TRUE instead." reads better to me. This needs changing in all places that refer to the deprecation.

  3. +++ b/core/lib/Drupal/Core/Render/RendererInterface.php
    @@ -116,6 +116,15 @@ public function renderPlaceholder($placeholder, array $elements);
    +   * element, be sure to set element['#printed']=TRUE before its parent
    

    Let's use real code: $element['#printed'] = TRUE

andypost’s picture

Status: Needs work » Needs review
FileSize
4.79 KB
7.47 KB

Fixed, I find the comment useless as well, also there's a fixed @see links to render method docs

smustgrave’s picture

Status: Needs review » Needs work

Seems to have build failures.

But checked interdiff and points #109 appear to be addressed.

andypost’s picture

Status: Needs work » Needs review
bnjmnm’s picture

Status: Needs review » Needs work
Issue tags: -Needs frontend framework manager review

Deprecating these seems worthwhile. I'd like to see a little bit of additional docs just to make it easier to grok if someone is dealing with code that now uses #printed instead of hide() / show(), which may not be the most consequential thing but a relatively simple change.

  1. Lets also update the doc for #printed in core/lib/Drupal/Core/Render/Element/RenderElement.php to clarify that it can be set to TRUE to prevent rendering as well, similar to what was added in RendererInterface
  2. +++ b/core/modules/file/file.field.inc
    @@ -66,9 +66,9 @@ function template_preprocess_file_widget_multiple(&$variables) {
         // Delay rendering of the "Display" option and the weight selector, so that
    

    Since changing #printed is a little less self-explanatory than a hide() method, could this comment be expanded slightly to describe how the rendering is being delayed?

alexpott’s picture

FWIW these methods are used by contrib and probably custom - see
http://grep.xnddx.ru/search?text=+hide%28&filename=.php
http://grep.xnddx.ru/search?text=+hide%28&filename=.module
http://grep.xnddx.ru/search?text=+show%28&filename=.module

There's loads and in popular modules. Are we really sure about this?

smustgrave’s picture

Looking at that list saml and editorally would be disruptive.

alexpott’s picture

Issue summary: View changes
Issue tags: +Needs issue summary update

This issue summary claims that there are no contrib usages - this in correct as per #114 - I'm not really sure how to update it.

longwave’s picture

Apologies for the mistake in #95, I should have filtered by extension. I went through the lists in #114 and while there are a handful of genuine uses, some are form elements that should probably be hidden by setting #access instead, and others are false positives:

  • accessibility: a comment in a PHPTemplate template
  • chinese_address: no published 8.x release
  • zen: an unported PHPTemplate template
  • bricks: affected, but probably should use #access instead
  • editoria11y: false positive in a method name
  • epub_reader_framework: affected, again should probably use #access as this is hiding a form element
  • faq: affected
  • field_group_background_image: affected
  • fpa: affected
  • media_acquiadam: affected, but should probably use #access
  • optimizedb: false positive in a method name
  • site_settings: affected, but should probably use #access
  • ui_patterns_settings: affected
  • packery: affected, but should use #access
  • damopen: affected, but should use #access
  • flickity: : affected, but should use #access
  • protected_file: affected (looks similar to the core preprocess that we have to alter here)
  • saml_sp: affected, but should use #access
  • uber_publisher_social_post: affected, but should use #access
  • vertical_tabs_config: affected
  • oembed: no published 8.x release
  • module_filter: false positive in JavaScript

As it looks like the many of the cases in contrib are actually using this to hide form elements, while this works, it's not really how it was intended to be done as far as I am aware - form elements should set #access to FALSE instead. If this is correct, to me this is a good reason to deprecate this and point users in the correct direction.

I think the options are:

  1. Do nothing, leave this alone
  2. Deprecate, explain in the deprecation/change record that form alters should use #access and render elements should use #printed
  3. Move hide() and show() to static methods on Element
andypost’s picture

I think it just needs better documentation for #printed as #113 said and deprecation

Great points about mixing it with #access but usage in contrib tells that no reason to keep it as public API

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.