/** * This function sets default values to * options for further usage */ protected function normalizeOptions() { $this->options['data'] = ArrayHelper::getValue($this->options, 'data', []); $this->options['style'] = ArrayHelper::getValue($this->options, 'style', ''); $this->options['data']['hash'] = $this->hash ?: ArrayHelper::getValue($this->options['data'], 'hash', null); $this->hash = $this->hash ?: ArrayHelper::getValue($this->options['data'], 'hash', null); if ($this->background) { $this->options['style'] = SwiperCssHelper::mergeStyleAndBackground($this->background, ArrayHelper::getValue($this->options, 'style', '')); } elseif (ArrayHelper::getValue($this->options, 'style')) { $this->background = SwiperCssHelper::getBackgroundUrl($this->options['style']); } $this->options = array_filter($this->options); $this->options['data'] = array_filter($this->options['data']); }
/** * This function sets default values to options of widget * such as [[id]] and [[class]] * * @see \romkaChev\yii2\swiper\Swiper::$containerOptions * @see \romkaChev\yii2\swiper\Swiper::$wrapperOptions * @see \romkaChev\yii2\swiper\Swiper::$paginationOptions * @see \romkaChev\yii2\swiper\Swiper::$scrollbarOptions * @see \romkaChev\yii2\swiper\Swiper::$nextButtonOptions * @see \romkaChev\yii2\swiper\Swiper::$prevButtonOptions * @see \romkaChev\yii2\swiper\Swiper::$parallaxOptions * @see \romkaChev\yii2\swiper\Swiper::$itemOptions */ protected function normalizeOptions() { $id = ArrayHelper::getValue($this->containerOptions, 'id', $this->getId()); //@formatter:off $this->itemOptions['options'] = ArrayHelper::getValue($this->itemOptions, 'options', []); $this->itemOptions['options']['data'] = ArrayHelper::getValue($this->itemOptions['options'], 'data', []); $this->itemOptions['options']['class'] = trim(ArrayHelper::getValue($this->itemOptions['options'], 'class', '') . ' swiper-slide', ' '); $this->containerOptions['id'] = $id; $this->containerOptions['class'] = trim(ArrayHelper::getValue($this->containerOptions, 'class', '') . ' swiper-container', ' '); $this->wrapperOptions['id'] = ArrayHelper::getValue($this->wrapperOptions, 'id', "{$id}-wrapper"); $this->wrapperOptions['class'] = trim(ArrayHelper::getValue($this->wrapperOptions, 'class', '') . ' swiper-wrapper', ' '); $this->paginationOptions['id'] = ArrayHelper::getValue($this->paginationOptions, 'id', "{$id}-pagination"); $this->paginationOptions['class'] = trim(ArrayHelper::getValue($this->paginationOptions, 'class', '') . ' swiper-pagination', ' '); $this->scrollbarOptions['id'] = ArrayHelper::getValue($this->scrollbarOptions, 'id', "{$id}-scrollbar"); $this->scrollbarOptions['class'] = trim(ArrayHelper::getValue($this->scrollbarOptions, 'class', '') . ' swiper-scrollbar', ' '); $this->nextButtonOptions['id'] = ArrayHelper::getValue($this->nextButtonOptions, 'id', "{$id}-button-next"); $this->nextButtonOptions['class'] = trim(ArrayHelper::getValue($this->nextButtonOptions, 'class', '') . ' swiper-button-next', ' '); $this->prevButtonOptions['id'] = ArrayHelper::getValue($this->prevButtonOptions, 'id', "{$id}-button-prev"); $this->prevButtonOptions['class'] = trim(ArrayHelper::getValue($this->prevButtonOptions, 'class', '') . ' swiper-button-prev', ' '); $this->parallaxOptions['id'] = ArrayHelper::getValue($this->parallaxOptions, 'id', "{$id}-parallax"); $this->parallaxOptions['class'] = trim(ArrayHelper::getValue($this->parallaxOptions, 'class', '') . ' parallax-bg', ' '); $this->parallaxOptions['data'] = ArrayHelper::getValue($this->parallaxOptions, 'data', []); /** * Parallax options, specified via shorthands, have more priority * than directly specified options */ $this->parallaxOptions['data']['swiper-parallax'] = ArrayHelper::getValue($this->parallaxOptions, self::PARALLAX_TRANSITION, ArrayHelper::getValue($this->parallaxOptions['data'], 'swiper-parallax', null)); $this->parallaxOptions['data']['swiper-parallax-x'] = ArrayHelper::getValue($this->parallaxOptions, self::PARALLAX_TRANSITION_X, ArrayHelper::getValue($this->parallaxOptions['data'], 'swiper-parallax-x', null)); $this->parallaxOptions['data']['swiper-parallax-y'] = ArrayHelper::getValue($this->parallaxOptions, self::PARALLAX_TRANSITION_Y, ArrayHelper::getValue($this->parallaxOptions['data'], 'swiper-parallax-y', null)); $this->parallaxOptions['data']['swiper-parallax-duration'] = ArrayHelper::getValue($this->parallaxOptions, self::PARALLAX_DURATION, ArrayHelper::getValue($this->parallaxOptions['data'], 'swiper-parallax-duration', null)); $this->parallaxOptions[self::PARALLAX_TRANSITION] = ArrayHelper::getValue($this->parallaxOptions, self::PARALLAX_TRANSITION, ArrayHelper::getValue($this->parallaxOptions['data'], 'swiper-parallax', null)); $this->parallaxOptions[self::PARALLAX_TRANSITION_X] = ArrayHelper::getValue($this->parallaxOptions, self::PARALLAX_TRANSITION_X, ArrayHelper::getValue($this->parallaxOptions['data'], 'swiper-parallax-x', null)); $this->parallaxOptions[self::PARALLAX_TRANSITION_Y] = ArrayHelper::getValue($this->parallaxOptions, self::PARALLAX_TRANSITION_Y, ArrayHelper::getValue($this->parallaxOptions['data'], 'swiper-parallax-y', null)); $this->parallaxOptions[self::PARALLAX_DURATION] = ArrayHelper::getValue($this->parallaxOptions, self::PARALLAX_DURATION, ArrayHelper::getValue($this->parallaxOptions['data'], 'swiper-parallax-duration', null)); $this->parallaxOptions['data'] = array_filter($this->parallaxOptions['data']); //@formatter:on if (ArrayHelper::getValue($this->parallaxOptions, self::PARALLAX_BACKGROUND)) { $this->parallaxOptions['style'] = SwiperCssHelper::mergeStyleAndBackground(ArrayHelper::getValue($this->parallaxOptions, self::PARALLAX_BACKGROUND, ''), ArrayHelper::getValue($this->parallaxOptions, 'style', '')); } elseif (ArrayHelper::getValue($this->parallaxOptions, 'style')) { $this->parallaxOptions[self::PARALLAX_BACKGROUND] = SwiperCssHelper::getBackgroundUrl($this->parallaxOptions['style']); } }