-
-
Notifications
You must be signed in to change notification settings - Fork 223
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
90/edit preview mode support v3 review #4521
90/edit preview mode support v3 review #4521
Conversation
…ted rendering mode
Otherwise, this feature would only work for this one page, successive links will currently not have that query param added - the linking service still needs to learn this, but we delay this for another time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this in general. But the runtime cache implemented in the return statement is a bit too much flexing ;-)
My brain likes simple code and runtime caches that use early returns.
} | ||
throw new Exception( | ||
'The requested interface render mode "' . $modeName . '" is not configured.' | ||
return $this->instances[$modeName] ??= match (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda dislike that you put the runtime cache in instances
into one live with code that populates this.
Needlessly harder to read and unterstand. Offcourse the runtime cache makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
public function findByName(string $modeName): RenderingMode
{
if ($instance = $this->instances[$modeName]) {
return $instance;
}
if ($modeName === RenderingMode::FRONTEND) {
$this->instances[$modeName] = RenderingMode::createFrontend();
} else {
$this->instances[$modeName] = RenderingMode::createFromConfiguration($modeName, $this->editPreviewModes[$modeName]);
}
return $this->instances[$modeName];
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??=
and match($modeName)
would be fine for me. What is imho too much is the match true you have to use to thwrow the exception. Will adjust and the merge this into the other pr.
Funny is that even the php documentation does not explain that operator other than mentioning its existence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW: This would be fine for me ... but it will not throw on unconfigured modes
return $this->instances[$modeName] ??= match($modeName) {
RenderingMode::FRONTEND => RenderingMode::createFrontend(),
default => RenderingMode::createFromConfiguration($modeName, $this->editPreviewModes[$modeName])
};
hehe i do understand what you mean. I was inspired by code I saw written from @grebaldi phps newer i think at one point we might get used to such patterns more and that this is for now too early to use? |
I won’t be on my pc today so please feel free to adjust the code as you liked (this was just a suggestion and it’s your pr after all ^^) |
9305987
to
5639b6b
Compare
TASK: Remove half-baked solution of session independent preview's
Otherwise, this feature would only work for this one page, successive links will currently not have that query param added - the linking service still needs to learn this, but we delay this for another time.
TASK: RenderingModeService instances runtime cache
TASK: Introduce constant
RenderingMode::FRONTEND
for system integrated rendering mode