Source of file DisplayLogicExtrasFormField.php
Size: 2,905 Bytes - Last Modified: 2021-12-23T10:57:31+00:00
/var/www/docs.ssmods.com/process/src/src/Extensions/DisplayLogicExtrasFormField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 | <?php namespace WebbuildersGroup\DisplayLogicExtras\Extensions; use UncleCheese\DisplayLogic\Extensions\DisplayLogic; use UncleCheese\DisplayLogic\Criteria; use SilverStripe\View\Requirements; class DisplayLogicExtrasFormField extends DisplayLogic { protected $display_logic_classes; protected $nestedLogic = []; /** * If the criteria evaluate true, the field should display * @param string $master The name of the master field * @return UncleCheese\DisplayLogic\Criteria */ public function displayIf($master) { $this->display_logic_classes = 'display-logic display-logic-hidden display-logic-display'; return parent::displayIf($master); } /** * If the criteria evaluate true, the field should hide. * The field will be hidden with CSS on page load, before the script loads. * @param string $master The name of the master field * @return UncleCheese\DisplayLogic\Criteria */ public function hideIf($master) { $this->display_logic_classes = 'display-logic display-logic-hide'; return parent::hideIf($master); } /** * Clears the display logic criteria * @return SilverStripe\Forms\FormField */ public function clearDisplayLogicCriteria() { //Reset the display logic criteria to an empty array $this->displayLogicCriteria = []; //Remove display logic classes $this->owner->removeExtraClass('display-logic'); $this->owner->removeExtraClass('display-logic-hide'); $this->owner->removeExtraClass('display-logic-hidden'); $this->owner->removeExtraClass('display-logic-display'); //Return the owner return $this->owner; } /** * Loads the dependencies and renders the JavaScript-readable logic to the form HTML * @return string */ public function DisplayLogic() { $parentResult = parent::DisplayLogic(); if ($this->getDisplayLogicCriteria()) { Requirements::javascript('unclecheese/display-logic: client/dist/js/bundle.js'); Requirements::javascript('webbuilders-group/silverstripe-display-logic-extras: client/dist/DisplayLogicExtras.js'); } return $parentResult; } /** * @param Criteria $criteria * @return Criteria */ public function setDisplayLogicCriteria(Criteria $criteria) { $this->owner->setField('displayLogic', $criteria); return $criteria; } /** * @param Criteria $criteria * @return Criteria|null */ public function getDisplayLogicCriteria() { return $this->owner->getField('displayLogic'); } /** * Gets the css classes needed for display logic * @return string */ public function getDisplayLogicClasses() { return $this->display_logic_classes; } } |