/** * Update SiteConfig with the top level fields * * @param FieldSet $fields * @return void */ function updateCMSFields(&$fields) { $fields->addFieldsToTab("Root.Access", array(new HeaderField(_t('SiteConfigCMSWorkflow.PUBLISHAPPROVEDHEADER', "Who can publish requests inside the CMS?"), 2), $actionTypeField = new OptionsetField("CanPublishType", "", array("LoggedInUsers" => _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS"), "OnlyTheseUsers" => _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)")), "OnlyTheseUsers"), $actionerGroupsField = new TreeMultiselectField("PublisherGroups", "Publisher groups"))); if (!Permission::check('ADMIN')) { $fields->replaceField('CanPublishType', $actionTypeField->performReadonlyTransformation()); $fields->replaceField('PublisherGroups', $actionerGroupsField->performReadonlyTransformation()); } }
/** * Implement permissions for TwoStep * * @return void */ public function updateCMSFields(&$fields) { $fields->addFieldsToTab("Root.Access", array(new HeaderField(_t('SiteTreeCMSWorkflow.PUBLISHHEADER', "Who can publish this inside the CMS?"), 2), $publishTypeField = new OptionsetField("CanPublishType", "", array("Inherit" => _t('SiteTree.EDITINHERIT', "Inherit from parent page"), "LoggedInUsers" => _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS"), "OnlyTheseUsers" => _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)")), "Inherit"), $publisherGroupsField = new TreeMultiselectField("PublisherGroups", $this->owner->fieldLabel('PublisherGroups')))); if (!$this->owner->canPublish() || !Permission::check('SITETREE_GRANT_ACCESS')) { $fields->replaceField('CanPublishType', $publishTypeField->performReadonlyTransformation()); $fields->replaceField('PublisherGroups', $publisherGroupsField->performReadonlyTransformation()); } }
public function testReadonlyField() { $sourceArray = array(0 => 'No', 1 => 'Yes'); $field = new OptionsetField('FeelingOk', 'are you feeling ok?', $sourceArray, 1); $field->setEmptyString('(Select one)'); $field->setValue(1); $readonlyField = $field->performReadonlyTransformation(); preg_match('/Yes/', $field->Field(), $matches); $this->assertEquals($matches[0], 'Yes'); }
public function performReadonlyTransformation() { if ($this->fieldType == 'CheckboxSetField') { return CheckboxSetField::performReadonlyTransformation(); } return parent::performReadonlyTransformation(); }
/** * Return a readonly version of this field. Keeps the composition but returns readonly * versions of all the child {@link FormField} objects. * * @return CompositeField */ public function performReadonlyTransformation() { parent::performReadonlyTransformation(); $newChildren = new FieldList(); $clone = clone $this; if ($clone->getChildren()) { foreach ($clone->getChildren() as $idx => $child) { if (is_object($child)) { $child = $child->transform(new ReadonlyTransformation()); } $newChildren->push($child, $idx); } } $clone->children = $newChildren; $clone->readonly = true; $clone->addExtraClass($this->extraClass()); $clone->setDescription($this->getDescription()); return $clone; }