<?php
namespace Website\Widgets\FormElements; use Moto; class InputWidget extends AbstractFormInputWidget { protected $_name = 'form_elements.input'; protected static $_defaultProperties = array( 'name' => '', 'placeholder' => '', 'type' => 'text', 'dateMailFormat' => 'Y-m-d', 'icon' => null, 'validation' => array( 'required' => false ), 'spacing' => array( 'top' => 'auto', 'right' => 'auto', 'bottom' => 'small', 'left' => 'auto', ), ); public function getTemplatePath($preset = null) { return '@websiteWidgets/form_elements/templates/input.twig.html'; } public function getValidationRules() { $rules = parent::getValidationRules(); if (is_array($rules)) { if ($this->properties['type'] === 'date') { unset($rules['min'], $rules['max'], $rules['minlength'], $rules['maxlength']); } elseif ($this->properties['type'] === 'number') { unset($rules['minlength'], $rules['maxlength']); } else { unset($rules['min'], $rules['max']); } } return $rules; } public function getFieldValue() { if ($this->getFieldType() === 'date') { try { $date = date_create($this->_fieldValue); if (!$date) { return null; } return $date->format($this->getPropertyValue('dateMailFormat')); } catch (\Exception $e) { return null; } } return parent::getFieldValue(); } } 