Source of file MultiValueListField.php
Size: 2,035 Bytes - Last Modified: 2021-12-23T10:33:21+00:00
/var/www/docs.ssmods.com/process/src/src/Fields/MultiValueListField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 | <?php namespace Symbiote\MultiValueField\Fields; use Symbiote\MultiValueField\ORM\FieldType\MultiValueField; use SilverStripe\CMS\Controllers\ContentController; use SilverStripe\Control\Controller; use SilverStripe\View\HTML; use SilverStripe\View\Requirements; use SilverStripe\Core\Convert; /** * A multivalued field that uses a multi choice select box for selecting the value * * @author Marcus Nyeholt <marcus@symbiote.com.au> */ class MultiValueListField extends MultiValueTextField { protected $source; public function __construct($name, $title = null, $source = [], $value = null) { parent::__construct($name, ($title === null) ? $name : $title, $value); $this->source = $source; } public function Field($properties = []) { if (Controller::curr() instanceof ContentController) { Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.js'); } Requirements::javascript('symbiote/silverstripe-multivaluefield: client/javascript/multivaluefield.js'); Requirements::css('symbiote/silverstripe-multivaluefield: client/css/multivaluefield.css'); $name = $this->name.'[]'; $options = ''; if (!$this->value) { $this->value = []; } foreach ($this->source as $index => $title) { $attrs = ['value' => $index]; if (in_array($index, $this->value)) { $attrs['selected'] = 'selected'; } $options .= HTML::createTag('option', $attrs, Convert::raw2xml($title)); } $attrs = [ 'class' => 'mventryfield mvlistbox '.($this->extraClass() ? $this->extraClass() : ''), 'id' => $this->id(), 'name' => $name, 'tabindex' => $this->getAttribute('tabindex'), 'multiple' => 'multiple', ]; if ($this->disabled) { $attrs['disabled'] = 'disabled'; } return HTML::createTag('select', $attrs, $options); } } |