0

So I have a module that defines a custom field which I need to style.

It seems the right way to accomplish is to define a library in my module and then refer to it through the '#attached' property.

Which I did, but the css file is not being loaded (I've cleared the cache, reinstall the module, no avail.) No network error, or other error of any kind. The file just isn't loaded.

Here's the relevant parts of my code:

swan_fields_pt_zipcode.libraries.yml

zipcode_widget:
  css:
    component:
      'css/zipcodewidget.layout.css': {}

swan_fields_pt_zipcode.info.yml

name: Swan Fields PT ZipCode
type: module
core: 8.x
libraries:
  - 'swan_fields_pt_zipcode/zipcode_widget'

WidgetInterface implementation:

public function formElement(
  FieldItemListInterface $items,
  $delta,
  array $element,
  array &$form,
  FormStateInterface $form_state
) {
  // ...
  // ...form definition and stuff

  $element['insidecontainer']['#attached']['library'][] = 'swan_fields_pt_zipcode/zipcode_widget';
}

What am I missing?

  • Have you looked in the generated HTML? Is there a reference to the CSS file at all? – Jaypan Sep 25 '17 at 8:24
  • No reference to the CSS file in the generated HTML – Tivie Sep 25 '17 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.