Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've implemented Preprocess plugin for page and trying to run this code in proprocessVariables()
method:
if (array_key_exists('newsmenu', $variables['page']['header'])) {
$variables->addClass('with-section-menu', DrupalAttributes::CONTENT);
}
but this code fails with
Warning: array_unique() expects parameter 1 to be array, object given in Drupal\bootstrap\Utility\Attributes->getClasses() (line 63 of themes/bootstrap/src/Utility/Attributes.php).
Here is method code
public function &getClasses() {
$classes = &$this->offsetGet('class', []);
$classes = array_unique($classes);
return $classes;
}
and in case there is no defined classes yet $this->offsetGet('class', [])
returns instance of \Drupal\Core\Template\AttributeArray
instead of just array.
Is this a bug or I'm doing something wrong?
Comment | File | Size | Author |
---|
Comments
Comment #2
tstoecklerI've hit a similar issue where custom code was incorrectly setting
$element['#attributes']['class']
to a string instead of an array. That is easy to fix, but I'm still wondering whether Bootstrap should be a bit more forgiving here, especially since there are also still instances in core of this.Attached patch should fix this.
@berdyshev could you try it out whether this fixes your issue as well?
Comment #3
markhalliwellClasses should be an array of strings. Find offending code and fix it.