Move classes out of the preprocess functions and into the Twig templates. Use the addClass() attribute method to add classes in the template. Use the clean_class filter to filter class names, if necessary. Maintain all existing functionality and ensure all existing class names are still in the markup, even ones that are inherited.

See the following issues for more detailed examples:
#2217731: Move field classes out of preprocess and into templates
#2254153: Move node classes out of preprocess and into templates

See this change record for information about using the addClass() method:
https://www.drupal.org/node/2315471

See this change record for more information about the phase 1 process of moving class from preprocess to templates:
https://www.drupal.org/node/2325067

Preprocess Functions Modified

template_preprocess_update_report
template_preprocess_update_project_status

Twig Templates Modified

update-report.html.twig
update-project-status.html.twig

Files: 
CommentFileSizeAuthor
#14 update-project-name-2.png72.57 KBDickJohnson
#14 update-classes.png250.13 KBDickJohnson
#10 interdiff.txt604 bytesCottser
#10 2329829-10.patch5.11 KBCottser
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 77,624 pass(es). View

Comments

davidhernandez’s picture

Issue tags: +FUDK
dstorozhuk’s picture

Assigned: Unassigned » dstorozhuk
Cottser’s picture

@dstorozhuk - I don't want to rush you but have you started work on this? I'm just making sure we get patches on all these sub-issues to keep our momentum up :)

If you won't have time you can unassign. I'll give you a couple days to respond as to whether you are working on this or not. Thanks!

Cottser’s picture

Assigned: dstorozhuk » Unassigned

Up for grabs.

lauriii’s picture

Assigned: Unassigned » lauriii
lauriii’s picture

Assigned: lauriii » Unassigned
Status: Active » Needs review
FileSize
5.11 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 76,183 pass(es). View
Wim Leers’s picture

Status: Needs review » Needs work
+++ b/core/modules/update/templates/update-project-status.html.twig
@@ -58,11 +67,18 @@
+  set extra_attributes = [
+    project.status == constant('UPDATE_NOT_SECURE') ? 'project-not-secure',
+    project.status == constant('UPDATE_REVOKED') ? 'project-revoked',
+    project.status == constant('UPDATE_NOT_SUPPORTED') ? 'project-not-supported',
+  ]
+%}
 <div class="info">
   {% if extras %}
     <div class="extra">
       {% for extra in extras %}
-        <div{{ extra.attributes }}>
+        <div{{ extra.attributes.addClass(extra_attributes) }}>

These are extra classes, not extra attributes.

Off-topic: how do you set extra attributes in Twig? Doesn't seem to be supported?

lauriii’s picture

Status: Needs work » Needs review
FileSize
5.11 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 76,313 pass(es). View
896 bytes
davidhernandez’s picture

Cottser’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
5.11 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 77,624 pass(es). View
604 bytes

This is the only thing I could find:

+++ b/core/modules/update/update.report.inc
@@ -290,32 +290,26 @@ function template_preprocess_update_project_status(&$variables) {
+  $variables['status']['attributes'] = new Attribute;

new Attribute() per https://www.drupal.org/coding-standards#constructors.

Rolled in here. Manually tested and RTBC. Nice work!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

  • webchick committed f722c3c on 8.0.x
    Issue #2329829 by Cottser, lauriii | davidhernandez: Move update classes...

Status: Fixed » Closed (fixed)

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

DickJohnson’s picture

FileSize
250.13 KB
72.57 KB

While I was working on #2408499: Rewrite update components inline with our CSS standards I noticed that we still have classes at least in core/modules/update/src/Form/UpdateManagerUpdate.php

example:

1. rows 245-252
    $headers = array(
      'title' => array(
        'data' => $this->t('Name'),
        'class' => array('update-project-name'),
      ),
      'installed_version' => $this->t('Installed version'),
      'recommended_version' => $this->t('Recommended version'),
    );

DOM
search

I also noticed that a lot of markup is coming from somewhere else than templates, so when we start to add new classes to table-elements I'm pretty sure we will get even more classes to non-template files.

As I tried to point out there: https://www.drupal.org/node/2408499#comment-9591331 testing these templates, CSS and which classes are being used and where is relatively difficult, so we should double check things.

davidhernandez’s picture

If there is something we missed, assuming it isn't gigantic, add it here #2407565: Consensus Banana Phase 1, cleanup and we'll try to get it all cleaned up in one patch.

Cottser’s picture

@DickJohnson - in general we knew going into this (banana) that we wouldn't be eliminating all classes. They are coming from too many places. But we can reduce at least. Thanks for looking into that!