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

FIX Ensure correct link is used when gridfield is readonly #90

Merged
merged 1 commit into from
May 16, 2024

Conversation

AljosaB
Copy link

@AljosaB AljosaB commented Mar 19, 2019

Copy link

@robbieaverill robbieaverill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to create a pull request for this issue! I haven't had time yet to test the code out, but thought I'd mention that I'm not super happy about the approach.

I don't think that overloading the GridField class is necessary to fix your issue - I also think you should be able to use GridFieldConfig to target and replace the View button with what appears to be a sort of Edit button. If you can do this (I haven't looked far enough into it yet) then you can get away with less changes and less new APIs introduced.

I'll pick this up later this week and have a closer look. In the meantime, please let me know what you think =)

@NightJar
Copy link

I agree with @robbieaverill - only a single class needs to be introduced (the new GridFieldSiteTreeViewButton you've created @AljosaB), and edits to the components for the GridField would be more appropriate in GridFieldConfig_Lumberjack :)

@AljosaB
Copy link
Author

AljosaB commented Mar 20, 2019

The thing is, there is no View button in GridField config, so I can not replace it. There is Edit button that gets replaced later when canEdit check is made

LeftAndMain::getEditForm (Edit button is removed somewhere after this)

if (!$record->canEdit()) {
	$readonlyFields = $form->Fields()->makeReadonly();
	$form->setFields($readonlyFields);
}

and in the end View button is added in GridField::performReadonlyTransformation

// As the edit button may have been removed, add a view button if it doesn't have one
if (!$copyConfig->getComponentByType(GridFieldViewButton::class)) {
	$copyConfig->addComponent(new GridFieldViewButton);

I didn't find any hook after that to replace View button with my extended View button, that's why I had to introduce an extended GridField and overload performReadonlyTransformation function. I hope you find a better solution.

@robbieaverill
Copy link

I'll take a look at this later this week :)

@GuySartorelli GuySartorelli changed the base branch from master to 3 May 10, 2024 02:23
@GuySartorelli GuySartorelli changed the title fix broken link when edit button is replaced with view button FIX Ensure correct link is used when gridfield is readonly May 10, 2024
@GuySartorelli
Copy link
Member

GuySartorelli commented May 10, 2024

I've updated this PR to use the newish API for updating the set of readonly components.
It requires a companion PR in framework so the correct view button class is used.

Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, works well

@emteknetnz emteknetnz merged commit 82f0010 into silverstripe:3 May 16, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants