mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FIX Update CMS fields now that they're being scaffolded (#1315)
This commit is contained in:
parent
01dcf8ab1c
commit
8037b0fbe1
@ -49,6 +49,12 @@ class UserFormFieldEditorExtension extends DataExtension
|
|||||||
'Fields'
|
'Fields'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private static array $scaffold_cms_fields_settings = [
|
||||||
|
'ignoreRelations' => [
|
||||||
|
'Fields',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the field editor to the page.
|
* Adds the field editor to the page.
|
||||||
*
|
*
|
||||||
|
@ -15,10 +15,14 @@ use SilverStripe\Forms\DropdownField;
|
|||||||
use SilverStripe\Forms\FieldGroup;
|
use SilverStripe\Forms\FieldGroup;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\Form;
|
use SilverStripe\Forms\Form;
|
||||||
|
use SilverStripe\Forms\FormField;
|
||||||
use SilverStripe\Forms\GridField\GridField;
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
|
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
|
||||||
use SilverStripe\Forms\GridField\GridFieldButtonRow;
|
use SilverStripe\Forms\GridField\GridFieldButtonRow;
|
||||||
use SilverStripe\Forms\GridField\GridFieldConfig;
|
use SilverStripe\Forms\GridField\GridFieldConfig;
|
||||||
|
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
||||||
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
|
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
|
||||||
|
use SilverStripe\Forms\GridField\GridFieldDetailForm;
|
||||||
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
|
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
|
||||||
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
|
||||||
use SilverStripe\Forms\LiteralField;
|
use SilverStripe\Forms\LiteralField;
|
||||||
@ -163,6 +167,46 @@ class EmailRecipient extends DataObject
|
|||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scaffoldFormFieldForHasMany(
|
||||||
|
string $relationName,
|
||||||
|
?string $fieldTitle,
|
||||||
|
DataObject $ownerRecord,
|
||||||
|
bool &$includeInOwnTab
|
||||||
|
): FormField {
|
||||||
|
$includeInOwnTab = true;
|
||||||
|
return $this->scaffoldFormFieldForManyRelation($relationName, $fieldTitle, $ownerRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scaffoldFormFieldForManyMany(
|
||||||
|
string $relationName,
|
||||||
|
?string $fieldTitle,
|
||||||
|
DataObject $ownerRecord,
|
||||||
|
bool &$includeInOwnTab
|
||||||
|
): FormField {
|
||||||
|
$includeInOwnTab = true;
|
||||||
|
return $this->scaffoldFormFieldForManyRelation($relationName, $fieldTitle, $ownerRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function scaffoldFormFieldForManyRelation(
|
||||||
|
string $relationName,
|
||||||
|
?string $fieldTitle,
|
||||||
|
DataObject $ownerRecord
|
||||||
|
): FormField {
|
||||||
|
$emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10);
|
||||||
|
$emailRecipientsConfig->getComponentByType(GridFieldAddNewButton::class)
|
||||||
|
->setButtonName(
|
||||||
|
_t(UserDefinedForm::class . '.ADDEMAILRECIPIENT', 'Add Email Recipient')
|
||||||
|
);
|
||||||
|
$emailRecipientsConfig->getComponentByType(GridFieldDetailForm::class)
|
||||||
|
->setItemRequestClass(UserFormRecipientItemRequest::class);
|
||||||
|
return GridField::create(
|
||||||
|
$relationName,
|
||||||
|
$fieldTitle,
|
||||||
|
$ownerRecord->$relationName(),
|
||||||
|
$emailRecipientsConfig
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get instance of UserForm when editing in getCMSFields
|
* Get instance of UserForm when editing in getCMSFields
|
||||||
*
|
*
|
||||||
|
@ -3,15 +3,12 @@
|
|||||||
namespace SilverStripe\UserForms;
|
namespace SilverStripe\UserForms;
|
||||||
|
|
||||||
use Colymba\BulkManager\BulkManager;
|
use Colymba\BulkManager\BulkManager;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
|
||||||
use SilverStripe\Forms\CheckboxField;
|
use SilverStripe\Forms\CheckboxField;
|
||||||
use SilverStripe\Forms\CompositeField;
|
use SilverStripe\Forms\CompositeField;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\GridField\GridField;
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
|
|
||||||
use SilverStripe\Forms\GridField\GridFieldButtonRow;
|
use SilverStripe\Forms\GridField\GridFieldButtonRow;
|
||||||
use SilverStripe\Forms\GridField\GridFieldConfig;
|
use SilverStripe\Forms\GridField\GridFieldConfig;
|
||||||
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
|
|
||||||
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
||||||
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
|
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
|
||||||
use SilverStripe\Forms\GridField\GridFieldDetailForm;
|
use SilverStripe\Forms\GridField\GridFieldDetailForm;
|
||||||
@ -32,7 +29,6 @@ use SilverStripe\UserForms\Extension\UserFormFieldEditorExtension;
|
|||||||
use SilverStripe\UserForms\Extension\UserFormValidator;
|
use SilverStripe\UserForms\Extension\UserFormValidator;
|
||||||
use SilverStripe\UserForms\Form\UserFormsGridFieldFilterHeader;
|
use SilverStripe\UserForms\Form\UserFormsGridFieldFilterHeader;
|
||||||
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
||||||
use SilverStripe\UserForms\Model\Recipient\UserFormRecipientItemRequest;
|
|
||||||
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
|
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField;
|
use SilverStripe\UserForms\Model\EditableFormField;
|
||||||
use SilverStripe\View\Requirements;
|
use SilverStripe\View\Requirements;
|
||||||
@ -117,8 +113,8 @@ trait UserForm
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private static $has_many = [
|
private static $has_many = [
|
||||||
|
'EmailRecipients' => EmailRecipient::class,
|
||||||
'Submissions' => SubmittedForm::class,
|
'Submissions' => SubmittedForm::class,
|
||||||
'EmailRecipients' => EmailRecipient::class
|
|
||||||
];
|
];
|
||||||
|
|
||||||
private static $cascade_deletes = [
|
private static $cascade_deletes = [
|
||||||
@ -135,6 +131,17 @@ trait UserForm
|
|||||||
'ErrorContainerID' => 'Text'
|
'ErrorContainerID' => 'Text'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private static array $scaffold_cms_fields_settings = [
|
||||||
|
'ignoreFields' => [
|
||||||
|
'OnCompleteMessageLabel',
|
||||||
|
'OnCompleteMessage',
|
||||||
|
'DisableSaveSubmissions',
|
||||||
|
],
|
||||||
|
'ignoreRelations' => [
|
||||||
|
'Submissions',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error container selector which matches the element for grouped messages
|
* Error container selector which matches the element for grouped messages
|
||||||
*
|
*
|
||||||
@ -183,72 +190,42 @@ trait UserForm
|
|||||||
{
|
{
|
||||||
Requirements::css('silverstripe/userforms:client/dist/styles/userforms-cms.css');
|
Requirements::css('silverstripe/userforms:client/dist/styles/userforms-cms.css');
|
||||||
|
|
||||||
$this->beforeUpdateCMSFields(function ($fields) {
|
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
||||||
|
$fields->findTab('Root.EmailRecipients')
|
||||||
|
?->setName('Recipients')
|
||||||
|
?->setTitle(_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.RECIPIENTS', 'Recipients'));
|
||||||
|
$fields->dataFieldByName('EmailRecipients')?->setTitle('');
|
||||||
|
|
||||||
// remove
|
// Configuration options
|
||||||
$fields->removeByName([
|
|
||||||
'OnCompleteMessageLabel',
|
|
||||||
'OnCompleteMessage',
|
|
||||||
'Fields',
|
|
||||||
'EmailRecipients'
|
|
||||||
]);
|
|
||||||
|
|
||||||
// define tabs
|
|
||||||
$fields->findOrMakeTab('Root.FormOptions')->setTitle(_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.CONFIGURATION', 'Configuration'));
|
$fields->findOrMakeTab('Root.FormOptions')->setTitle(_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.CONFIGURATION', 'Configuration'));
|
||||||
$fields->findOrMakeTab('Root.Recipients')->setTitle(_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.RECIPIENTS', 'Recipients'));
|
$fields->addFieldsToTab('Root.FormOptions', [
|
||||||
|
// text to show on complete
|
||||||
|
CompositeField::create(
|
||||||
// text to show on complete
|
$label = LabelField::create(
|
||||||
$onCompleteFieldSet = CompositeField::create(
|
'OnCompleteMessageLabel',
|
||||||
$label = LabelField::create(
|
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')
|
||||||
'OnCompleteMessageLabel',
|
),
|
||||||
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.ONCOMPLETELABEL', 'Show on completion')
|
$editor = HTMLEditorField::create(
|
||||||
),
|
'OnCompleteMessage',
|
||||||
$editor = HTMLEditorField::create(
|
'',
|
||||||
'OnCompleteMessage',
|
$this->OnCompleteMessage
|
||||||
'',
|
)
|
||||||
$this->OnCompleteMessage
|
)->addExtraClass('field'),
|
||||||
)
|
...$this->getFormOptions()->toArray(),
|
||||||
);
|
|
||||||
|
|
||||||
$onCompleteFieldSet->addExtraClass('field');
|
|
||||||
|
|
||||||
$editor->setRows(3);
|
|
||||||
$label->addExtraClass('left');
|
|
||||||
|
|
||||||
// Define config for email recipients
|
|
||||||
$emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10);
|
|
||||||
$emailRecipientsConfig->getComponentByType(GridFieldAddNewButton::class)
|
|
||||||
->setButtonName(
|
|
||||||
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.ADDEMAILRECIPIENT', 'Add Email Recipient')
|
|
||||||
);
|
|
||||||
|
|
||||||
// who do we email on submission
|
|
||||||
$emailRecipients = GridField::create(
|
|
||||||
'EmailRecipients',
|
|
||||||
'',
|
|
||||||
$this->EmailRecipients(),
|
|
||||||
$emailRecipientsConfig
|
|
||||||
);
|
|
||||||
$emailRecipients
|
|
||||||
->getConfig()
|
|
||||||
->getComponentByType(GridFieldDetailForm::class)
|
|
||||||
->setItemRequestClass(UserFormRecipientItemRequest::class);
|
|
||||||
|
|
||||||
$fields->addFieldToTab('Root.FormOptions', $onCompleteFieldSet);
|
|
||||||
$fields->addFieldToTab('Root.Recipients', $emailRecipients);
|
|
||||||
$fields->addFieldsToTab('Root.FormOptions', $this->getFormOptions()->toArray());
|
|
||||||
|
|
||||||
$submissions = $this->getSubmissionsGridField();
|
|
||||||
$fields->findOrMakeTab('Root.Submissions')->setTitle(_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SUBMISSIONS', 'Submissions'));
|
|
||||||
$fields->addFieldToTab('Root.Submissions', $submissions);
|
|
||||||
$fields->addFieldToTab(
|
|
||||||
'Root.FormOptions',
|
|
||||||
CheckboxField::create(
|
CheckboxField::create(
|
||||||
'DisableSaveSubmissions',
|
'DisableSaveSubmissions',
|
||||||
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SAVESUBMISSIONS', 'Disable Saving Submissions to Server')
|
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SAVESUBMISSIONS', 'Disable Saving Submissions to Server')
|
||||||
)
|
)
|
||||||
);
|
]);
|
||||||
|
$editor->setRows(3);
|
||||||
|
$label->addExtraClass('left');
|
||||||
|
|
||||||
|
$submissions = $this->getSubmissionsGridField();
|
||||||
|
$fields->findOrMakeTab('Root.Submissions')->setTitle(_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.SUBMISSIONS', 'Submissions'));
|
||||||
|
$fields->addFieldToTab('Root.Submissions', $submissions);
|
||||||
|
|
||||||
|
// Fix tab order - otherwise recipients comes too early due to being scaffolded
|
||||||
|
$fields->findTab('Root')->changeTabOrder(['Main', 'FormOptions', 'Recipients', 'Submissions']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
|
Loading…
Reference in New Issue
Block a user