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

CMSMain - Fixed and enhanced BatchActionParameters #2746

Merged
merged 6 commits into from
Jul 12, 2022
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
1 change: 1 addition & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Name: cmsextensions
SilverStripe\Admin\LeftAndMain:
extensions:
- SilverStripe\CMS\Controllers\LeftAndMainPageIconsExtension
- SilverStripe\CMS\Controllers\LeftAndMainBatchActionsExtension
---
Name: cmsmodals
---
Expand Down
24 changes: 17 additions & 7 deletions code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -2112,28 +2112,38 @@ 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 = 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 .= "<div class=\"params\" id=\"BatchActionParameters_$urlSegment\">$html</div>\n\n";
$pageHtml .= '<div class="params" id="BatchActionParameters_' . $urlSegment . '" style="display:none">' . $html . '</div>';
}
return new LiteralField("BatchActionParameters", '<div id="BatchActionParameters" style="display:none">'.$pageHtml.'</div>');
return new LiteralField('BatchActionParameters', '<div id="BatchActionParameters" class="action-parameters" style="display:none">' . $pageHtml . '</div>');
}

/**
* Returns a list of batch actions
*/
Expand Down
16 changes: 16 additions & 0 deletions code/Controllers/LeftAndMainBatchActionsExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace SilverStripe\CMS\Controllers;

use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Core\Extension;

class LeftAndMainBatchActionsExtension extends Extension
{
public function updateBatchActionsForm(&$form)
{
$cmsMain = singleton(CMSMain::class);
$form->Fields()->insertAfter('Action', $cmsMain->BatchActionParameters());
return $form;
}
}