The form provided in this function is a renderable element and should use the more flexible #attached property rather than drupal_add_css() in the function.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

barbi’s picture

Status: Active » Needs review

Drupal newbie here.
Can you please let me know where in the form tree does the #attached go?
I am trying to add it to the $form['blocks']. Is this right?

  $form['blocks'] = array(
    '#attached' => array(
      'css' => array(drupal_get_path('module', 'block') . '/block.css')
    )
  );
DjebbZ’s picture

Status: Needs review » Needs work

Not sure. I would rather write

  $form['#attached']['css'] = array(
    drupal_get_path('module', 'block') . '/block.css'),
  );

Basically just removing the "blocks" entry, because it needs to be attached to the whole form. Read the Form API reference on api.drupal.org.
You should try to provide a patch for this.

davisben’s picture

Status: Needs work » Needs review
FileSize
619 bytes

Here's a patch.

lambic’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

Dries’s picture

Issue tags: +Needs backport to D7

Committed to 8.x. This is a candidate for backporting to 7.x. I'm moving this to webchick's queue so she can consider committing this to 7.x.

RobLoach’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
607 bytes
RobLoach’s picture

Version: 8.x-dev » 7.x-dev
Issue tags: -Needs backport to D7

Status: Needs review » Needs work
Issue tags: -Novice, -dgd7

The last submitted patch, use-attached-for-css-1122584-4.patch, failed testing.

RobLoach’s picture

Status: Needs work » Needs review
Issue tags: +Novice, +dgd7
lambic’s picture

Status: Needs review » Reviewed & tested by the community
webchick’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +Needs backport to D7

This doesn't look like it'll change anything as far as what CSS is shown on the page; merely how it's added.

Committed and pushed to 7.x. Thanks!

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