Skip to content

Commit

Permalink
[TASK] Extend blog_example with relations
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
tmotyl authored and maddy2101 committed Aug 30, 2018
1 parent d070ae3 commit 973fead
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 5 deletions.
@@ -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;
}
}
Expand Up @@ -42,6 +42,11 @@ class Post extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
*/
protected $author;

/**
* @var \ExtbaseTeam\BlogExample\Domain\Model\Person
*/
protected $secondAuthor;

/**
* @var \ExtbaseTeam\BlogExample\Domain\Model\Person
*/
Expand Down Expand Up @@ -76,6 +81,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
*/
Expand All @@ -86,6 +110,7 @@ public function __construct()
$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();
}

/**
Expand Down Expand Up @@ -258,6 +283,22 @@ public function getAuthor()
return $this->author;
}

/**
* @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
*/
Expand Down Expand Up @@ -382,6 +423,79 @@ public function getRelatedPosts()
return $this->relatedPosts;
}

/**
* @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
*
Expand Down
@@ -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']
],
];
Expand Up @@ -9,6 +9,8 @@
'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' => [
Expand All @@ -20,6 +22,37 @@
'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',
Expand Down Expand Up @@ -91,7 +124,7 @@
],
],
'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' => '']
Expand Down

0 comments on commit 973fead

Please sign in to comment.