Source of file InteractiveElementalExtension.php
Size: 1,847 Bytes - Last Modified: 2021-12-23T10:07:50+00:00
/var/www/docs.ssmods.com/process/src/src/Extension/InteractiveElementalExtension.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 | <?php namespace Symbiote\Interactives\Extension; use DNADesign\Elemental\Models\BaseElement; use SilverShop\HasOneField\HasOneButtonField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\LiteralField; use SilverStripe\ORM\DataExtension; class InteractiveElementalExtension extends DataExtension { private static $has_one = [ 'ContentElement' => BaseElement::class ]; private static $owns = [ 'ContentElement', ]; public function updateCMSFields(FieldList $fields) { if ($this->owner->ID) { $hasone = HasOneButtonField::create($this->owner, 'ContentElement'); $fields->addFieldToTab('Root.Content', $hasone); $fields->addFieldToTab("Root.Content", LiteralField::create('ElementInstruction', "If an element is chosen, you <b>must</b> add the \$Element keyword above to HTMLContent for it to be displayed." . "When adding a new element, ensure you select the type on the 'Settings' tab")); $content = $fields->dataFieldByName('HTMLContent'); if ($content) { $content->setRightTitle("If an element is chosen below, you must add the \$Element keyword above for it to be displayed"); } } } public function updateInteractiveData($data) { /** @var \Symbiote\Interactives\Model\Interactive $owner */ $owner = $this->owner; if ($owner->ContentElementID && isset($data['Content']) && strpos($data['Content'], '$Element') !== false) { $element = $owner->ContentElement(); $controller = $element->getController(); if ($controller) { $content = $controller->forTemplate(); $data['Content'] = str_replace('$Element', $content, $data['Content']); } } } } |