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

ENH Improve type safety to support refactored template layer #3010

Merged

Conversation

GuySartorelli
Copy link
Member

@GuySartorelli GuySartorelli marked this pull request as draft September 26, 2024 04:52
@GuySartorelli GuySartorelli force-pushed the pulls/6/refactor-template-layer branch 3 times, most recently from dc43d36 to cde12fa Compare October 4, 2024 00:13
@GuySartorelli GuySartorelli force-pushed the pulls/6/refactor-template-layer branch 5 times, most recently from 51186ef to 1a5eab0 Compare October 10, 2024 00:28
Comment on lines 295 to 301
public function Menu($level)
{
return $this->getMenu($level);
}
Copy link
Member Author

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.

Comment on lines 422 to 415
$templatesFound[] = SSViewer::get_templates_by_class(static::class, $action, Controller::class);
$templatesFound[] = SSViewer::get_templates_by_class(static::class, $action ?? '', Controller::class);
Copy link
Member Author

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.

@GuySartorelli GuySartorelli marked this pull request as ready for review October 23, 2024 03:03
Comment on lines -293 to -301
/**
* @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);
}
Copy link
Member Author

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);
Copy link
Member Author

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());
Copy link
Member Author

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()
Copy link
Member Author

Choose a reason for hiding this comment

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

obj() can return null

@emteknetnz emteknetnz merged commit 1034dc5 into silverstripe:6 Oct 30, 2024
5 of 12 checks passed
@emteknetnz emteknetnz deleted the pulls/6/refactor-template-layer branch October 30, 2024 21:50
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