Source of file ComponentFieldHolder.php
Size: 3,807 Bytes - Last Modified: 2021-12-23T10:05:09+00:00
/var/www/docs.ssmods.com/process/src/src/Composite/Model/ComponentFieldHolder.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 | <?php /** * Milkyway Multimedia * ComponentFieldHolder.php * * @package * @author Mellisa Hankins <mellisa.hankins@me.com> */ abstract class ComponentFieldHolder extends CompositeField { /** * @var mixed */ protected $subItemType; /** * @var string */ protected $activeItem; /** * @var boolean */ protected $firstActive = true; /** * @var string */ protected $appendType; /** * @var string */ protected $defaultTemplate; public function __construct($name, $children = null) { $this->name = $name; if ($children && $type = $this->subItemType) { $sub = []; foreach ($children as $child) { if ($child instanceof $type) { $sub[] = $child; } } } else { $sub = $children ? $children : FieldList::create(); } CompositeField::__construct($sub); } public function setActiveItem($item = null) { if ($item instanceof FormField) { $this->activeItem = $item->Name; } else { $this->activeItem = $item; } return $this; } public function getActiveItem() { return $this->activeItem; } public function activeAtStart($flag = false) { $this->firstActive = $flag; return $this; } public function makeFirstActive($force = false) { if (((!$this->activeItem && !$force) || $force) && $this->children && $this->children->exists()) { $this->activeItem = $this->children->first()->Name; } return $this; } public function ID() { $append = $this->appendType ? $this->appendType : str_replace('ComponentField', '', $this->class); if ($append) { return $this->form ? $this->form->FormName() . '_' . $this->name . '-' . $append : $this->name . '-' . $append; } else { return $this->form ? $this->form->FormName() . '_' . $this->name : $this->name; } } public function push(FormField $field) { parent::push($field); if ($field instanceof ComponentFieldHolder_Item) { $field->setHolder($this); } } public function insertBefore($field, $insertBefore) { parent::insertBefore($field, $insertBefore); if ($field instanceof ComponentFieldHolder_Item) { $field->setHolder($this); } $this->sequentialSet = null; } public function insertAfter($field, $insertAfter) { parent::insertBefore($field, $insertAfter); if ($field instanceof ComponentFieldHolder_Item) { $field->setHolder($this); } $this->sequentialSet = null; } public function getAttributes() { $attrs = [ 'class' => $this->extraClass(), 'id' => $this->ID(), ]; return array_merge($attrs, $this->attributes); } public function FieldHolder($properties = []) { return $this->Field($properties); } public function Field($properties = []) { if ($this->firstActive) { $this->makeFirstActive(); } return parent::Field($properties); } /** * Returns an array of templates to use for rendering {@link FieldH} * * @return array */ public function getTemplates() { $template = parent::getTemplates(); if ($default = $this->defaultTemplate) { $key = array_search('FormField', $template); if ($key !== false) { $default[$key] = $this->defaultTemplate; } } return $template; } } |