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

API Strong typing for the view layer #1244

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Controllers/ElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ public function getElement()
/**
* Renders the managed {@link BaseElement} wrapped with the current
* {@link ElementController}.
*
* @return string HTML
*/
public function forTemplate()
public function forTemplate(): string
{
$defaultStyles = $this->config()->get('default_styles');
$this->extend('updateForTemplateDefaultStyles', $defaultStyles);
Expand Down
6 changes: 2 additions & 4 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,18 +600,16 @@ private function getFieldNamesExcludedFromCmsSearch(): array
* Default way to render element in templates. Note that all blocks should
* be rendered through their {@link ElementController} class as this
* contains the holder styles.
*
* @return string|null HTML
*/
public function forTemplate($holder = true)
public function forTemplate($holder = true): string
{
$templates = $this->getRenderTemplates();

if ($templates) {
return $this->renderWith($templates);
}

return null;
return '';
Comment on lines +604 to +612
Copy link
Member Author

Choose a reason for hiding this comment

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

There's no parent class enforcing non-nullable values yet - but part of the next piece of work will include adding forTemplate() directly on ViewableData where its return type will be string.
There's just no reason for this method to ever return null, in comparison with an empty string.

}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Models/ElementalArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ public function supportedPageTypes()
return $elementalClasses;
}

/**
* @return DBHTMLText
*/
public function forTemplate()
public function forTemplate(): string
{
return $this->renderWith(static::class);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/FieldType/DBObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct()
/**
* Add the field to the underlying database.
*/
public function requireField()
public function requireField(): void
{
// noop - This class exists only to bind to a custom GraphQL type
}
Expand Down
Loading