-
Notifications
You must be signed in to change notification settings - Fork 333
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
ENH Improve type safety to support refactored template layer #3010
ENH Improve type safety to support refactored template layer #3010
Conversation
dc43d36
to
cde12fa
Compare
51186ef
to
1a5eab0
Compare
public function Menu($level) | ||
{ | ||
return $this->getMenu($level); | ||
} |
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.
This method only exists to work around the fact that $Menu(2)
doesn't pass the 2
arg to getMenu()
.
I've changed it so that the args are passed into getters, so this method isn't needed anymore.
$templatesFound[] = SSViewer::get_templates_by_class(static::class, $action, Controller::class); | ||
$templatesFound[] = SSViewer::get_templates_by_class(static::class, $action ?? '', Controller::class); |
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.
$action
isn't typed, and null
is pretty common to say "there's no action" so just a bit of type safety here.
1a5eab0
to
fe90886
Compare
fe90886
to
6157338
Compare
6157338
to
db61732
Compare
/** | ||
* @return ArrayList<SiteTree> | ||
* @deprecated 5.4.0 Use getMenu() instead. You can continue to use $Menu in templates. | ||
*/ | ||
public function Menu($level) | ||
{ | ||
Deprecation::noticeWithNoReplacment('5.4.0', 'Use getMenu() instead. You can continue to use $Menu in templates.'); | ||
return $this->getMenu($level); | ||
} |
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.
This isn't needed anymore. It existed because you couldn't pass args into getters from a template using $Menu(2)
syntax.
I've resolved that - the args now get passed through to the getter.
// Find templates for the controller + action together - e.g. PageController_action.ss | ||
$templatesFound[] = SSViewer::get_templates_by_class(static::class, $action, Controller::class); | ||
// Find templates for the controller + action together - e.g. PageController_action | ||
$templatesFound[] = SSViewer::get_templates_by_class(static::class, $action ?? '', Controller::class); |
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.
$action
isn't strongly typed so I've added a little type safety here.
|
||
$templates = array_merge(...$templatesFound); | ||
return SSViewer::create($templates); | ||
return SSViewer::create($templates, $this->getTemplateEngine()); |
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.
See Controller::getTemplateEngine()
in the framework PR
'content' => $this->obj('Title')->forTemplate() | ||
'content' => $this->obj('Title')?->forTemplate() |
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.
obj()
can return null
Issue