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.
In ColorBackgroudFormatter.php
#attached uses css to add css to an element, but this is no more supported.
foreach ($items as $delta => $item) {
$elements[$delta] = array(
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => t('The content area color has been changed to @code', array('@code' => $item->value)),
'#attached' => array(
'css' => array(
array(
'data' => 'main { background-color:' . $item->value . ';}',
'type' => 'inline',
),
),
),
);
}
Comment | File | Size | Author |
---|---|---|---|
#2 | cannot_add_css_using-2715247-2.patch | 962 bytes | jeevanbhushetty |
|
Comments
Comment #2
jeevanbhushetty CreditAttribution: jeevanbhushetty at QED42 commentedComment #3
AjitSNice catch! The patch solves the issue quite elegantly.
RTBC from my side.
Comment #5
Mile23I'm going to commit this because it's really a critical: D8 throws an unhandled exception meaning things stop working.
I'm a bit gobsmacked that we don't have a test for
ColorBackgroudFormatter
, because that would have found this flaw. We need to add that, but it can be a follow-up since this is actually critical.Here's the follow-up: #2720833: Add a functional test for field_example ColorBackgroudFormatter
Thanks, folks!
Comment #6
jeevanbhushetty CreditAttribution: jeevanbhushetty at QED42 commentedThanks @Miles23, I am working on test case for ColorBackgroundFormatter, we already have issues created for this #2634034: Create a regression test for ColorBackgroudFormatter so closing #2720833: Add a functional test for field_example ColorBackgroudFormatter as duplicate.