0

I have the following problem and I'm sure some of you will mark this question as duplicate but I couldn't find a specific answer for my problem.

I have an extension and I want to add images / pdf's etc. using the FAL.

According to tutorials I have to config the TCA. Well, the docs are sh.. about that point and the tutorials are based on the knowledge of TCA.

I also have to use some TypoScript, which I haven't used to this point.

Ok, as far as I got here's my question: Where do I edit the TCA? I have a file named ext_tables where I can see $GLOBALS['TCA']. I also have a directory TCA with some files in it (only filled with $GLOBALES['TCA'].

And after that, how do I access these datas? I need to build a tree in the inside of a modal (pop-up is also possible)

I know these questions sound horribly easy but I couldn't find a tutorial which could explain anything at all.

I appreciate all help :)

Thanks a lot.

Daniel
  • 6,916
  • 2
  • 36
  • 47
PaddaelsM
  • 457
  • 2
  • 14

1 Answers1

1

Your question is king of vague:

What exactly did you try so far?

Which files did you change?

Do you need the files inside your FLUIDTEMPLATE, inside your extbase controller or somewhere else?


Steps to add FAL fields to your extension

Extend the database (typo3conf/ext/yourExtFolder/ext_tables.sql):

CREATE TABLE your_database_table (   
    your_fal_field int(11) unsigned DEFAULT '0' NOT NULL  
)

Extend the TCA:

If you extend an existing table from another extension you have the extend the TCA inside typo3conf/ext/yourExtFolder/Configuration/TCA/Overrides/your_database_table.php

Example (extend tt_content):

$newColumn = [
    'field_name' => [
        'image' => [                
            'label'   => 'Image',
            'config'  => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', [
               'appearance' => [
                    'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference',
                ],
                'minitems'   => 0,
                'maxitems'   => 1,
            ], $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),
        ],
   ],
];
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $newColumn);

If you add the field to your own extension your have to extend typo3conf/ext/yourExtFolder/Configuration/TCA/your_database_table.php. Example (from TYPO3 core be_users TCA - shortened version):

return [
    'ctrl' => [
        'label' => 'username',
        'descriptionColumn' => 'description',
    ],
    'columns' => [
        'username' => [
            'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:be_users.username',
            'config' => [
                'type' => 'input',
                'size' => 20,
                'max' => 50,
                'eval' => 'nospace,trim,lower,unique,required',
                'autocomplete' => false,
            ]
        ],
        'avatar' => [
            'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:be_users.avatar',
            'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
                'avatar',
                ['maxitems' => 1],
                $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
            )
        ],
    ],
    // Removed more `columns`, `types` and `palettes` config         
];

The important part is the definition of avatar which uses the getFileFieldTCAConfig function.

Extend your extbase model (typo3conf/ext/yourExtFolder/Classes/Domain/Model/YourClass.php)

Simplified snippet from keinerweiss.de:

class YourClass extends TheModelYouWantToExtend or \TYPO3\CMS\Extbase\DomainObject\AbstractEntity  {
    // ...

    /**
     * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
     */
    protected $yourField;

    /**
     * Returns the image
     *
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $image
     */
    public function getYourField() {
            return $this->yourField;
    }

    /**
     * Sets the image
     *
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $image
     * @return void
     */
    public function setYourField($image) {
            $this->yourField = $yourField;
    }       
}

Use your images in Fluid (From t3-developer.com):

<f:for each="{mymodel.mypictures}" as="picture">    
    <f:image src="{mypicture.image.uid}" alt="" treatIdAsReference="TRUE" /> 
</f:for>

More links (english):

https://gist.github.com/maddy2101/5668835

http://blog.scwebs.in/typo3/typo3-fal-file-abstraction-layer-in-extbasefluid-extension

More links(german):

http://keinerweiss.de/755-typo3-fal-in-einer-eigenen-extbasefluid-extension-einsetzen.html

http://t3-developer.com/ext-programmierung/techniken-in-extensions/fal-in-typo3-extensions-verwenden/

http://t3g.at/extbase-bilder-fal-in-extension-integrieren/

  • Extend database `CREATE TABLE your_database_table (your_fal_field int(11) unsigned DEFAULT '0' NOT NULL)`. It's only a counter for references. – Heinz Schilling May 07 '17 at 06:19
  • Hi, thanks for your help but that's exactly what i found so far - and already did change. When you add a new page to your website, you can also add text and images. When you klick on a button to "add media files" it opens a pop-up with a list of existing files. That's exactly what i need. And that's the part which no tutorial could tell me so far. – PaddaelsM May 12 '17 at 10:51
  • I'm a bit confused now. :-) Do you see the additional field, but the "add media files" button is missing or is still the whole field missing? My answer should create exactly the field you described (including the Add media files button and the popup). The wizard is configured by getFileFieldTCAConfig. Where exactly do you need the additional field? Pages? Existing content element? A custom content element you created? – Christoph Bessei May 13 '17 at 11:09
  • Hi Christoph, I'm not using Flexforms or any orther form. It was an existing extension created by using ExtensionBuilder. Therefore there is only a template which I have to change manually. – PaddaelsM May 14 '17 at 21:23
  • Hi Patrick! I never talked about flexform, getFileFieldTCAConfig is also used for "normal" fields. Can you pleast post the current state? What exactly did you try? Is the whole field missing just the "add media files" wizard? Maybe upload your extension so I can check? – Christoph Bessei May 16 '17 at 12:16