lekoala /
silverstripe-admini
| 1 | <?php |
||
| 2 | |||
| 3 | namespace LeKoala\Admini\Forms; |
||
| 4 | |||
| 5 | use LeKoala\Admini\LeftAndMain; |
||
| 6 | use SilverStripe\Core\Extension; |
||
| 7 | use LeKoala\Admini\MaterialIcons; |
||
| 8 | use SilverStripe\Forms\FieldList; |
||
| 9 | use SilverStripe\Forms\FormAction; |
||
| 10 | use SilverStripe\Control\Controller; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Improve how actions are rendered if you are using the cms-actions module |
||
| 14 | */ |
||
| 15 | class AdminiCmsActionsExtension extends Extension |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @param FieldList||FormAction[] $actions |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 19 | * @return void |
||
| 20 | */ |
||
| 21 | public function onAfterUpdateCMSActions(FieldList $actions) |
||
| 22 | { |
||
| 23 | $controller = Controller::curr(); |
||
| 24 | |||
| 25 | // Avoid side effects on regular admin |
||
| 26 | if (!$controller instanceof LeftAndMain) { |
||
| 27 | return; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** @var \SilverStripe\Forms\Tab $dropUpContainer */ |
||
| 31 | $dropUpContainer = $actions->fieldByName('ActionMenus.MoreOptions'); |
||
|
0 ignored issues
–
show
Are you sure the assignment to
$dropUpContainer is correct as $actions->fieldByName('ActionMenus.MoreOptions') targeting SilverStripe\Forms\FieldList::fieldByName() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 32 | |||
| 33 | // Replace with our own logic |
||
| 34 | if ($dropUpContainer) { |
||
|
0 ignored issues
–
show
|
|||
| 35 | $group = new AdminiDropUpField($dropUpContainer->getChildren()); |
||
| 36 | $actions->insertBefore('RightGroup', $group); |
||
| 37 | $actions->removeByName('ActionMenus'); |
||
| 38 | } |
||
| 39 | |||
| 40 | $this->updateStyle($actions); |
||
| 41 | } |
||
| 42 | |||
| 43 | protected function updateStyle($actions) |
||
| 44 | { |
||
| 45 | /** @var FormAction $action */ |
||
| 46 | foreach ($actions as $action) { |
||
| 47 | if ($action->hasMethod("getChildren")) { |
||
| 48 | foreach ($action->getChildren() as $child) { |
||
| 49 | $this->updateStyle($child); |
||
| 50 | } |
||
| 51 | continue; |
||
| 52 | } |
||
| 53 | if ($action->hasExtraClass('btn-outline-danger')) { |
||
| 54 | $action->removeExtraClass('btn-outline-danger'); |
||
| 55 | $action->addExtraClass('btn-danger'); |
||
| 56 | if ($action->hasExtraClass('font-icon-trash-bin')) { |
||
| 57 | $action->removeExtraClass('font-icon-trash-bin'); |
||
| 58 | $action->setIcon(MaterialIcons::DELETE); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | if ($action->hasExtraClass('btn-outline-primary')) { |
||
| 62 | $action->removeExtraClass('btn-outline-primary'); |
||
| 63 | $action->addExtraClass('btn-outline-success'); |
||
| 64 | if ($action->hasExtraClass('font-icon-level-up')) { |
||
| 65 | $action->removeExtraClass('font-icon-level-up'); |
||
| 66 | $action->setIcon(MaterialIcons::KEYBOARD_RETURN); |
||
| 67 | } |
||
| 68 | if ($action->hasExtraClass('font-icon-angle-double-left')) { |
||
| 69 | $action->removeExtraClass('font-icon-angle-double-left'); |
||
| 70 | $action->setIcon(MaterialIcons::NAVIGATE_BEFORE); |
||
| 71 | } |
||
| 72 | if ($action->hasExtraClass('font-icon-angle-double-right')) { |
||
| 73 | $action->removeExtraClass('font-icon-angle-double-right'); |
||
| 74 | $action->addExtraClass('btn-flex btn-icon-end'); |
||
| 75 | $action->setIcon(MaterialIcons::NAVIGATE_NEXT); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | if ($action->hasExtraClass('btn-primary')) { |
||
| 79 | $action->removeExtraClass('btn-primary'); |
||
| 80 | $action->addExtraClass('btn-success'); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 |