getBeforeAfterSlider(); $fields = []; foreach ($variables['field_collection_items'] as $field_collection_item_id) { if (isset($node_before_after_slider[$field_collection_item_id])) { $fields[] = $node_before_after_slider[$field_collection_item_id]; } } $has_full_width_images = FALSE; // Form sliders. $variables['sliders'] = array_map(function ($field) use (&$has_full_width_images) { if (empty($field['images']['before']) || empty($field['images']['after'])) { return []; } // Set the class name for the layout. $layout = $field['layout'] ?? 'default'; $has_full_width_images = $layout === 'full-width'; // Create a render array of images. $images = []; foreach ($field['images'] as $key => $image) { $images[$key] = [ '#theme' => 'image_style', '#path' => $image['uri'], '#style_name' => 'fresco_1200', '#alt' => $image['alt'], '#attributes' => [ 'class' => sprintf('%s-image', $key), ], 'label' => $image['label'], ]; } // Create a render array. $build = [ 'beer_slider' => [ '#type' => 'container', '#attributes' => [ 'class' => [ 'beer-slider', implode('-', ['layout', $layout]), ], 'data-beer-label' => $images['after']['label'], ], [ $images['after'], [ '#type' => 'container', '#attributes' => [ 'class' => 'beer-reveal', 'data-beer-label' => $images['before']['label'], ], [ $images['before'], ], ], ], ], ]; if (empty($field['caption']) && empty($field['photographer'])) { return $build; } $build['caption'] = [ '#type' => 'container', '#attributes' => [ 'class' => [ 'footer', 'beer-slider--footer' ], ], 'content' => [ '#type' => 'container', '#attributes' => [ 'class' => 'caption', ], 'content' => [], ], ]; if (!empty($field['caption'])) { $build['caption']['content']['content'][] = [ '#type' => 'markup', '#markup' => str_pad($field['caption'], strlen($field['caption']) + 2, ' ', STR_PAD_BOTH), ]; } if (!empty($field['photographer'])) { $build['caption']['content']['content'][] = [ '#type' => 'html_tag', '#tag' => 'span', '#value' => sprintf(' Fotograf:  %s', $field['photographer']), '#attributes' => [ 'class' => 'photographer', ], ]; } return $build; }, $fields); $variables['has_full_width_images'] = $has_full_width_images; drupal_add_library('mkbh_beforeafter_slider', 'beerslider'); drupal_add_library('mkbh_beforeafter_slider', 'beerslider_initialization'); }