Source of file TextCheckboxGroupField.php
Size: 1,997 Bytes - Last Modified: 2021-12-24T06:44:48+00:00
/var/www/docs.ssmods.com/process/src/src/Forms/TextCheckboxGroupField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | <?php namespace DNADesign\Elemental\Forms; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\CompositeField; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\TextField; class TextCheckboxGroupField extends CompositeField { protected $schemaComponent = 'TextCheckboxGroupField'; /** * Set the composite's title to that of the first child * * @param string|null $title */ public function __construct($title = null) { if (!$title) { $title = _t(__CLASS__ . '.Title', 'Title'); } $fields = [ TextField::create('Title', $title), CheckboxField::create('ShowTitle', _t(__CLASS__ . '.ShowTitleLabel', 'Displayed')) ]; parent::__construct($fields); $this->setTitle($title); } /** * Don't use the custom template for readonly states * * {@inheritDoc} */ public function performReadonlyTransformation() { $field = $this; if (!$this->readonly) { $field = parent::performReadonlyTransformation(); $field->setTemplate(CompositeField::class); $field->setTitle('Title'); $titleField = $field->fieldByName('Title'); if ($titleField) { $field->replaceField('Title', LiteralField::create( 'Title', $titleField->Value() )); } $displayedText = _t(__CLASS__ . '.DISPLAYED', 'Displayed'); $notDisplayedText = _t(__CLASS__ . '.NOT_DISPLAYED', 'Not displayed'); $showTitle = $field->fieldByName('ShowTitle'); if ($showTitle) { $field->replaceField('ShowTitle', LiteralField::create( 'ShowTitle', $showTitle->Value() === 'Yes' ? $displayedText : $notDisplayedText )->addExtraClass('show-title')); } } return $field; } } |