public function ParagraphsAccordionPlugin::view

Extends the paragraph render array with behavior.

Parameters

array &$build: A renderable array representing the paragraph. The module may add elements to $build prior to rendering. The structure of $build is a renderable array as expected by drupal_render().

\Drupal\paragraphs\Entity\Paragraph $paragraph: The paragraph.

\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The entity view display holding the display options configured for the entity components.

string $view_mode: The view mode the entity is rendered in.

Overrides ParagraphsBehaviorInterface::view

File

paragraphs_collection/modules/paragraphs_collection_demo/src/Plugin/paragraphs/Behavior/ParagraphsAccordionPlugin.php, line 28

Class

ParagraphsAccordionPlugin
Provides a way to define accordion effect.

Namespace

Drupal\paragraphs_collection_demo\Plugin\paragraphs\Behavior

Code

public function view(array &$build, Paragraph $paragraph, EntityViewDisplayInterface $display, $view_mode) {
  foreach (Element::children($build) as $field) {
    if ($field == $this
      ->getConfiguration()['paragraph_accordion_field']) {
      $build[$field]['#attributes']['class'][] = 'accordion';
      break;
    }
  }
  $build['#attached']['library'] = [
    'paragraphs_collection_demo/accordion',
  ];
}