-->

Extending sys_file_reference (FAL)

2019-05-30 14:57发布

问题:

I want to extend sys_file_reference with a own field. So i created the field and the TCA. In the backend the field is usable, but i cant refer to the field in my fluid template.

ext_tables.php:

CREATE TABLE sys_file_reference (
 nofollow int(11) DEFAULT '0' NOT NULL,
);

Configuration/TCA/Overrides/sys_file_reference.php:

$tempColumns = array(
    'nofollow' => array(
        'exclude' => 1,
        'l10n_mode' => 'mergeIfNotBlank',
        'label' => 'Link als Nofollow?',
        'config' => array(
            'type' => 'check',
            'default' => '0'
        )
    )
);
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file_reference',$tempColumns,1);
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette('sys_file_reference', 'imageoverlayPalette','--linebreak--,nofollow','after:description');

As far it works in the backend.

Classes/Domain/Model/MyFileReference.php

<?php
namespace LISARDO\Foerderland\Domain\Model;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;

class MyFileReference extends FileReference {

    /**
     * nofollow
     *
     * @var integer
     */
    protected $nofollow;


    /**
     * Returns the nofollow
     *
     * @return integer $nofollow
     */
    public function getNofollow() {
        return $this->nofollow;
    }

    /**
     * Sets the nofollow
     *
     * @param integer $nofollow
     * @return void
     */
    public function setNofollow($nofollow) {
        $this->nofollow = $nofollow;
    }
}

in my setup:

config.tx_extbase.persistence.classes {
    LISARDO\Foerderland\Domain\Model\MyFileReference {
        mapping {
            tableName = sys_file_reference
        }
    }
}

In Fluid i get image.uid oder image.link but image.nofollow is always empty. What did i wrong? I presume the mapping is not correct ...


Well i got the right answer and noticed that i made a mistake and explained it wrong in some ways. First: it is not a normal extbase extension but simply a own content element. So i do not have a own model for my extension where i can inject the implementation as Georg and Victor proposed. I simply had to change the syntax in fluid: {image.properties.nofollow} does the job.

And i recognized that i dont need most of my code:

  • Classes/Domain/Model/MyFileReference.php is not necessary
  • config.tx_extbase.persistence.classes is not necessary too

Only the TCA-Code is needed and a different syntax in fluid.

But i cant figure out why this syntax works and the normal syntax dont.

Thanks for all answers!

回答1:

As I known you can access your own properties in fluid with {image.properties.nofollow}.



回答2:

Are you referencing your sys_file_reference implementation as well?

So, that could look like that

/**
 *
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\LISARDO\Foerderland\Domain\Model\MyFileReference>
 * @lazy
 */
protected $media;


回答3:

You need to refer to your custom implementation.

Do it either, like Georg Ringer suggests in his answer, or you can substitute the class on TS level, like this:

plugin.tx_yourext {
    objects {
        TYPO3\CMS\Extbase\Domain\Model\FileReference {
            className = LISARDO\Foerderland\Domain\Model\MyFileReference
        }
    }
}

This will automatically instantiate MyFileReference instead of core's FileReference in all properties, that refer to it, also includes @inject and ObjectManager->get() calls.

If you want to do it on global level (for all plugins, including core), you can just change tx_yourext to tx_extbase in TS above.



标签: typo3 fal