TYPO3 9 Extbase EXT originalResource для FileReference всегда имеет значение NULL. Почему? - PullRequest
0 голосов
/ 08 января 2020

Я разрабатываю свое собственное расширение. В этом расширении можно добавлять изображения в элемент контента. В представлении Backend работает все отлично. В БД ссылка sys_file на мою таблицу базы данных через sys_file_reference тоже выглядит хорошо. Но когда я делаю {_all} в шаблоне, originalResource файла имеет значение NULL.

Может ли кто-то сказать мне, что мне не хватает?

Вот код моего расширения : ext_tables. sql

#
# Table structure for table 'tx_redspaceproduct_domain_model_product'
#
CREATE TABLE tx_redspaceproduct_domain_model_product (

uid int(11) unsigned NOT NULL AUTO_INCREMENT,
pid int(11) unsigned DEFAULT '0' NOT NULL,

number int(5) DEFAULT '0' NOT NULL,
name varchar(255) DEFAULT '' NOT NULL,
slug varchar(255) DEFAULT '' NOT NULL,
subname varchar(255) DEFAULT '' NOT NULL,
image int(11) unsigned NOT NULL default '0',
flyer int(11) unsigned NOT NULL default '0',
featureteaser text DEFAULT '',
description text DEFAULT '',
specifications text DEFAULT '',
features text DEFAULT '',
accuracy text DEFAULT '',
category int(11) unsigned DEFAULT '0' NOT NULL,
type int(11) unsigned DEFAULT '0' NOT NULL,
sibling int(11) unsigned DEFAULT '0' NOT NULL,
related int(11) unsigned DEFAULT '0' NOT NULL,
accessory int(11) unsigned DEFAULT '0' NOT NULL,
package int(11) unsigned DEFAULT '0' NOT NULL,
download int(11) unsigned DEFAULT '0' NOT NULL,

hidden int(1) unsigned DEFAULT '0' NOT NULL,
deleted int(1) unsigned DEFAULT '0' NOT NULL,

PRIMARY KEY (uid),
FOREIGN KEY (category) REFERENCES tx_redspaceproduct_domain_model_category(uid),
FOREIGN KEY (type) REFERENCES tx_redspaceproduct_domain_model_type(uid)

);

tx_redspaceproduct_domain_model_product. php

'image' => [
        'exclude' => true,
        'label' => 'LLL:EXT:redspace_product/Resources/Private/Language/locallang_db.xlf:tx_redspaceproduct_domain_model_product.image',
        'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
            'image',
            [
                'appearance' => [
                    'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference'
                ],
                'overrideChildTca' => [
                    'types' => [
                        'foreign_types' => [
                            '0' => [
                                'showitem' => '
                                --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                                --palette--;;filePalette'
                            ],
                            \TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
                                'showitem' => '
                                --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                                --palette--;;filePalette'
                            ],
                            \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
                                'showitem' => '
                                --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                                --palette--;;filePalette'
                            ],
                            \TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
                                'showitem' => '
                                --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                                --palette--;;filePalette'
                            ],
                            \TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
                                'showitem' => '
                                --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                                --palette--;;filePalette'
                            ],
                            \TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
                                'showitem' => '
                                --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                                --palette--;;filePalette'
                            ]
                        ],
                    ],
                ],
                'maxitems' => 99
            ],
            $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
        ),
    ],

Product. php

<?php
namespace REDSPACE\RedspaceProduct\Domain\Model;

use \TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use \TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use \TYPO3\CMS\Extbase\Domain\Model\FileReference;

/***
 *
 * This file is part of the "Redspace Product" Extension for TYPO3 CMS.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 *  (c) 2019 Robin Probst <web@redspace.ch>, REDSPACE AG
 *
 ***/

/**
 * Product
*/
class Product extends AbstractEntity
{

    /**
     * image
     * 
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<TYPO3\CMS\Extbase\Domain\Model\FileReference>
     * @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
     */
    protected $image = null;

    /**
     * __construct
     */
    public function __construct()
    {
        $this->initStorageObjects();
    }

    /**
     * Initializes all ObjectStorage properties
     * 
     * @return void
     */
    protected function initStorageObjects()
    {
        $this->file = new ObjectStorage();
    }

    /**
     * Returns the image
     * 
     * @return ObjectStorage<FileReference> $image
     */
    public function getImage()
    {
        return $this->image;
    }

    /**
     * Sets the image
     * 
     * @param ObjectStorage<FileReference> $image
     * @return void
     */
    public function setImage(ObjectStorage $image)
    {
        $this->image = $image;
    }
}

ProductRepository. php:

<?php
namespace REDSPACE\RedspaceProduct\Domain\Repository;

use \TYPO3\CMS\Extbase\Persistence\Repository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;

/***
 *
 * This file is part of the "Redspace Product" Extension for TYPO3 CMS.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 *  (c) 2019 Robin Probst <web@redspace.ch>, REDSPACE AG
 *
 ***/

/**
 * The repository for Products
 */
class ProductRepository extends Repository
{
    protected $tableName = 'tx_redspaceproduct_domain_model_product';

    public function getProductOfCategory($category) {
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)- >getQueryBuilderForTable($this->tableName);
        $statement = $queryBuilder
            ->select('*')
            ->from($this->tableName)
            ->where($queryBuilder->expr()->like('category', $category))
            ->execute();

        $rows = $statement->fetchAll();

        return $rows;
    }

    public function getFlyerIdentifier($uid) {
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)- >getQueryBuilderForTable($this->tableName);
        $statement = $queryBuilder
            ->select('identifier')
            ->from('sys_file')
            ->leftJoin('sys_file','sys_file_reference','sys_file_reference',$queryBuilder->expr()->eq('sys_file_reference.uid_local', $queryBuilder->quoteIdentifier('sys_file.uid')))
            ->where($queryBuilder->expr()->eq('sys_file_reference.uid_foreign', $uid))
            ->andWhere($queryBuilder->expr()->eq('extension', '"pdf"'))
            ->execute();

        $rows = $statement->fetchAll();

        return $rows;
    }
}

Это вывод f: debug:
This is the Output of f:debug:

Журнал устаревания: Deprecation Log

1 Ответ

1 голос
/ 09 января 2020

вы можете получить доступ к originalResource в debug-ViewHelper, если вызовите его напрямую:

<f:debug>{image.originalResource}</f:debug>

Причина: https://forge.typo3.org/issues/66727#note -2

...