dev7ch /
luya-ext-slick
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * SliderBlock. |
||
| 4 | * |
||
| 5 | * @author Silvan Hahn <[email protected]> |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace dev7ch\slick\blocks; |
||
| 9 | |||
| 10 | use dev7ch\slick\BaseSlickBlock; |
||
| 11 | use dev7ch\slick\Module; |
||
| 12 | use luya\cms\frontend\blockgroups\ProjectGroup; |
||
| 13 | use luya\cms\helpers\BlockHelper; |
||
| 14 | |||
| 15 | class SlickBlock extends BaseSlickBlock |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var bool Choose whether a block can be cached trough the caching component. Be carefull with caching container blocks. |
||
| 19 | */ |
||
| 20 | public $cacheEnabled = false; |
||
| 21 | /** |
||
| 22 | * @var int The cache lifetime for this block in seconds (3600 = 1 hour), only affects when cacheEnabled is true |
||
| 23 | */ |
||
| 24 | public $cacheExpiration = 3600; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * {@inheritdoc} |
||
| 28 | */ |
||
| 29 | 2 | public function blockGroup() |
|
| 30 | { |
||
| 31 | 2 | return ProjectGroup::class; |
|
|
0 ignored issues
–
show
|
|||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritdoc} |
||
| 36 | */ |
||
| 37 | 2 | public function name() |
|
| 38 | { |
||
| 39 | 2 | return 'Slick Slider'; |
|
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * {@inheritdoc} |
||
| 44 | */ |
||
| 45 | 2 | public function icon() |
|
| 46 | { |
||
| 47 | 2 | return 'burst_mode'; // see the list of icons on: https://design.google.com/icons/ |
|
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * {@inheritdoc} |
||
| 52 | */ |
||
| 53 | 2 | public function config() |
|
| 54 | { |
||
| 55 | return [ |
||
| 56 | 2 | 'vars' => [ |
|
| 57 | 2 | ['var' => 'images', 'label' => Module::t('block_slick_item'), 'type' => self::TYPE_MULTIPLE_INPUTS, 'options' => [ |
|
| 58 | 2 | ['var' => 'image', 'label' => Module::t('block_slick_image'), 'type' => self::TYPE_IMAGEUPLOAD, 'options' => ['no_filter' => false]], |
|
| 59 | 2 | ['var' => 'alt', 'label' => Module::t('block_slick_image_alt'), 'type' => self::TYPE_TEXT], |
|
| 60 | 2 | ['var' => 'title', 'label' => Module::t('block_slick_image_title'), 'type' => self::TYPE_TEXT], |
|
| 61 | 2 | ['var' => 'link', 'label' => Module::t('block_slick_image_link'), 'type' => self::TYPE_LINK], |
|
| 62 | 2 | ['var' => 'responsive_images', 'label' => Module::t('block_slick_adaptive'), 'type' => self::TYPE_MULTIPLE_INPUTS, 'options' => [ |
|
| 63 | 2 | ['var' => 'image', 'label' => Module::t('block_slick_adaptive_image'), 'type' => self::TYPE_IMAGEUPLOAD, 'options' => ['no_filter' => true]], |
|
| 64 | 2 | ['var' => 'breakpoint', 'label' => Module::t('block_slick_adaptive_breakpoint'), 'type' => self::TYPE_TEXT, 'options' => ['placeholder' => Module::t('block_slick_adaptive_breakpoint_info')]], |
|
| 65 | 2 | ['var' => 'image_hd', 'label' => Module::t('block_slick_adaptive_image_hd'), 'type' => self::TYPE_IMAGEUPLOAD, 'options' => ['no_filter' => true]], |
|
| 66 | 2 | ['var' => 'orientation', 'label' => Module::t('block_slick_adaptive_orientation'), 'type' => self::TYPE_SELECT, 'options' => BlockHelper::selectArrayOption( |
|
| 67 | [ |
||
| 68 | 2 | 'landscape' => Module::t('block_slick_adaptive_orientation_landscape'), |
|
| 69 | 2 | 'portrait' => Module::t('block_slick_adaptive_orientation_portrait'), |
|
| 70 | ] |
||
| 71 | )], |
||
| 72 | ]], |
||
| 73 | ]], |
||
| 74 | ], |
||
| 75 | 'cfgs' => [ |
||
| 76 | // in progress |
||
| 77 | 2 | ['var' => 'cssBackground', 'label' => 'Bild via CSS darstellen', 'type' => self::TYPE_CHECKBOX], |
|
| 78 | 2 | ['var' => 'positionTop', 'label' => 'Position vertikal', 'type' => self::TYPE_TEXT, 'placeholder' => '50'], |
|
| 79 | 2 | ['var' => 'positionLeft', 'label' => 'Position horizontal', 'type' => self::TYPE_TEXT, 'placeholder' => '50'], |
|
| 80 | 2 | ['var' => 'sliderConfig', 'label' => 'Slider options', 'type' => self::TYPE_MULTIPLE_INPUTS, 'options' => [ |
|
| 81 | 2 | ['var' => 'option', 'label' => 'Option', 'type' => self::TYPE_TEXT], |
|
| 82 | 2 | ['var' => 'config', 'label' => 'Config', 'type' => self::TYPE_TEXT, 'options' => ['initValue' => 'true']], |
|
| 83 | ]], |
||
| 84 | ], |
||
| 85 | ]; |
||
| 86 | } |
||
| 87 | |||
| 88 | 2 | public function responsiveImages($parent) |
|
| 89 | { |
||
| 90 | 2 | $respImagesInput = $parent['responsive_images']; |
|
| 91 | 2 | $respImages = []; |
|
| 92 | 2 | foreach ($respImagesInput as $item) { |
|
| 93 | 2 | $respImages[] = [ |
|
| 94 | 2 | 'breakpoint' => isset($item['breakpoint']) ? $item['breakpoint'] : '0', |
|
| 95 | 2 | 'orientation' => isset($item['orientation']) ? $item['orientation'] : 'portrait', |
|
| 96 | 2 | 'image' => isset($item['image']) ? BlockHelper::imageUpload($item['image'], false, true) : null, |
|
| 97 | 2 | 'imageHD' => isset($item['image_hd']) ? BlockHelper::imageUpload($item['image_hd'], false, true) : null, |
|
| 98 | ]; |
||
| 99 | } |
||
| 100 | |||
| 101 | 2 | return $respImages; |
|
| 102 | } |
||
| 103 | |||
| 104 | 5 | public function images($image = null) |
|
| 105 | { |
||
| 106 | 5 | $imagesInput = $image != null ? $image : $this->getVarValue('images', []); |
|
| 107 | 5 | $images = []; |
|
| 108 | 5 | foreach ($imagesInput as $item) { |
|
| 109 | 1 | $images[] = [ |
|
| 110 | 1 | 'image' => isset($item['image']) ? BlockHelper::imageUpload($item['image'], false, true) : null, |
|
| 111 | 1 | 'alt' => isset($item['alt']) ? $item['alt'] : 'no-alt-text-set', |
|
| 112 | 1 | 'title' => isset($item['title']) ? $item['title'] : '', |
|
| 113 | 1 | 'link' => isset($item['link']) ? BlockHelper::linkObject($item['link']) : null, |
|
| 114 | 1 | 'isPublished' => isset($item['isPublished']) ? true : false, |
|
| 115 | 1 | 'responsive_images' => $this->responsiveImages($item), |
|
| 116 | |||
| 117 | ]; |
||
| 118 | } |
||
| 119 | |||
| 120 | 5 | return $images; |
|
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * {@inheritdoc} |
||
| 125 | */ |
||
| 126 | 4 | public function extraVars() |
|
| 127 | { |
||
| 128 | return [ |
||
| 129 | 4 | 'images' => $this->images(), |
|
| 130 | ]; |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * {@inheritdoc} |
||
| 135 | * |
||
| 136 | * @param {{extras.image}} |
||
| 137 | * @param {{vars.image}} |
||
| 138 | * @param {{vars.isPublished}} |
||
| 139 | * @param {{vars.link}} |
||
| 140 | * @param {{vars.title}} |
||
| 141 | */ |
||
| 142 | 2 | public function admin() |
|
| 143 | { |
||
| 144 | 2 | return 'Slider Admin View'; |
|
| 145 | } |
||
| 146 | } |
||
| 147 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: