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

Replace new-record literal link when using MultiClass in grid #300

Closed
oilee80 opened this issue Dec 12, 2019 · 1 comment
Closed

Replace new-record literal link when using MultiClass in grid #300

oilee80 opened this issue Dec 12, 2019 · 1 comment

Comments

@oilee80
Copy link
Contributor

oilee80 commented Dec 12, 2019

Need to add something like below code.
Main issue with this is that the dropdown would drown would drop below the bottom of the page.
Also the JS doesn't trigger when "Add" is clicked.

Suggestion: Have it appear as a normal "Add" button but when clicked it pops up a list of options

Code:

<?php

use SilverStripe\Core\Extension;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\LiteralField;
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;

/**
 *
 */
class GridFieldDetailForm_ItemRequest_MultiClass_Extension extends Extension
{
    public function updateFormActions(FieldList &$actions)
    {
        $grid = $this->owner->GridField;
        $gridFieldConfig = $grid->getConfig();
        $addMultiClassComponent = $gridFieldConfig->getComponentByType(GridFieldAddNewMultiClass::class);
        if ($addMultiClassComponent) {
            $newRecordField = static::get_new_record_field_from_actions($actions);
            if ($newRecordField) {
                $newRecordField->getContainerFieldList()->removeByName('new-record');
                $newRecordField->getContainerFieldList()->push(
                    LiteralField::create('new-record', $addMultiClassComponent->getHTMLFragments($grid)['buttons-before-left'])
                );
            }
        }
    }

    /**
     * @param FieldList $actions
     * @return LiteralField OR NULL
     */
    private static function get_new_record_field_from_actions(FieldList &$actions)
    {
        $rightGroup = $actions->fieldByName('RightGroup');
        if (!$rightGroup) {
            return null;
        }
        return $rightGroup->getChildren()->fieldByName('new-record');
    }
}
oilee80 added a commit to oilee80/silverstripe-gridfieldextensions that referenced this issue Dec 12, 2019
@GuySartorelli
Copy link
Collaborator

The PR #301 was targetted for resolving this and was merged - I'm assuming that resolves this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants