Problem/Motivation

In Twig templates, calling <div{{ attributes.addClass() }}>results in <div class="">. When no attributes exists and addClass() is called without any arguments, it adds an empty class definition.

I discovered this while working on #2329759-9: Move container classes from preprocess to templates

Proposed resolution

Remaining tasks

API changes

none

CommentFileSizeAuthor
#1 drupal-attribute-addclass-2330731-1.test-must-fail.patch699 bytesSutharsan
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 75,610 pass(es), 1 fail(s), and 0 exception(s). View
#1 drupal-attribute-addclass-2330731-1.patch3.18 KBSutharsan
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 75,611 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

Sutharsan’s picture

Status: Active » Needs review
FileSize
3.18 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 75,611 pass(es). View
699 bytes
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 75,610 pass(es), 1 fail(s), and 0 exception(s). View

This patch adds an if-condition to addClass() to prevent adding a single empty class.

Status: Needs review » Needs work

The last submitted patch, 1: drupal-attribute-addclass-2330731-1.test-must-fail.patch, failed testing.

Sutharsan’s picture

Status: Needs work » Needs review

Last test failed on purpose. Back to needs review.

Cottser’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -frontendbanana +frontend, +banana, +Quick fix

Looks good, makes sense, and adds test coverage. RTBC, thanks @Sutharsan!

Cottser’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 4697eb9 and pushed to 8.0.x. Thanks!

  • alexpott committed 4697eb9 on 8.0.x
    Issue #2330731 by Sutharsan: Fixed Attribute::addClass() adds empty...
Cottser’s picture

Status: Fixed » Closed (fixed)

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