<?php
namespace Website\Widgets\Tabs; use Moto; class Widget extends Moto\System\Widgets\AbstractContainerWidget { protected $_name = 'tabs'; protected static $_defaultProperties = array( 'type' => 'horizontal', 'horizontal' => array( 'justifiedHeaders' => false, 'headersAlignment' => 'left', ), 'vertical' => array( 'position' => 'left', 'headerTextAlignment' => 'left', 'widthType' => 'responsive', 'fixedWidth' => '150px', 'responsiveWidth' => '20%', ), 'visible_on' => 'mobile-v', 'openByDefault' => [ 'index' => 0, 'id' => null, ], 'preset' => 'default', 'iconsAlignment' => 'left', 'animation' => '', 'spacing' => array( 'top' => 'auto', 'right' => 'auto', 'bottom' => 'auto', 'left' => 'auto', ), 'headingTag' => 'span', ); protected $_templateType = 'templates'; protected $_templatePath = '@websiteWidgets/tabs/templates/default.twig.html'; protected $_widgetId = true; public function init() { if (isset($this->properties['justifiedHeaders'])) { $this->_migrateProperties(); } parent::init(); } protected function _migrateProperties() { $this->properties['horizontal']['justifiedHeaders'] = $this->properties['justifiedHeaders']; $this->properties['horizontal']['headersAlignment'] = $this->properties['headersAlignment']; unset($this->properties['justifiedHeaders']); unset($this->properties['headersAlignment']); } public function getWrapperClasses() { $result = 'moto-widget-tabs__headers-wrapper_icon-' . $this->properties['iconsAlignment']; if ($this->properties['type'] === 'horizontal') { if ($this->properties['horizontal']['justifiedHeaders']) { $result .= ' moto-widget-tabs__headers-wrapper_headers-justified'; } else { $result .= ' moto-widget-tabs__headers-wrapper_headers-' . $this->properties['horizontal']['headersAlignment']; } } else { $result .= ' moto-widget-tabs__headers-wrapper_text-' . $this->properties['vertical']['headerTextAlignment']; } return $result; } public function getWrapperWidth() { return ($this->properties['type'] === 'vertical') ? $this->properties['vertical'][$this->properties['vertical']['widthType'] . 'Width'] : 'auto'; } public function getCssClasses() { $result = $this->getAlignClass(); $result .= ' ' . $this->getSpacing('classes'); $result .= ' ' . $this->getVisibleOn('classes'); $result .= ' ' . $this->getAnimationClasses(); $result .= ' moto-preset-' . $this->properties['preset']; $result .= ' moto-widget-tabs_type-' . $this->properties['type']; if ($this->properties['type'] === 'vertical') { $result .= ' moto-widget-tabs_type-vertical_' . $this->properties['vertical']['position']; } return $result; } public function isTabOpenedByDefault($widget) { $opened = $this->getPropertyValue('openByDefault.id'); if ($opened) { return ($opened === $widget->getWidgetId()); } return (array_search($widget, $this->children, true) === 0); } } 