Yaffs site version 1.1
[yaffs-website] / web / modules / contrib / blazy / src / Dejavu / BlazyStylePluginBase.php
1 <?php
2
3 namespace Drupal\blazy\Dejavu;
4
5 use Drupal\views\Plugin\views\style\StylePluginBase;
6 use Drupal\blazy\BlazyManagerInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8
9 /**
10  * A base for blazy views integration to have re-usable methods in one place.
11  *
12  * @see \Drupal\mason\Plugin\views\style\MasonViews
13  * @see \Drupal\gridstack\Plugin\views\style\GridStackViews
14  * @see \Drupal\slick_views\Plugin\views\style\SlickViews
15  */
16 abstract class BlazyStylePluginBase extends StylePluginBase {
17
18   use BlazyStylePluginTrait;
19
20   /**
21    * {@inheritdoc}
22    */
23   protected $usesRowPlugin = TRUE;
24
25   /**
26    * {@inheritdoc}
27    */
28   protected $usesGrouping = FALSE;
29
30   /**
31    * Constructs a GridStackManager object.
32    */
33   public function __construct(array $configuration, $plugin_id, $plugin_definition, BlazyManagerInterface $blazy_manager) {
34     parent::__construct($configuration, $plugin_id, $plugin_definition);
35     $this->blazyManager = $blazy_manager;
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
42     return new static($configuration, $plugin_id, $plugin_definition, $container->get('blazy.manager'));
43   }
44
45   /**
46    * Returns an individual row/element content.
47    */
48   public function buildElement(array &$element, $row, $index) {
49     $settings = &$element['settings'];
50     $item_id  = empty($settings['item_id']) ? 'box' : $settings['item_id'];
51
52     // Add main image fields if so configured.
53     if (!empty($settings['image'])) {
54       // Supports individual grid/box image style either inline IMG, or CSS.
55       $image             = $this->getImageRenderable($settings, $row, $index);
56       $element['item']   = $this->getImageItem($image);
57       $element[$item_id] = empty($image['rendered']) ? [] : $image['rendered'];
58     }
59
60     // Add caption fields if so configured.
61     $element['caption'] = $this->getCaption($index, $settings);
62
63     // Add layout field, may be a list field, or builtin layout options.
64     if (!empty($settings['layout'])) {
65       $this->getLayout($settings, $index);
66     }
67   }
68
69 }