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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sutharsan’s picture

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.

star-szr’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!

star-szr’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...
star-szr’s picture

Status: Fixed » Closed (fixed)

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