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:
screenshot of api.drupal.org with bad output

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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rwohleb created an issue. See original summary.

cilefen’s picture

Issue tags: +Novice
deepanker_bhalla’s picture

Assigned: Unassigned » deepanker_bhalla

Working on it.. and will share the solution soon.

msankhala’s picture

msankhala’s picture

Version: 8.6.x-dev » 8.7.x-dev
Issue tags: +ContributionWeekend2019

This issue exists on `8.7.x` as well.

msankhala’s picture

Status: Active » Needs review
FileSize
706 bytes

Here is the patch.

msankhala’s picture

Issue tags: +dcg2019, +DrupalCampGoa2019
rachel_norfolk’s picture

Assigned: msankhala » Unassigned

just removing assignment if it is now up for review ;-)

rachel_norfolk’s picture

Issue summary: View changes
Issue tags: +Needs steps to reproduce

Just 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

rachel_norfolk’s picture

Status: Needs review » Needs work
bibliophileaxe’s picture

We 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?

bibliophileaxe’s picture

Issue summary: View changes
bibliophileaxe’s picture

Issue summary: View changes
bibliophileaxe’s picture

Status: Needs work » Needs review
rachel_norfolk’s picture

rachel_norfolk’s picture

Status: Needs review » Reviewed & tested by the community

This 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!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This is trickier though. This is twig code and not PHP code. We need our @code to be different code aware.

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.

bibliophileaxe’s picture

Created an issue for parsing twig comments in @code @endcode blocks - https://www.drupal.org/project/api/issues/3047324.

jhodgdon’s picture

I 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?

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.

jhodgdon’s picture

Issue summary: View changes
Issue tags: +Europe2020

Updating issue summary.

I have tagged this issue as Novice and Europe2020 for first time contributors at DrupalCon Europe. Thanks

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!

Geordi’s picture

Frederikvho’s picture

Status: Needs work » Needs review
Frederikvho’s picture

Does anyone know how to pass the error from test? It says the file does not exist, yet it should exist in 9.2-dev?

cilefen’s picture

Hello: 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...

cilefen’s picture

But 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?

Geordi’s picture

Yes I am working with a git checkout of drupal core. I used the "Create patch" function of PHPStorm, maybe that was the problem?

cilefen’s picture

Yes, probably. In fact, the patch did contain the "core" directory. I was mistaken about that.

The automated tests use git apply <patch_file>.

jhodgdon’s picture

Status: Needs review » Needs work

That patch seems to work... and it looks good, except for the indentation:

  * been printed from being printed again. For example:
  * @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
+ *  Produces:
+ * @code
+ *  <cat class="cat black-cat white-cat black-white-cat my-custom-class" id="socks">
  * @endcode
  *
  * The attribute keys and values are automatically escaped for output with

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?

shreyakaushik11’s picture

Assigned: Unassigned » shreyakaushik11

I'm assigning it to me.

shreyakaushik11’s picture

Assigned: shreyakaushik11 » Unassigned
Status: Needs work » Needs review
FileSize
4.65 KB
4.49 KB

I'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.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks 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!

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
900 bytes
3.85 KB
jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

  • catch committed 50d154e on 9.2.x
    Issue #3014121 by Geordi, shreyakaushik11, anmolgoyal74, msankhala,...

  • catch committed 874196d on 9.1.x
    Issue #3014121 by Geordi, shreyakaushik11, anmolgoyal74, msankhala,...
catch’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!

Status: Fixed » Closed (fixed)

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