Merge pull request #2746 from mooror/enhance-batch-action-parameters

CMSMain - Fixed and enhanced BatchActionParameters
This commit is contained in:
Guy Sartorelli 2022-07-12 15:36:53 +12:00 committed by GitHub
commit de8d7632c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 7 deletions

View File

@ -4,6 +4,7 @@ Name: cmsextensions
SilverStripe\Admin\LeftAndMain: SilverStripe\Admin\LeftAndMain:
extensions: extensions:
- SilverStripe\CMS\Controllers\LeftAndMainPageIconsExtension - SilverStripe\CMS\Controllers\LeftAndMainPageIconsExtension
- SilverStripe\CMS\Controllers\LeftAndMainBatchActionsExtension
--- ---
Name: cmsmodals Name: cmsmodals
--- ---

View File

@ -2112,28 +2112,38 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
return new CMSBatchActionHandler($this, '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() public function BatchActionParameters()
{ {
$batchActions = CMSBatchActionHandler::config()->batch_actions; $batchActions = $this->batchactions()->registeredActions();
$forms = []; $forms = [];
foreach ($batchActions as $urlSegment => $batchAction) { foreach ($batchActions as $urlSegment => $batchAction) {
$SNG_action = singleton($batchAction); $SNG_action = singleton($batchAction['class']);
if ($SNG_action->canView() && $fieldset = $SNG_action->getParameterFields()) { if ($SNG_action->canView() && $fieldList = $SNG_action->getParameterFields()) {
$formHtml = ''; $formHtml = '';
/** @var FormField $field */ /** @var FormField $field */
foreach ($fieldset as $field) { foreach ($fieldList as $field) {
$formHtml .= $field->Field(); $formHtml .= $field->FieldHolder();
} }
$forms[$urlSegment] = $formHtml; $forms[$urlSegment] = $formHtml;
} }
} }
$pageHtml = ''; $pageHtml = '';
foreach ($forms as $urlSegment => $html) { 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 * Returns a list of batch actions
*/ */

View File

@ -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;
}
}