You are here

public function ParagraphsSliderPlugin::view in Paragraphs Collection 8

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.

Return value

array A render array provided by the plugin.

Overrides ParagraphsBehaviorInterface::view

File

modules/paragraphs_collection_demo/src/Plugin/paragraphs/Behavior/ParagraphsSliderPlugin.php, line 221

Class

ParagraphsSliderPlugin
Provides Slider plugin.

Namespace

Drupal\paragraphs_collection_demo\Plugin\paragraphs\Behavior

Code

public function view(array &$build, Paragraph $paragraph, EntityViewDisplayInterface $display, $view_mode) {
  $elements = [];
  $field_name = $this
    ->getConfiguration()['field_name'];
  $slider_optionset = $paragraph
    ->getBehaviorSetting($this
    ->getPluginId(), 'slick_slider');
  if (isset($build[$field_name])) {
    $field_slides = Element::children($build[$field_name]);
    foreach ($field_slides as $delta) {
      $elements['items'][]['slide'] = $build[$field_name][$delta];
    }
  }
  if ($slider_optionset) {
    $elements['options'] = $this
      ->getOptionSet($slider_optionset);
  }
  $build[$field_name] = $this->slickManager
    ->build($elements);
}