Search code examples
listaccordiondrupal-8

Drupal 8 - creating an accordion field


In Drupal 8 -- I want to modify the basic-page content type to be able to support an "accordion field type"

I've seen the list field type - that can have unlimited fields -- but I am looking for a solution that can feature -- header/body - type features.

enter image description here


Solution

  • There is no module to handle this for you, the solution is to create unlimited Entity Reference in your content type, it must have two fields, Title and Body as you want, and to convert it to accordions you should customize new entity field theme and implement accordion there.

    Another solution is, handle it by https://www.drupal.org/project/views_bootstrap which support accordion or https://www.drupal.org/project/faqfield module :

    Features:
    Configurable default text formats
    Configurable answer widget
    Types: Normal textareas, textfields and formatable textareas
    Formatable textareas for any Wysiwyg editor
    Configurable number of rows for textarea widget
    Field formatters
    jQuery Accordion UI
    Simple themeable text
    Definition list (HTML <dl>)
    Anchor link list
    Accordion display options
    Choose first active question
    Collapse open questions
    Event to open/collapse questions (eg. mouseover, click)