Homebox-Actions Container attributes are not real attributes but an array

Created on 2 November 2023, 8 months ago

Problem/Motivation

Some context.. tried to do this:

function THEMENAME_theme_suggestions_container_alter(array &$suggestions, array $variables) {
  if($variables['#attributes']->hasClass('homebox-actions')){
     dsm($variables);
  }
}

=> Error: Call to a member function hasClass() on array in drowl_child_theme_suggestions_container_alter()

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: works as designed

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @thomas.frobieter
  • Issue was unassigned.
  • Status changed to Closed: works as designed 8 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Looking at the code where we're using the actions type:

    $build['homebox_actions_general'] = [
          '#type' => 'actions',
          '#weight' => -100,
          'back_button' => $this->buildBackButton($entity),
          '#attributes' => [
            'class' => [
              'container-inline',
              'homebox-actions',
              'homebox-actions--general',
              'homebox-actions--general-personalize',
            ],
          ],
        ];
    

    and the docs:
    https://www.drupal.org/docs/8/theming-drupal-8/using-attributes-in-templ... β†’
    https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Template%...

    I think we're doing it right. Still I'm not 100% sure.

    So this is maybe what you want:

    if(is_array($variables['#attributes']['class]) && in_array('homebox-actions', $variables['#attributes']['class])) {
    ...
    }
    

    Still I don't think it's the right way to add a button. Correct would be to use a hook_form_alter() here I guess. But that's a different topic.

    Closing this for now until we find other cases where #attributes are not properly handled.

Production build 0.69.0 2024