API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...

The example code shows

'#attributes' => array(
'class' => 'accommodation',
),

I believe this should read

'#attributes' => array(
'class' => array('accommodation'),
),

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mholloway created an issue. See original summary.

gaurav.kapoor’s picture

Status: Active » Needs review
FileSize
1.25 KB

Converted class attributes to array and replaced old array syntax with new one.

levmyshkin’s picture

I checked container with plain string classes in attributes and with classes in array. Both options are working. But I checked Drupal core modules and there are only classes in array:
https://api.drupal.org/api/drupal/core%21modules%21views_ui%21src%21View...
https://api.drupal.org/api/drupal/core%21modules%21field_ui%21src%21Form...
https://api.drupal.org/api/drupal/core%21modules%21field_ui%21src%21Form...
https://api.drupal.org/api/drupal/core%21modules%21media_library%21src%2...

Also as follow from this RenderElement comment:
core/lib/Drupal/Core/Render/Element/RenderElement.php
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...

* - #attributes: (array) HTML attributes for the element. The first-level
* keys are the attribute names, such as 'class', and the attributes are
* usually given as an array of string values to apply to that attribute
* (the rendering system will concatenate them together into a string in
* the HTML output).

Classes should be in array. So I think we need to apply changes for comments in Container class. I'm only not sure about code style for array() or [].

levmyshkin’s picture

Status: Needs review » Reviewed & tested by the community
knyshuk.vova’s picture

The patch looks good and applies successfully. +1 for RTBC.

idebr’s picture

Version: 8.2.x-dev » 8.7.x-dev
idebr’s picture

alexpott’s picture

Title: FAPI Container example class must be array » Change FAPI Container example class to an array
Category: Bug report » Task
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

It does not have to be an array so this is just a task.

Committed and pushed dcf633a96c to 8.7.x and 5525420f98 to 8.6.x. Thanks!

As a docs only change backported to 8.6.x

  • alexpott committed dcf633a on 8.7.x
    Issue #2903322 by gaurav.kapoor, levmyshkin: Change FAPI Container...

  • alexpott committed 5525420 on 8.6.x
    Issue #2903322 by gaurav.kapoor, levmyshkin: Change FAPI Container...
idebr’s picture

Version: 8.7.x-dev » 8.6.x-dev

Status: Fixed » Closed (fixed)

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