1
votes

FYI, i'm a TYPO3 rookie :) I'm making my own extbase/fluid extension in my TYPO3 personal website to manage galleries. For now, i'm following this documentation : Developing TYPO3 Extensions with Extbase and Fluid

For now, I only built 2 classes in Domain/Model :

  • Galery.php
  • Picture.php.

Variables are set, getters/setters too.

I well understood that I need to link both within a relationship ("1:n" ?) but I don't use the Extension Builder and want to understand by myself how to do that. I guess I have to edit the Gallery.php model to explain what is the relation I want to implement, but can't understand how to do.

Any help ?

3

3 Answers

1
votes

A great way to learn how to do this is to create an extension using the Extension Builder and then read the generated code.

If you want to add the relationship on your own, you would need to edit the ext_tables.sql and add the columns to your TCA and in your models. Read chapter 6 of the book you mentioned and you'll find out what to do.

1
votes

You already received some good answers.

Additional points (for programming a slideshow extension):

  • You might want to look at using a property of type FileReference in your Picture. You can also select that in the extension_builder. Your model might then contain something like this:

PictureModel.php:

/**
 * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
 * @cascade remove
 */    
 protected $image = null;
  • If you use 1:n for Gallery / Picture it means your images can only be in one Gallery at a time. An unnecessary restriction. I would suggust using m:n (but that is actually a general database modeling question).
  • For m:n you need an extra table for the relations (by convention called something like tx_slideshow_gallery_picture_mm). It is definitely easier to let the extension_builder create that for you. Manually you would need to change at least the database model (ext_tables.sql), the Model and TCA. Especially the TCA can be a bit tricky to write from scratch.

Example TCA:

'picture' => [
                'exclude' => true,
                'label' => 'LLL:EXT:uniolslideshow/Resources/Private/Language/locallang_db.xlf:tx_uniolslideshow_domain_model_gallery.picture',
                'config' => [
                            'type' => 'select',
                            'renderType' => 'selectMultipleSideBySide',
                            'foreign_table' => 'tx_uniolslideshow_domain_model_picture',
                            'MM' => 'tx_uniolslideshow_gallery_picture_mm',
                            'size' => 10,
                            'autoSizeMax' => 30,
                            'maxitems' => 9999,
                            'multiple' => 0,
                            'wizards' => [
                                // the fun starts here ...
  • Later, you might decide that you don't even need an extra Picture class but just use a list of FileReferences ... but for educational purposes I would recommend to follow your initial approach.
  • Trying to understand how things works instead of using a "builder" to create things for you is admirable, but consider that in TYPO3 a numer of files are necessary to create a model (TCA, Model, Repository, ext_tables.sql). Thus, doing everything manually can be tedious and errorprone. A combination of reading the docs, using extension_builder and modifying code yourself, also looking at existing extensions is in my opinion the way to go for education purposes. Later, a combination of using extension_builder to create a skeleton and then modifying it yourself works best for me.
0
votes

Maybe the blog example can help with relation: A journey through the Blog Example. https://docs.typo3.org/typo3cms/ExtbaseFluidBook/3-BlogExample/Index.html