<?php
namespace Website\Widgets\FormElements; use Moto; class SelectWidget extends AbstractFormInputWidget { protected $_name = 'form_elements.select'; protected static $_defaultProperties = array( 'name' => '', 'options' => array(), 'validation' => array( 'required' => false ), 'spacing' => array( 'top' => 'auto', 'right' => 'auto', 'bottom' => 'small', 'left' => 'auto', ), ); public function getTemplatePath($preset = null) { return '@websiteWidgets/form_elements/templates/select.twig.html'; } public function getSelectedOptionValue() { foreach ($this->properties['options'] as $option) { if ($option['selected']) { $value = $option['value']; break; } } return isset($value) ? $value : ''; } public function getPreviewOptionLabel() { $emptyOption = ''; foreach ($this->properties['options'] as $option) { if ($option['selected']) { return $option['label']; } if (empty($option['value'])) { $emptyOption = $option['label']; } } return $emptyOption; } } 