<?php
 namespace App\Form\Input; class Cloned_KeyValueTextSelector extends \Engine\Form\Input\ElementAbstract { protected $class = "clonedKeyValueTextSelector"; protected $selectValues = []; protected $showDefaultOption=null; protected $defaultOptionText = '-'; public function __construct($label=null, $name=null, $value=null) { parent::__construct($label, $name, $value); $this->settings['minItems'] = 1; $this->settings['operations'] = []; $this->settings['operations']['add'] = true; $this->settings['operations']['remove'] = true; $this->settings['operations']['default'] = false; $this->settings['forceSelect'] = true; $this->settings['showCounter'] = false; } public function setSelectValues(array $possibleSelectorValues) { $this->selectValues = (array) $possibleSelectorValues; } public function showDefaultOption($show=true) { $this->showDefaultOption=(bool)$show; return $this; } public function setDefaultOptionText($text) { $this->defaultOptionText = $text; return $this; } public function setElementLabels(array $labels) { foreach($labels as $name => $labelStr) { $this->settings['labels'][$name] = $labelStr; } } protected function getTemplateParams($templateClass = null, $parentElement = null) { $params = parent::getTemplateParams($templateClass, $parentElement); $params['selectValues'] = $this->selectValues; if ($this->showDefaultOption===false) { unset($params['selectValues']['']); } if ($this->showDefaultOption===true) { if (!$params['selectValues']['']) { $params['selectValues']= [''=>$this->defaultOptionText] + $params['selectValues']; } } return $params; } } 