mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-10 00:56:12 +01:00

[FEATURE] Add Tea.image as a FAL example (#15)

This commit is contained in:
Oliver Klee 2018-05-25 22:39:33 +02:00 committed by GitHub
parent 9b10334c0d
commit 09dc1281ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 109 additions and 3 deletions

View file

@ -2,7 +2,9 @@
declare(strict_types = 1); declare(strict_types = 1);
namespace OliverKlee\Tea\Domain\Model\Product; namespace OliverKlee\Tea\Domain\Model\Product;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy;
/** /**
* This class represents a tea (flavor), e.g., "Earl Grey". * This class represents a tea (flavor), e.g., "Earl Grey".
@ -21,6 +23,12 @@ class Tea extends AbstractEntity
*/ */
protected $description = ''; protected $description = '';
/**
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* @lazy
*/
protected $image = null;
/** /**
* @return string * @return string
*/ */
@ -56,4 +64,26 @@ class Tea extends AbstractEntity
{ {
$this->description = $description; $this->description = $description;
} }
/**
* @return FileReference|null
*/
public function getImage()
{
if ($this->image instanceof LazyLoadingProxy) {
$this->image = $this->image->_loadRealInstance();
}
return $this->image;
}
/**
* @param FileReference $image
*
* @return void
*/
public function setImage(FileReference $image)
{
$this->image = $image;
}
} }

View file

@ -13,10 +13,10 @@ return [
'searchFields' => 'title, description', 'searchFields' => 'title, description',
], ],
'interface' => [ 'interface' => [
'showRecordFieldList' => 'title, description', 'showRecordFieldList' => 'title, description, image',
], ],
'types' => [ 'types' => [
'1' => ['showitem' => 'title, description'], '1' => ['showitem' => 'title, description, image'],
], ],
'columns' => [ 'columns' => [
'title' => [ 'title' => [
@ -38,5 +38,21 @@ return [
'eval' => 'trim', 'eval' => 'trim',
], ],
], ],
'image' => [
'label' => 'LLL:EXT:tea/Resources/Private/Language/locallang_db.xlf:tx_tea_domain_model_product_tea.image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'image',
[
'maxitems' => 1,
'appearance' => [
'collapseAll' => true,
'useSortable' => false,
'enabledControls' => [
'hide' => false,
],
],
]
),
],
], ],
]; ];

View file

@ -15,6 +15,10 @@
<source>Description</source> <source>Description</source>
<target>Beschreibung</target> <target>Beschreibung</target>
</trans-unit> </trans-unit>
<trans-unit id="tx_tea_domain_model_product_tea.image">
<source>Image</source>
<target>Bild</target>
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>

View file

@ -12,6 +12,9 @@
<trans-unit id="tx_tea_domain_model_product_tea.description"> <trans-unit id="tx_tea_domain_model_product_tea.description">
<source>Description</source> <source>Description</source>
</trans-unit> </trans-unit>
<trans-unit id="tx_tea_domain_model_product_tea.image">
<source>Image</source>
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>

View file

@ -10,6 +10,21 @@
<uid>2</uid> <uid>2</uid>
<pid>1</pid> <pid>1</pid>
<title>Assam</title> <title>Assam</title>
<description>Dark ans strong.</description> <description>Dark and strong.</description>
</tx_tea_domain_model_product_tea> </tx_tea_domain_model_product_tea>
<tx_tea_domain_model_product_tea>
<uid>3</uid>
<pid>1</pid>
<title>Gunpowder</title>
<description>Bitter and very green.</description>
<image>1</image>
</tx_tea_domain_model_product_tea>
<sys_file_reference>
<uid>1</uid>
<pid>1</pid>
<uid_foreign>3</uid_foreign>
<tablenames>tx_tea_domain_model_product_tea</tablenames>
<fieldname>image</fieldname>
<l10n_diffsource></l10n_diffsource>
</sys_file_reference>
</dataset> </dataset>

View file

@ -6,6 +6,7 @@ use Nimut\TestingFramework\TestCase\FunctionalTestCase;
use OliverKlee\Tea\Domain\Model\Product\Tea; use OliverKlee\Tea\Domain\Model\Product\Tea;
use OliverKlee\Tea\Domain\Repository\Product\TeaRepository; use OliverKlee\Tea\Domain\Repository\Product\TeaRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Object\ObjectManager;
/** /**
@ -84,4 +85,20 @@ class TeaRepositoryTest extends FunctionalTestCase
static::assertSame('Earl Grey', $model->getTitle()); static::assertSame('Earl Grey', $model->getTitle());
static::assertSame('Fresh and hot.', $model->getDescription()); static::assertSame('Fresh and hot.', $model->getDescription());
} }
/**
* @test
*/
public function fillsImageRelation()
{
$this->importDataSet(__DIR__ . '/../Fixtures/Product/Tea.xml');
$uid = 3;
/** @var Tea $model */
$model = $this->subject->findByUid($uid);
$image = $model->getImage();
static::assertInstanceOf(FileReference::class, $image);
static::assertSame(1, $image->getUid());
}
} }

View file

@ -4,6 +4,7 @@ namespace OliverKlee\Tea\Tests\Unit\Domain\Model\Product;
use Nimut\TestingFramework\TestCase\UnitTestCase; use Nimut\TestingFramework\TestCase\UnitTestCase;
use OliverKlee\Tea\Domain\Model\Product\Tea; use OliverKlee\Tea\Domain\Model\Product\Tea;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
/** /**
@ -68,4 +69,23 @@ class TeaTest extends UnitTestCase
static::assertSame($value, $this->subject->getDescription()); static::assertSame($value, $this->subject->getDescription());
} }
/**
* @test
*/
public function getImageInitiallyReturnsNull()
{
static::assertNull($this->subject->getImage());
}
/**
* @test
*/
public function setImageSetsImage()
{
$model = new FileReference();
$this->subject->setImage($model);
static::assertSame($model, $this->subject->getImage());
}
} }

View file

@ -10,6 +10,7 @@ CREATE TABLE tx_tea_domain_model_product_tea (
title varchar(255) DEFAULT '' NOT NULL, title varchar(255) DEFAULT '' NOT NULL,
description varchar(2000) DEFAULT '' NOT NULL, description varchar(2000) DEFAULT '' NOT NULL,
image int(11) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (uid), PRIMARY KEY (uid),
KEY parent (pid) KEY parent (pid)