Skip to content

Commit

Permalink
[BUGFIX] Correct the integration of categories (#77)
Browse files Browse the repository at this point in the history
The following errors have been fixed:

    T3docs\BlogExample\Domain\Model\Blog::getCategories(): Return value must be of type TYPO3\CMS\Extbase\Persistence\ObjectStorage, null returned
    T3docs\BlogExample\Domain\Model\Post::getCategories(): Return value must be of type TYPO3\CMS\Extbase\Persistence\ObjectStorage, null returned

Additionally, the categories were not displayed in the backend when editing records.

Releases: main, 12.4
  • Loading branch information
format-gmbh authored and brotkrueml committed Mar 30, 2024
1 parent 13cbb6a commit 8191999
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Classes/Domain/Model/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class Blog extends AbstractEntity
public $posts;

/**
* @var ObjectStorage<Category>
* @var ?ObjectStorage<Category>
*/
public $categories;
public ?ObjectStorage $categories = null;

/**
* The blog's administrator
Expand Down Expand Up @@ -134,7 +134,7 @@ public function setCategories(ObjectStorage $categories)
/**
* Get categories
*/
public function getCategories(): ObjectStorage
public function getCategories(): ?ObjectStorage
{
return $this->categories;
}
Expand Down
8 changes: 4 additions & 4 deletions Classes/Domain/Model/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class Post extends AbstractEntity
public ObjectStorage $tags;

/**
* @var ObjectStorage<Category>
* @var ?ObjectStorage<Category>
*/
public ObjectStorage $categories;
public ?ObjectStorage $categories = null;

/**
* @var ObjectStorage<Comment>
Expand Down Expand Up @@ -157,9 +157,9 @@ public function setCategories(ObjectStorage $categories): void
/**
* Get categories
*
* @return ObjectStorage<Category>
* @return ?ObjectStorage<Category>
*/
public function getCategories(): ObjectStorage
public function getCategories(): ?ObjectStorage
{
return $this->categories;
}
Expand Down
16 changes: 16 additions & 0 deletions Configuration/Extbase/Persistence/Classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,20 @@
\T3docs\BlogExample\Domain\Model\FrontendUserGroup::class => [
'tableName' => 'fe_groups',
],
\T3docs\BlogExample\Domain\Model\Blog::class => [
'tableName' => 'tx_blogexample_domain_model_blog',
'properties' => [
'categories' => [
'fieldName' => 'category',
],
],
],
\T3docs\BlogExample\Domain\Model\Post::class => [
'tableName' => 'tx_blogexample_domain_model_post',
'properties' => [
'categories' => [
'fieldName' => 'category',
],
],
],
];
2 changes: 1 addition & 1 deletion Configuration/TCA/tx_blogexample_domain_model_blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
],
],
'types' => [
'1' => ['showitem' => 'sys_language_uid, hidden, fe_group, title, description, logo, posts, administrator'],
'1' => ['showitem' => 'sys_language_uid, hidden, fe_group, title, description, logo, posts, administrator, category'],
],
'palettes' => [
'1' => ['showitem' => ''],
Expand Down
2 changes: 1 addition & 1 deletion Configuration/TCA/tx_blogexample_domain_model_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'maxSingleDBListItems' => 500,
],
'types' => [
'1' => ['showitem' => 'sys_language_uid, hidden, blog, title, date, author, second_author, content, tags, comments, related_posts, additional_name, additional_info, additional_comments'],
'1' => ['showitem' => 'sys_language_uid, hidden, blog, title, date, author, second_author, content, tags, comments, related_posts, additional_name, additional_info, additional_comments, category'],
],
'columns' => [
'sys_language_uid' => [
Expand Down

0 comments on commit 8191999

Please sign in to comment.