Problem/Motivation

HTML classes should be usually added in templates instead of preprocess functions. Also, Drupal core modules shouldn't include represantional HTML classes.

Proposed resolution

Move the HTML classes from the preprocess function to the template. The classes should be added in a template in Classy / Stable but not in the module.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

lauriii created an issue. See original summary.

lauriii’s picture

hardik_patel_12’s picture

Kindly review a patch

hardik_patel_12’s picture

Status: Active » Needs review

Status: Needs review » Needs work
hardik_patel_12’s picture

StatusFileSize
new540 bytes
new1.77 KB

Kindly follow a new patch

hardik_patel_12’s picture

Status: Needs work » Needs review
ankush_03’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new13.8 KB
new41.95 KB

Patch #6 Working fine, Also attached image for the same.

Status: Reviewed & tested by the community » Needs work
prabha1997’s picture

Assigned: Unassigned » prabha1997

I am working on this issue

prabha1997’s picture

Assigned: prabha1997 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.36 KB

I created a patch for this issue

prabha1997’s picture

StatusFileSize
new1.36 KB
new1.89 KB
dhirendra.mishra’s picture

Assigned: Unassigned » dhirendra.mishra
Status: Needs review » Needs work

@prabha, Your patch does not contain the changes from preprocess which was there in #6 comment.

Let me upload the latest patch along with Inter-diff from #12.

dhirendra.mishra’s picture

Assigned: dhirendra.mishra » Unassigned
Status: Needs work » Needs review
StatusFileSize
new482 bytes
new1.92 KB

Status: Needs review » Needs work

The last submitted patch, 14: 3105015-14.patch, failed testing. View results

dhirendra.mishra’s picture

Status: Needs work » Needs review
StatusFileSize
new1.33 KB
new2 KB

Status: Needs review » Needs work

The last submitted patch, 16: 3105015-16.patch, failed testing. View results

prabha1997’s picture

Assigned: Unassigned » prabha1997
prabha1997’s picture

Assigned: prabha1997 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.47 KB
new1.74 KB

we can add classes directly using class attribute

Status: Needs review » Needs work

The last submitted patch, 19: 3105015-19.patch, failed testing. View results

prabha1997’s picture

StatusFileSize
new1.69 KB
new1.76 KB
krzysztof domański’s picture

1. Re #19 @prabha1997 We should leave the variable attributes in templates.

-<div{{ attributes }}>
+<div class="image-widget js-form-managed-file form-managed-file clearfix">

Then we can use attributes.classes in child templates, for example:

{% extends '@claro/content-edit/file-managed-file.html.twig' %}
{% set attributes = attributes.addClass(classes) %}

2. Patch from #14 looks good. There are more templates to change. See core/modules/image/templates/image-widget.html.twig and core/themes/claro/templates/content-edit/image-widget.html.twig. One note, div {{ there should be no spaces here.

diff --git a/core/modules/image/templates/image-widget.html.twig b/core/modules/image/templates/image-widget.html.twig
index 3a3d3da..5377968 100644
--- a/core/modules/image/templates/image-widget.html.twig
+++ b/core/modules/image/templates/image-widget.html.twig
@@ -12,7 +12,15 @@
  * @ingroup themeable
  */
 #}
-<div{{ attributes }}>
+{%
+  set classes = [
+    'image-widget',
+    'js-form-managed-file',
+    'form-managed-file',
+    'clearfix',
+  ]
+%}
+<div{{ attributes.addClass(classes) }}>
krzysztof domański’s picture

Now I noticed that we should not change the templates in the module. #22.2 is not a good idea then.

The classes should be added in a template in Classy / Stable but not in the module.

swatichouhan012’s picture

Status: Needs work » Needs review
StatusFileSize
new3.65 KB
new3.05 KB

We can use classes from parent template. I am attaching patch here please review.

The last submitted patch, 24: 3105015-24.patch, failed testing. View results

swatichouhan012’s picture

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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 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.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.