Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Ensure all fields are available for updateCMSFields(). #1089

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions code/Model/EditableFormField/EditableCheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class EditableCheckbox extends EditableFormField
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->replaceField('Default', CheckboxField::create(
"CheckedDefault",
_t('SilverStripe\\UserForms\\Model\\EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?')
));

return $fields;
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->replaceField('Default', CheckboxField::create(
"CheckedDefault",
_t('SilverStripe\\UserForms\\Model\\EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?')
));
});

return parent::getCMSFields();
}

public function getFormField()
Expand Down
45 changes: 23 additions & 22 deletions code/Model/EditableFormField/EditableCountryDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\i18n\i18n;
use SilverStripe\UserForms\Model\EditableCustomRule;
Expand Down Expand Up @@ -35,28 +36,28 @@ class EditableCountryDropdownField extends EditableFormField
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->removeByName('Default');
$fields->addFieldToTab(
'Root.Main',
DropdownField::create('Default', _t(__CLASS__ . '.DEFAULT', 'Default value'))
->setSource(i18n::getData()->getCountries())
->setHasEmptyDefault(true)
->setEmptyString('---')
);

$fields->addFieldToTab(
'Root.Main',
CheckboxField::create('UseEmptyString', _t(__CLASS__ . '.USE_EMPTY_STRING', 'Set default empty string'))
);

$fields->addFieldToTab(
'Root.Main',
TextField::create('EmptyString', _t(__CLASS__ . '.EMPTY_STRING', 'Empty String'))
);

return $fields;
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName('Default');
$fields->addFieldToTab(
'Root.Main',
DropdownField::create('Default', _t(__CLASS__ . '.DEFAULT', 'Default value'))
->setSource(i18n::getData()->getCountries())
->setHasEmptyDefault(true)
->setEmptyString('---')
);

$fields->addFieldToTab(
'Root.Main',
CheckboxField::create('UseEmptyString', _t(__CLASS__ . '.USE_EMPTY_STRING', 'Set default empty string'))
);

$fields->addFieldToTab(
'Root.Main',
TextField::create('EmptyString', _t(__CLASS__ . '.EMPTY_STRING', 'Empty String'))
);
});

return parent::getCMSFields();
}

public function getFormField()
Expand Down
28 changes: 14 additions & 14 deletions code/Model/EditableFormField/EditableDropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ class EditableDropdown extends EditableMultipleOptionField
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->addFieldToTab(
'Root.Main',
CheckboxField::create('UseEmptyString')
->setTitle('Set default empty string')
);

$fields->addFieldToTab(
'Root.Main',
CheckboxField::create('UseEmptyString')
->setTitle('Set default empty string')
);
$fields->addFieldToTab(
'Root.Main',
TextField::create('EmptyString')
->setTitle('Empty String')
);

$fields->addFieldToTab(
'Root.Main',
TextField::create('EmptyString')
->setTitle('Empty String')
);
$fields->removeByName('Default');
});

$fields->removeByName('Default');

return $fields;
return parent::getCMSFields();
}

/**
Expand Down
9 changes: 6 additions & 3 deletions code/Model/EditableFormField/EditableFieldGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\UserForms\Model\EditableFormField;

use SilverStripe\Core\Convert;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\LabelField;
use SilverStripe\UserForms\FormField\UserFormsGroupField;
use SilverStripe\UserForms\Model\EditableFormField;
Expand Down Expand Up @@ -46,9 +47,11 @@ class EditableFieldGroup extends EditableFormField

public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->removeByName(['MergeField', 'Default', 'Validation', 'DisplayRules']);
return $fields;
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName(['MergeField', 'Default', 'Validation', 'DisplayRules']);
});

return parent::getCMSFields();
}

public function getCMSTitle()
Expand Down
9 changes: 6 additions & 3 deletions code/Model/EditableFormField/EditableFieldGroupEnd.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\UserForms\Model\EditableFormField;

use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\LabelField;
use SilverStripe\Security\Group;
Expand Down Expand Up @@ -50,9 +51,11 @@ public function getCMSTitle()

public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->removeByName(['MergeField', 'Default', 'Validation', 'DisplayRules']);
return $fields;
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName(['MergeField', 'Default', 'Validation', 'DisplayRules']);
});

return parent::getCMSFields();
}

public function getInlineClassnameField($column, $fieldClasses)
Expand Down
64 changes: 32 additions & 32 deletions code/Model/EditableFormField/EditableFileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,42 +141,42 @@ private static function getNonInheritedViewType(File $file)
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();

$treeView = TreeDropdownField::create(
'FolderID',
_t(__CLASS__.'.SELECTUPLOADFOLDER', 'Select upload folder'),
Folder::class
);
$treeView->setDescription(static::getFolderPermissionString($this->Folder()));
$fields->addFieldToTab(
'Root.Main',
$treeView
);
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$treeView = TreeDropdownField::create(
'FolderID',
_t(__CLASS__.'.SELECTUPLOADFOLDER', 'Select upload folder'),
Folder::class
);
$treeView->setDescription(static::getFolderPermissionString($this->Folder()));
$fields->addFieldToTab(
'Root.Main',
$treeView
);

// Warn the user if the folder targeted by this field is not restricted
if ($this->FolderID && !$this->Folder()->hasRestrictedAccess()) {
$fields->addFieldToTab("Root.Main", LiteralField::create(
'FileUploadWarning',
'<p class="alert alert-warning">' . _t(
'SilverStripe\\UserForms\\Model\\UserDefinedForm.UnrestrictedFileUploadWarning',
'Access to the current upload folder "{path}" is not restricted. Uploaded files will be publicly accessible if the exact URL is known.',
['path' => Convert::raw2att($this->Folder()->Filename)]
)
. '</p>'
), 'Type');
}
// Warn the user if the folder targeted by this field is not restricted
if ($this->FolderID && !$this->Folder()->hasRestrictedAccess()) {
$fields->addFieldToTab("Root.Main", LiteralField::create(
'FileUploadWarning',
'<p class="alert alert-warning">' . _t(
'SilverStripe\\UserForms\\Model\\UserDefinedForm.UnrestrictedFileUploadWarning',
'Access to the current upload folder "{path}" is not restricted. Uploaded files will be publicly accessible if the exact URL is known.',
['path' => Convert::raw2att($this->Folder()->Filename)]
)
. '</p>'
), 'Type');
}

$fields->addFieldToTab(
'Root.Main',
NumericField::create('MaxFileSizeMB')
->setTitle('Max File Size MB')
->setDescription("Note: Maximum php allowed size is {$this->getPHPMaxFileSizeMB()} MB")
);
$fields->addFieldToTab(
'Root.Main',
NumericField::create('MaxFileSizeMB')
->setTitle('Max File Size MB')
->setDescription("Note: Maximum php allowed size is {$this->getPHPMaxFileSizeMB()} MB")
);

$fields->removeByName('Default');
$fields->removeByName('Default');
});

return $fields;
return parent::getCMSFields();
}

/**
Expand Down
52 changes: 26 additions & 26 deletions code/Model/EditableFormField/EditableFormHeading.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,32 @@ class EditableFormHeading extends EditableFormField
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->removeByName(['Default', 'Validation', 'RightTitle']);

$levels = [
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6'
];

$fields->addFieldsToTab('Root.Main', [
DropdownField::create(
'Level',
_t(__CLASS__.'.LEVEL', 'Select Heading Level'),
$levels
),
CheckboxField::create(
'HideFromReports',
_t('SilverStripe\\UserForms\\Model\\EditableFormField\\EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?')
)
]);

return $fields;
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName(['Default', 'Validation', 'RightTitle']);

$levels = [
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6'
];

$fields->addFieldsToTab('Root.Main', [
DropdownField::create(
'Level',
_t(__CLASS__.'.LEVEL', 'Select Heading Level'),
$levels
),
CheckboxField::create(
'HideFromReports',
_t('SilverStripe\\UserForms\\Model\\EditableFormField\\EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?')
)
]);
});

return parent::getCMSFields();
}

public function getFormField()
Expand Down
8 changes: 4 additions & 4 deletions code/Model/EditableFormField/EditableFormStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class EditableFormStep extends EditableFormField
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName(['MergeField', 'Default', 'Validation', 'RightTitle']);
});

$fields->removeByName(['MergeField', 'Default', 'Validation', 'RightTitle']);

return $fields;
return parent::getCMSFields();
}

/**
Expand Down
38 changes: 19 additions & 19 deletions code/Model/EditableFormField/EditableLiteralField.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,25 @@ public function setContent($content)
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->removeByName(['Default', 'Validation', 'RightTitle']);

$fields->addFieldsToTab('Root.Main', [
HTMLEditorField::create('Content', _t(__CLASS__.'.CONTENT', 'HTML'))
->setRows(4)
->setColumns(20),
CheckboxField::create(
'HideFromReports',
_t(__CLASS__.'.HIDEFROMREPORT', 'Hide from reports?')
),
CheckboxField::create(
'HideLabel',
_t(__CLASS__.'.HIDELABEL', "Hide 'Title' label on frontend?")
)
]);

return $fields;
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName(['Default', 'Validation', 'RightTitle']);

$fields->addFieldsToTab('Root.Main', [
HTMLEditorField::create('Content', _t(__CLASS__.'.CONTENT', 'HTML'))
->setRows(4)
->setColumns(20),
CheckboxField::create(
'HideFromReports',
_t(__CLASS__.'.HIDEFROMREPORT', 'Hide from reports?')
),
CheckboxField::create(
'HideLabel',
_t(__CLASS__.'.HIDELABEL', "Hide 'Title' label on frontend?")
)
]);
});

return parent::getCMSFields();
}

public function getFormField()
Expand Down
32 changes: 16 additions & 16 deletions code/Model/EditableFormField/EditableMemberListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ class EditableMemberListField extends EditableFormField
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->removeByName('Default');
$fields->removeByName('Validation');

/** @skipUpgrade */
$fields->addFieldToTab(
'Root.Main',
DropdownField::create(
'GroupID',
_t('SilverStripe\\UserForms\\Model\\EditableFormField.GROUP', 'Group'),
Group::get()->map()
)->setEmptyString(' ')
);

return $fields;
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName('Default');
$fields->removeByName('Validation');

/** @skipUpgrade */
$fields->addFieldToTab(
'Root.Main',
DropdownField::create(
'GroupID',
_t('SilverStripe\\UserForms\\Model\\EditableFormField.GROUP', 'Group'),
Group::get()->map()
)->setEmptyString(' ')
);
});

return parent::getCMSFields();
}

public function getFormField()
Expand Down
Loading