Problem/Motivation
In core/lib/Drupal/Core/Template/Attribute.php there is a problem on api.drupal.org displaying a code block that looks like this:
* @code
* <cat class="{{ attributes.class }} my-custom-class"{{ attributes|without('class') }}>
* {# Produces <cat class="cat black-cat white-cat black-white-cat my-custom-class" id="socks"> #}
* @endcode
The output looks like this:
Proposed resolution
Move the line that gives the output outside of the code/endcode block. So it should look something like this:
* @code
* <cat class="{{ attributes.class }} my-custom-class"{{ attributes|without('class') }}>
* @endcode
* Produces:
* @code
* <cat class="cat black-cat white-cat black-white-cat my-custom-class" id="socks">
* @endcode
Steps to reproduce
Visit https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Template%...
and see the problematic
Remaining tasks
Make a new patch (Novice task!)
User interface changes
The comment will no longer incorrectly appear in the generated error message
API changes
none
Data model changes
none
Release notes snippet
none
Original report by rwohleb
API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Template%...
The code snippet for using "without" on attributes is not properly escaped. The browser is trying to interpret it. See screenshot.
Comment | File | Size | Author |
---|---|---|---|
#36 | interdiff_34_36.txt | 3.85 KB | anmolgoyal74 |
#36 | 3014121-36.patch | 900 bytes | anmolgoyal74 |
#34 | interdiff_30-34.txt | 4.49 KB | shreyakaushik11 |
#34 | 3014121-34.patch | 4.65 KB | shreyakaushik11 |
#30 | Attribute-php-code-snippet-3014121-30.patch | 733 bytes | Geordi |
Comments
Comment #2
cilefen CreditAttribution: cilefen as a volunteer commentedComment #3
deepanker_bhalla CreditAttribution: deepanker_bhalla as a volunteer and at Srijan | A Material+ Company commentedWorking on it.. and will share the solution soon.
Comment #4
msankhala CreditAttribution: msankhala at Srijan | A Material+ Company commentedComment #5
msankhala CreditAttribution: msankhala at Srijan | A Material+ Company commentedThis issue exists on `8.7.x` as well.
Comment #6
msankhala CreditAttribution: msankhala at Srijan | A Material+ Company commentedHere is the patch.
Comment #7
msankhala CreditAttribution: msankhala at Srijan | A Material+ Company commentedComment #8
rachel_norfolkjust removing assignment if it is now up for review ;-)
Comment #9
rachel_norfolkJust adding an Issue Summary Template and some tasks that help the reviewers (and committers!)
Looks like a couple of actions are needed, too, like how to reproduce
Comment #10
rachel_norfolkComment #11
bibliophileaxeWe can reproduce it by setting up -
https://www.drupal.org/docs/7/modules/api-module/create-your-own-api-7x-...
and then checking the documentation page for Attributes.php.
The issue is also visible here: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Template%...
Also, just a thought - phpcs does not even give a warning for this, should this also be included in Drupal coding standards?
Comment #12
bibliophileaxeComment #13
bibliophileaxeComment #14
bibliophileaxeComment #15
rachel_norfolkComment #16
rachel_norfolkThis change does indeed stop the comment appearing in generated phpdocs.
Adding a test into phpcs makes sense. It's a different project, though, at drupal.org/project/coder and an issue should be raised there (referencing this one)
Setting to RTBC!
Comment #17
alexpottThis is trickier though. This is twig code and not PHP code. We need our @code to be different code aware.
Comment #19
bibliophileaxeCreated an issue for parsing twig comments in @code @endcode blocks - https://www.drupal.org/project/api/issues/3047324.
Comment #20
jhodgdonI think that the right solution here is actually to take the "Produces" part out of the @code/@endcode entirely. I don't see why it needs to be inside the code block at all?
Comment #24
jhodgdonUpdating issue summary.
After 11 December 2020, anyone can do this, but until then we are asking only participants in DrupalCon Europe first time contributors take this issue on. Thanks!
Comment #25
Geordi CreditAttribution: Geordi commentedComment #26
FrederikvhoComment #27
FrederikvhoDoes anyone know how to pass the error from test? It says the file does not exist, yet it should exist in 9.2-dev?
Comment #28
cilefen CreditAttribution: cilefen as a volunteer commentedHello: The patch looks rather unusual in its format. The expected patch format is the one that `git diff` creates. See https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa...
Comment #29
cilefen CreditAttribution: cilefen as a volunteer commentedBut in fact the reason it fails is because the patch is missing the core directory, as in
core/lib/Drupal/Core/Template/Attribute.php
.Are you working with a Git checkout of Drupal core?
Comment #30
Geordi CreditAttribution: Geordi commentedYes I am working with a git checkout of drupal core. I used the "Create patch" function of PHPStorm, maybe that was the problem?
Comment #31
cilefen CreditAttribution: cilefen as a volunteer commentedYes, probably. In fact, the patch did contain the "core" directory. I was mistaken about that.
The automated tests use
git apply <patch_file>
.Comment #32
jhodgdonThat patch seems to work... and it looks good, except for the indentation:
The "Produces" line and code lines are all indented by 1 space from the rest of the documentation. We would normally either want to indent things in doc blocks by 0 or 2 spaces. I see that the 1-space is consistent with the lines that were already in the code section... but can we fix it? Either remove the indentation or indent by 2 spaces. Thanks! I think removing the indentation would be best?
Comment #33
shreyakaushik11 CreditAttribution: shreyakaushik11 at Srijan | A Material+ Company for Drupal India Association commentedI'm assigning it to me.
Comment #34
shreyakaushik11 CreditAttribution: shreyakaushik11 at Srijan | A Material+ Company for Drupal India Association commentedI've created a patch and has implemented the changes suggested in #32. I've switched it from 1 space to 0 space as it was 0 in other files so just to keep it consistent.
Please review the patch and the interdiff.
Comment #35
jhodgdonThanks for the patch!
Our practice in the Drupal core project is that one issue should cover one thing. This issue is only about fixing the part of Attribute.php that is described in the issue summary. So even though the rest of your fixes would be a good idea to do, we need the patch for this issue to only cover those few lines in Attribute.php.
Could you make another patch that only changes those few lines (which were changed correctly in the latest patch)? Thanks!
Comment #36
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedComment #37
jhodgdonThank you!
Comment #40
catchCommitted/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!