[TASK] Extend blog_example with relations 32/58032/15
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Fri, 24 Aug 2018 16:55:29 +0000 (18:55 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 30 Aug 2018 14:11:13 +0000 (16:11 +0200)
* 1:1 inline relation csv (Post->additonalName)
* 1:1 inline relation foreign_field (Post->additonalInfo)
* 1:n inline relation csv (Post->additionalComments)
* n:1 group relation (Post->secondAuthor)

It also makes Person model translatable.

Resolves: #85974
Releases: master
Change-Id: I75a8e6c070e9a6bdfba0772b102a13bc94f7556f
Reviewed-on: https://review.typo3.org/58032
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Domain/Model/Info.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Domain/Model/Post.php
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/tx_blogexample_domain_model_info.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/tx_blogexample_domain_model_person.php
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/tx_blogexample_domain_model_post.php
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Resources/Private/Language/locallang_db.xml
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/ext_tables.sql

diff --git a/typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Domain/Model/Info.php b/typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Domain/Model/Info.php
new file mode 100644 (file)
index 0000000..a9406ec
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+namespace ExtbaseTeam\BlogExample\Domain\Model;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * A post additional info (1:1 inline relation to post)
+ */
+class Info extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
+{
+
+    /**
+     * @var string
+     */
+    protected $name = '';
+
+    /**
+     * Sets the name
+     *
+     * @param string $name
+     */
+    public function setName($name)
+    {
+        $this->content = $name;
+    }
+
+    /**
+     * Getter for name
+     *
+     * @return string
+     */
+    public function getName()
+    {
+        return $this->name;
+    }
+
+    /**
+     * Returns this info as a formatted string
+     *
+     * @return string
+     */
+    public function __toString()
+    {
+        return $this->name;
+    }
+}
index 9108eee..6bc3eeb 100644 (file)
@@ -45,6 +45,11 @@ class Post extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
     /**
      * @var \ExtbaseTeam\BlogExample\Domain\Model\Person
      */
+    protected $secondAuthor;
+
+    /**
+     * @var \ExtbaseTeam\BlogExample\Domain\Model\Person
+     */
     protected $reviewer;
 
     /**
@@ -77,6 +82,25 @@ class Post extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
     protected $relatedPosts;
 
     /**
+     * 1:1 relation stored as CSV value in this class
+     * @var \ExtbaseTeam\BlogExample\Domain\Model\Info
+     */
+    protected $additionalName;
+
+    /**
+     * 1:1 relation stored as foreign key in Info class
+     * @var \ExtbaseTeam\BlogExample\Domain\Model\Info
+     */
+    protected $additionalInfo;
+
+    /**
+     * 1:n relation stored as CSV value
+     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\ExtbaseTeam\BlogExample\Domain\Model\Comment>
+     * @Extbase\ORM\Lazy
+     */
+    protected $additionalComments;
+
+    /**
      * Constructs this post
      */
     public function __construct()
@@ -86,6 +110,7 @@ class Post extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
         $this->comments = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
         $this->relatedPosts = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
         $this->date = new \DateTime();
+        $this->additionalComments = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
     }
 
     /**
@@ -261,6 +286,22 @@ class Post extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
     /**
      * @return \ExtbaseTeam\BlogExample\Domain\Model\Person
      */
+    public function getSecondAuthor(): ?\ExtbaseTeam\BlogExample\Domain\Model\Person
+    {
+        return $this->secondAuthor;
+    }
+
+    /**
+     * @param \ExtbaseTeam\BlogExample\Domain\Model\Person $secondAuthor
+     */
+    public function setSecondAuthor(\ExtbaseTeam\BlogExample\Domain\Model\Person $secondAuthor): void
+    {
+        $this->secondAuthor = $secondAuthor;
+    }
+
+    /**
+     * @return \ExtbaseTeam\BlogExample\Domain\Model\Person
+     */
     public function getReviewer()
     {
         return $this->reviewer;
@@ -383,6 +424,79 @@ class Post extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
     }
 
     /**
+     * @return ?Info
+     */
+    public function getAdditionalName(): ?Info
+    {
+        return $this->additionalName;
+    }
+
+    /**
+     * @param Info $additionalName
+     */
+    public function setAdditionalName(Info $additionalName): void
+    {
+        $this->additionalName = $additionalName;
+    }
+
+    /**
+     * @return ?Info
+     */
+    public function getAdditionalInfo(): ?Info
+    {
+        return $this->additionalInfo;
+    }
+
+    /**
+     * @param Info $additionalInfo
+     */
+    public function setAdditionalInfo(Info $additionalInfo): void
+    {
+        $this->additionalInfo = $additionalInfo;
+    }
+
+    /**
+     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
+     */
+    public function getAdditionalComments(): \TYPO3\CMS\Extbase\Persistence\ObjectStorage
+    {
+        return $this->additionalComments;
+    }
+
+    /**
+     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $additionalComments
+     */
+    public function setAdditionalComments(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $additionalComments): void
+    {
+        $this->additionalComments = $additionalComments;
+    }
+
+    /**
+     * @param Comment $comment
+     */
+    public function addAdditionalComment(Comment $comment)
+    {
+        $this->additionalComments->attach($comment);
+    }
+
+    /**
+     * Remove all additional Comments
+     */
+    public function removeAllAdditionalComments()
+    {
+        $comments = clone $this->additionalComments;
+        $this->additionalComments->removeAll($comments);
+    }
+
+    /**
+     * @param Comment $comment
+     */
+    public function removeAdditionalComment(Comment $comment)
+    {
+        $this->additionalComments->detach($comment);
+    }
+
+    /**
      * Returns this post as a formatted string
      *
      * @return string
diff --git a/typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/tx_blogexample_domain_model_info.php b/typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/tx_blogexample_domain_model_info.php
new file mode 100644 (file)
index 0000000..47f10d0
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+
+return [
+    'ctrl' => [
+        'title' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xml:tx_blogexample_domain_model_info',
+        'label' => 'name',
+        'tstamp' => 'tstamp',
+        'crdate' => 'crdate',
+        'versioningWS' => true,
+        'languageField' => 'sys_language_uid',
+        'transOrigPointerField' => 'l18n_parent',
+        'transOrigDiffSourceField' => 'l18n_diffsource',
+        'delete' => 'deleted',
+        'sortby' => 'sorting',
+        'enablecolumns' => [
+            'disabled' => 'hidden'
+        ],
+        'iconfile' => 'EXT:blog_example/Resources/Public/Icons/icon_tx_blogexample_domain_model_tag.gif'
+    ],
+    'interface' => [
+        'showRecordFieldList' => 'hidden, name'
+    ],
+    'columns' => [
+        'sys_language_uid' => [
+            'exclude' => true,
+            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
+            'config' => [
+                'type' => 'select',
+                'renderType' => 'selectSingle',
+                'special' => 'languages',
+                'items' => [
+                    [
+                        'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages',
+                        -1,
+                        'flags-multiple'
+                    ],
+                ],
+                'default' => 0,
+            ]
+        ],
+        'l18n_parent' => [
+            'exclude' => true,
+            'displayCond' => 'FIELD:sys_language_uid:>:0',
+            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.l18n_parent',
+            'config' => [
+                'type' => 'select',
+                'renderType' => 'selectSingle',
+                'items' => [
+                    ['', 0],
+                ],
+                'foreign_table' => 'tx_blogexample_domain_model_info',
+                'foreign_table_where' => 'AND tx_blogexample_domain_model_info.pid=###CURRENT_PID### AND tx_blogexample_domain_model_info.sys_language_uid IN (-1,0)',
+                'default' => 0
+            ]
+        ],
+        'l18n_diffsource' => [
+            'config' => [
+                'type' => 'passthrough',
+                'default' => '',
+            ],
+        ],
+        'hidden' => [
+            'exclude' => true,
+            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.visible',
+            'config' => [
+                'type' => 'check',
+                'renderType' => 'checkboxToggle',
+                'items' => [
+                    [
+                        0 => '',
+                        1 => '',
+                        'invertStateDisplay' => true
+                    ]
+                ],
+            ]
+        ],
+        'name' => [
+            'label' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xml:tx_blogexample_domain_model_info.name',
+            'config' => [
+                'type' => 'input',
+                'size' => 20,
+                'eval' => 'trim, required',
+                'max' => 256
+            ]
+        ],
+        'post' => [
+            'config' => [
+                'type' => 'passthrough',
+            ]
+        ],
+    ],
+    'types' => [
+        0 => ['showitem' => 'sys_language_uid, l18n_parent, hidden, name']
+    ],
+];
index 071ad43..f265e93 100644 (file)
@@ -9,6 +9,8 @@ return [
         'crdate' => 'crdate',
         'versioningWS' => true,
         'origUid' => 't3_origuid',
+        'languageField' => 'sys_language_uid',
+        'transOrigPointerField' => 'l10n_parent',
         'prependAtCopy' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.prependAtCopy',
         'delete' => 'deleted',
         'enablecolumns' => [
@@ -20,6 +22,37 @@ return [
         'showRecordFieldList' => 'firstname, lastname, email, avatar'
     ],
     'columns' => [
+        'sys_language_uid' => [
+            'exclude' => true,
+            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
+            'config' => [
+                'type' => 'select',
+                'renderType' => 'selectSingle',
+                'special' => 'languages',
+                'items' => [
+                    [
+                        'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages',
+                        -1,
+                        'flags-multiple'
+                    ],
+                ],
+                'default' => 0
+            ]
+        ],
+        'l10n_parent' => [
+            'displayCond' => 'FIELD:sys_language_uid:>:0',
+            'exclude' => true,
+            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.l18n_parent',
+            'config' => [
+                'type' => 'select',
+                'renderType' => 'selectSingle',
+                'items' => [
+                    ['', 0],
+                ],
+                'foreign_table' => 'tx_blogexample_domain_model_person',
+                'foreign_table_where' => 'AND tx_blogexample_domain_model_person.uid=###REC_FIELD_l10n_parent### AND tx_blogexample_domain_model_person.sys_language_uid IN (-1,0)',
+            ]
+        ],
         'hidden' => [
             'exclude' => true,
             'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.hidden',
@@ -91,7 +124,7 @@ return [
         ],
     ],
     'types' => [
-        '1' => ['showitem' => 'firstname, lastname, email, avatar, tags, tags_special']
+        '1' => ['showitem' => 'sys_language_uid, firstname, lastname, email, avatar, tags, tags_special']
     ],
     'palettes' => [
         '1' => ['showitem' => '']
index b4f156e..fb050f2 100644 (file)
@@ -25,7 +25,7 @@ return [
         'maxSingleDBListItems' => 500
     ],
     'types' => [
-        '1' => ['showitem' => 'sys_language_uid, hidden, blog, title, date, author, content, tags, comments, related_posts']
+        '1' => ['showitem' => 'sys_language_uid, hidden, blog, title, date, author, second_author, content, tags, comments, related_posts, additional_name, additional_info, additional_comments']
     ],
     'columns' => [
         'sys_language_uid' => [
@@ -122,6 +122,28 @@ return [
                 ],
             ],
         ],
+        'second_author' => [
+            'exclude' => true,
+            'label' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xml:tx_blogexample_domain_model_post.second_author',
+            'config' => [
+                'type' => 'group',
+                'internal_type' => 'db',
+                'allowed' => 'tx_blogexample_domain_model_person',
+                'foreign_table' => 'tx_blogexample_domain_model_person',
+                'maxitems' => 1,
+                'fieldControl' => [
+                    'editPopup' => [
+                        'disabled' => false,
+                    ],
+                    'addRecord' => [
+                        'disabled' => false,
+                    ],
+                    'listModule' => [
+                        'disabled' => false,
+                    ],
+                ],
+            ],
+        ],
         'reviewer' => [
             'exclude' => true,
             'label' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xml:tx_blogexample_domain_model_post.reviewer',
@@ -197,5 +219,36 @@ return [
                 'MM_opposite_field' => 'related_posts',
             ]
         ],
+        'additional_name' => [
+            'exclude' => true,
+            'label' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xml:tx_blogexample_domain_model_post.additional_name',
+            'config' => [
+                'type' => 'inline', // this will store the info uid in the additional_name field (CSV)
+                'foreign_table' => 'tx_blogexample_domain_model_info',
+                'minitems' => 0,
+                'maxitems' => 1,
+            ],
+        ],
+        'additional_info' => [
+            'exclude' => true,
+            'label' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xml:tx_blogexample_domain_model_post.additional_info',
+            'config' => [
+                'type' => 'inline', // this will store the post uid in the post field of the info table
+                'foreign_table' => 'tx_blogexample_domain_model_info',
+                'foreign_field' => 'post',
+                'minitems' => 0,
+                'maxitems' => 1,
+            ],
+        ],
+        'additional_comments' => [
+            'exclude' => true,
+            'label' => 'LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xml:tx_blogexample_domain_model_post.additional_comments',
+            'config' => [
+                'type' => 'inline', // this will store the comments uids in the additional_comments field (CSV)
+                'foreign_table' => 'tx_blogexample_domain_model_comment',
+                'minitems' => 0,
+                'maxitems' => 200,
+            ],
+        ],
     ]
 ];
index 3d74357..1667f65 100644 (file)
                        <label index="tx_blogexample_domain_model_post.subtitle">Title</label>
                        <label index="tx_blogexample_domain_model_post.date">Date</label>
                        <label index="tx_blogexample_domain_model_post.author">Author</label>
+                       <label index="tx_blogexample_domain_model_post.second_author">Second author</label>
+                       <label index="tx_blogexample_domain_model_post.reviewer">Reviewer</label>
                        <label index="tx_blogexample_domain_model_post.content">Content</label>
                        <label index="tx_blogexample_domain_model_post.votes">Votes</label>
                        <label index="tx_blogexample_domain_model_post.published">Published</label>
                        <label index="tx_blogexample_domain_model_post.tags">Tags</label>
                        <label index="tx_blogexample_domain_model_post.comments">Comments</label>
                        <label index="tx_blogexample_domain_model_post.related">Related posts</label>
+                       <label index="tx_blogexample_domain_model_post.additional_info">Additional info (inline 1:1 foreign_field)</label>
+                       <label index="tx_blogexample_domain_model_post.additional_name">Additional name (inline 1:1 csv)</label>
+                       <label index="tx_blogexample_domain_model_post.additional_comments">Additional comments (inline 1:n csv)</label>
                        <label index="tx_blogexample_domain_model_person">Person</label>
                        <label index="tx_blogexample_domain_model_person.firstname">Firstname</label>
                        <label index="tx_blogexample_domain_model_person.lastname">Lastname</label>
@@ -40,6 +45,9 @@
                        <label index="tx_blogexample_domain_model_tag">Tag</label>
                        <label index="tx_blogexample_domain_model_tag.name">Name</label>
                        <label index="tx_blogexample_domain_model_tag.posts">Related posts</label>
+                       <label index="tx_blogexample_domain_model_info">Additional Info</label>
+                       <label index="tx_blogexample_domain_model_info.name">Additional name</label>
+                       <label index="tx_blogexample_domain_model_info.post">Post - parent</label>
                        <label index="tx_blogexample_domain_model_dateexample">Date example</label>
                        <label index="fe_users.tx_extbase_type.ExtbaseTeam\BlogExample\Domain\Model\Administrator">Blog Admin (BlogExample)</label>
                </languageKey>
index 7a11bbf..73b3721 100644 (file)
@@ -19,12 +19,16 @@ CREATE TABLE tx_blogexample_domain_model_post (
 
        title varchar(255) DEFAULT '' NOT NULL,
        date int(11) DEFAULT '0' NOT NULL,
-       author int(255) DEFAULT '0' NOT NULL,
-       reviewer int(255) DEFAULT '0' NOT NULL,
+       author int(11) DEFAULT '0' NOT NULL,
+       second_author int(11) DEFAULT '0' NOT NULL,
+       reviewer int(11) DEFAULT '0' NOT NULL,
        content text NOT NULL,
        tags int(11) unsigned DEFAULT '0' NOT NULL,
        comments int(11) unsigned DEFAULT '0' NOT NULL,
-       related_posts int(11) unsigned DEFAULT '0' NOT NULL
+       related_posts int(11) unsigned DEFAULT '0' NOT NULL,
+       additional_name varchar(255) DEFAULT '' NOT NULL,
+       additional_info int(11) DEFAULT '0' NOT NULL,
+       additional_comments varchar(255) DEFAULT '' NOT NULL
 );
 
 #
@@ -107,3 +111,11 @@ CREATE TABLE tx_blogexample_domain_model_dateexample (
        datetime_text varchar(255) DEFAULT '' NOT NULL,
        datetime_datetime datetime
 );
+
+#
+# Table structure for table 'tx_blogexample_domain_model_info'
+#
+CREATE TABLE tx_blogexample_domain_model_info (
+       name varchar(255) DEFAULT '' NOT NULL,
+       post int(11) DEFAULT '0' NOT NULL
+);