From 81593057dee42b4d939df2c0c4bd4f80a54999f6 Mon Sep 17 00:00:00 2001 From: Benjamin Blake Date: Mon, 4 Jul 2022 22:14:53 -0600 Subject: [PATCH 1/6] CMSMain - Fixed and enhanced BatchActionParameters + Fixed the $batchActions variable by making it use the `registeredActions()` method + Made the loop use `FieldHolder` instead of `Field` so CMS fields display correctly + Added hidden styles to the batch action div for jQuery show/hide functionality (found in Admin module PR) --- code/Controllers/CMSMain.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index db715788fd..741fed45d6 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -2114,23 +2114,23 @@ public function batchactions() public function BatchActionParameters() { - $batchActions = CMSBatchActionHandler::config()->batch_actions; + $batchActions = $this->batchactions()->registeredActions(); $forms = []; foreach ($batchActions as $urlSegment => $batchAction) { - $SNG_action = singleton($batchAction); - if ($SNG_action->canView() && $fieldset = $SNG_action->getParameterFields()) { + $SNG_action = singleton($batchAction["class"]); + if ($SNG_action->canView() && $fieldList = $SNG_action->getParameterFields()) { $formHtml = ''; /** @var FormField $field */ - foreach ($fieldset as $field) { - $formHtml .= $field->Field(); + foreach ($fieldList as $field) { + $formHtml .= $field->FieldHolder(); } $forms[$urlSegment] = $formHtml; } } $pageHtml = ''; foreach ($forms as $urlSegment => $html) { - $pageHtml .= "
$html
\n\n"; + $pageHtml .= "
$html
\n\n"; } return new LiteralField("BatchActionParameters", ''); } From 654fa5a6813a94a045c4b655d5b0f0d66d061a38 Mon Sep 17 00:00:00 2001 From: Benjamin Blake Date: Tue, 5 Jul 2022 20:11:20 -0600 Subject: [PATCH 2/6] CMSMain - Linting changes + Added Docblock + Made the linting changes requested by @GuySartorelli + Added method documentation for BatchActionParameters() --- code/Controllers/CMSMain.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 741fed45d6..1401ca86ce 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -2112,13 +2112,22 @@ public function batchactions() return new CMSBatchActionHandler($this, 'batchactions'); } + /** + * Returns a LiteralField containing parameter field HTML + * for batch actions + * + * Used by {@link LeftAndMain} to render batch actions in + * the BatchActionsForm + * + * @return LiteralField + */ public function BatchActionParameters() { $batchActions = $this->batchactions()->registeredActions(); $forms = []; foreach ($batchActions as $urlSegment => $batchAction) { - $SNG_action = singleton($batchAction["class"]); + $SNG_action = singleton($batchAction['class']); if ($SNG_action->canView() && $fieldList = $SNG_action->getParameterFields()) { $formHtml = ''; /** @var FormField $field */ @@ -2130,10 +2139,11 @@ public function BatchActionParameters() } $pageHtml = ''; foreach ($forms as $urlSegment => $html) { - $pageHtml .= "
$html
\n\n"; + $pageHtml .= ''; } - return new LiteralField("BatchActionParameters", ''); + return new LiteralField('BatchActionParameters', ''); } + /** * Returns a list of batch actions */ From 6bd3618f09baf0677a5c886474b64fa50bd064af Mon Sep 17 00:00:00 2001 From: Michal Kleiner Date: Thu, 7 Jul 2022 10:32:19 +1200 Subject: [PATCH 3/6] Fix CS --- code/Controllers/CMSMain.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 1401ca86ce..0d47c44278 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -2115,7 +2115,7 @@ public function batchactions() /** * Returns a LiteralField containing parameter field HTML * for batch actions - * + * * Used by {@link LeftAndMain} to render batch actions in * the BatchActionsForm * From 35d12228d0fd3b1025893702c61232611dad7423 Mon Sep 17 00:00:00 2001 From: Benjamin Blake Date: Wed, 6 Jul 2022 22:45:50 -0600 Subject: [PATCH 4/6] CMSMain - Added HTML class attribute for styling + Added an `action-parameters` class to the BatchActionParameters field so we can style it without using ID selectors --- code/Controllers/CMSMain.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 0d47c44278..df619ea8d0 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -2141,7 +2141,7 @@ public function BatchActionParameters() foreach ($forms as $urlSegment => $html) { $pageHtml .= ''; } - return new LiteralField('BatchActionParameters', ''); + return new LiteralField('BatchActionParameters', ''); } /** From fa1c6ae3db2c0e5257bab796f85efbee4116e70c Mon Sep 17 00:00:00 2001 From: Benjamin Blake Date: Wed, 6 Jul 2022 22:49:24 -0600 Subject: [PATCH 5/6] Created a batch action extension for LeftAndMain + Created an extension to add the `BatchActionParameters` fields from CMSMain to the `BatchActionsForm` in LeftAndMain + Applied the extension to LeftAndMain using YAML --- _config/config.yml | 1 + .../LeftAndMainBatchActionsExtension.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 code/Controllers/LeftAndMainBatchActionsExtension.php diff --git a/_config/config.yml b/_config/config.yml index c480278a85..47a7621559 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -4,6 +4,7 @@ Name: cmsextensions SilverStripe\Admin\LeftAndMain: extensions: - SilverStripe\CMS\Controllers\LeftAndMainPageIconsExtension + - SilverStripe\CMS\Controllers\LeftAndMainBatchActionsExtension --- Name: cmsmodals --- diff --git a/code/Controllers/LeftAndMainBatchActionsExtension.php b/code/Controllers/LeftAndMainBatchActionsExtension.php new file mode 100644 index 0000000000..443931e7cb --- /dev/null +++ b/code/Controllers/LeftAndMainBatchActionsExtension.php @@ -0,0 +1,16 @@ +Fields()->insertAfter('Action', $cmsMain->BatchActionParameters()); + return $form; + } +} \ No newline at end of file From aca0defe164e057b67d23270f9d27744d5b4251f Mon Sep 17 00:00:00 2001 From: Benjamin Date: Thu, 7 Jul 2022 12:46:22 -0600 Subject: [PATCH 6/6] BatchActionsExtension - Added blank end line --- code/Controllers/LeftAndMainBatchActionsExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Controllers/LeftAndMainBatchActionsExtension.php b/code/Controllers/LeftAndMainBatchActionsExtension.php index 443931e7cb..8e582972e3 100644 --- a/code/Controllers/LeftAndMainBatchActionsExtension.php +++ b/code/Controllers/LeftAndMainBatchActionsExtension.php @@ -13,4 +13,4 @@ public function updateBatchActionsForm(&$form) $form->Fields()->insertAfter('Action', $cmsMain->BatchActionParameters()); return $form; } -} \ No newline at end of file +}