From 8191999157312ceaefc5d6e57d35c69a9871007d Mon Sep 17 00:00:00 2001 From: Andreas Kessel Date: Sat, 30 Mar 2024 18:52:20 +0100 Subject: [PATCH] [BUGFIX] Correct the integration of categories (#77) 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 --- Classes/Domain/Model/Blog.php | 6 +++--- Classes/Domain/Model/Post.php | 8 ++++---- Configuration/Extbase/Persistence/Classes.php | 16 ++++++++++++++++ .../TCA/tx_blogexample_domain_model_blog.php | 2 +- .../TCA/tx_blogexample_domain_model_post.php | 2 +- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Classes/Domain/Model/Blog.php b/Classes/Domain/Model/Blog.php index 8097344..582a639 100644 --- a/Classes/Domain/Model/Blog.php +++ b/Classes/Domain/Model/Blog.php @@ -54,9 +54,9 @@ class Blog extends AbstractEntity public $posts; /** - * @var ObjectStorage + * @var ?ObjectStorage */ - public $categories; + public ?ObjectStorage $categories = null; /** * The blog's administrator @@ -134,7 +134,7 @@ public function setCategories(ObjectStorage $categories) /** * Get categories */ - public function getCategories(): ObjectStorage + public function getCategories(): ?ObjectStorage { return $this->categories; } diff --git a/Classes/Domain/Model/Post.php b/Classes/Domain/Model/Post.php index 9199697..88c727b 100644 --- a/Classes/Domain/Model/Post.php +++ b/Classes/Domain/Model/Post.php @@ -54,9 +54,9 @@ class Post extends AbstractEntity public ObjectStorage $tags; /** - * @var ObjectStorage + * @var ?ObjectStorage */ - public ObjectStorage $categories; + public ?ObjectStorage $categories = null; /** * @var ObjectStorage @@ -157,9 +157,9 @@ public function setCategories(ObjectStorage $categories): void /** * Get categories * - * @return ObjectStorage + * @return ?ObjectStorage */ - public function getCategories(): ObjectStorage + public function getCategories(): ?ObjectStorage { return $this->categories; } diff --git a/Configuration/Extbase/Persistence/Classes.php b/Configuration/Extbase/Persistence/Classes.php index 7a239b8..9c00a75 100644 --- a/Configuration/Extbase/Persistence/Classes.php +++ b/Configuration/Extbase/Persistence/Classes.php @@ -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', + ], + ], + ], ]; diff --git a/Configuration/TCA/tx_blogexample_domain_model_blog.php b/Configuration/TCA/tx_blogexample_domain_model_blog.php index 2cfe492..76a76a3 100644 --- a/Configuration/TCA/tx_blogexample_domain_model_blog.php +++ b/Configuration/TCA/tx_blogexample_domain_model_blog.php @@ -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' => ''], diff --git a/Configuration/TCA/tx_blogexample_domain_model_post.php b/Configuration/TCA/tx_blogexample_domain_model_post.php index 9610c12..861b720 100644 --- a/Configuration/TCA/tx_blogexample_domain_model_post.php +++ b/Configuration/TCA/tx_blogexample_domain_model_post.php @@ -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' => [