Skip to content

ENH Throw exception if empty parent CMSEditLink#1408

Closed
emteknetnz wants to merge 1 commit intosilverstripe:6from
creative-commoners:pulls/6/add-exception
Closed

ENH Throw exception if empty parent CMSEditLink#1408
emteknetnz wants to merge 1 commit intosilverstripe:6from
creative-commoners:pulls/6/add-exception

Conversation

@emteknetnz
Copy link
Member

@emteknetnz emteknetnz commented Jan 28, 2026

Issue #1407

Requires PRs in #1405 to be merged and merged up for behat to pass

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

With the exception in that spot, it will be thrown for any of these public method calls:

  • getCMSEditLink()
  • getEditLink()
  • getBlockSchema()

That will happen no matter why they're called, and regardless of whether there even is a parent record for the block at the time of the call.

Probably the exception should be thrown from ElementalAreaController or some other place that's closer to the place where the link is actually needed.

Please also use LogicException instead of RuntimeException: https://www.php.net/manual/en/class.logicexception.php

Exception that represents error in the program logic. This kind of exception should lead directly to a fix in your code.

@GuySartorelli
Copy link
Member

Thinking more about this actually - there's some edge cases we need to square away as well. For example what if you move a block to a new parent, but that new parent doesn't have a edit link? Suddenly we're throwing an exception so the elemental area probably won't load. You can't really catch that at dev time.

I know I originally suggested an exception but perhaps it would be better to instead do a combination of logging an error, and displaying an error on the block. That way we don't have to consider every possible edge case, and content authors won't have elemental areas failing to load.

@GuySartorelli
Copy link
Member

Closing for now as the attached card was moved to refinement

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

Successfully merging this pull request may close these issues.

2 participants