Source of file ListFilterCompositeField.php
Size: 3,621 Bytes - Last Modified: 2021-12-23T10:20:51+00:00
/var/www/docs.ssmods.com/process/src/code/form/ListFilterCompositeField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 | <?php class ListFilterCompositeField extends CompositeField { /** * @var ListFilterBase */ public $Filter = null; /** * @var string */ public $context = ''; /** * @var array */ public $filterConfig = array(); /** * @var boolean */ protected $hasRendered = false; /** * @config * @var array */ private static $fieldset_tagnames = array( 'legend' => 'fieldset', 'nolegend' => 'div' ); public function __construct(ListFilterBase $filter) { $this->Filter = $filter; // Inherit $Title and $Name variables $this->setTitle($filter->Title); $this->setName($filter->Name); // Select template to use based on class hierarchy $templateName = ''; $templateHolderName = ''; $classAncestry = array_reverse(ClassInfo::ancestry($this->Filter->class)); foreach ($classAncestry as $subClass) { if ($templateName === '' && SSViewer::hasTemplate($subClass)) { $templateName = $subClass; } if ($templateHolderName === '' && SSViewer::hasTemplate($subClass.'_holder')) { $templateHolderName = $subClass.'_holder'; } } $this->setTemplate($templateName); $this->setFieldHolderTemplate($templateHolderName); // Set children $filterFields = $filter->getFilterFieldsAll(); if ($filterFields === null) { throw new Exception($filter->class.'::getFilterFieldsAll() should not return null.'); } if ($filterFields) { $dataFields = $filterFields->dataFields(); if ($dataFields) { foreach ($filterFields->dataFields() as $field) { $fieldName = $field->getName(); $field->setName('FilterGroup_'.$filter->ID.'_'.$fieldName); $field->setAttribute('data-name', $fieldName); } } } parent::__construct($filterFields); } /** * Get legend for a <fieldset> * * @return string */ public function getLegend() { return $this->Title(); } /** * Get the tag name to use for the <fieldset> wrapper. * * @return string */ public function getFieldsetTagName() { $fieldsetTagNames = $this->config()->fieldset_tagnames; if ($this->getLegend()) { return $fieldsetTagNames['legend']; } return $fieldsetTagNames['nolegend']; } /** * {@inheritdoc} */ public function getAttributes() { $result = parent::getAttributes(); if ($this->context === 'FieldHolder') { unset($result['id']); $result['class'] = 'js-listfilter-filter'; $result['data-fieldgroup-id'] = $this->Filter->ID; $result['data-fieldgroup-callback'] = $this->Filter->getJavascriptCallback(); $filterConfig = $this->filterConfig; if ($filterConfig) { if (is_array($filterConfig)) { $filterConfig = json_encode($filterConfig); } $result['data-fieldgroup-config'] = $filterConfig; } } return $result; } /** * Check if the filter has been rendered already or not * * @var boolean */ public function getHasRendered() { return $this->hasRendered; } /** * {@inheritdoc} */ public function FieldHolder($properties = array()) { $this->hasRendered = true; $this->context = __FUNCTION__; $this->failover = $this->Filter; $result = parent::FieldHolder($properties); $this->failover = null; return $result; } /** * {@inheritdoc} */ public function Field($properties = array()) { $this->hasRendered = true; $this->context = __FUNCTION__; $this->failover = $this->Filter; $result = parent::Field($properties); $this->failover = null; return $result; } public function forTemplate() { $this->hasRendered = true; $this->failover = $this->Filter; $result = parent::forTemplate(); $this->failover = null; return $result; } } |