简体   繁体   English

TYPO3 9 Extbase EXT originalResource of FileReference 始终为 NULL。 为什么?

[英]TYPO3 9 Extbase EXT originalResource of FileReference is always NULL. Why?

I'm developing my own Extension.我正在开发自己的扩展。 In this Extension it is possible to add Images to a content element.在此扩展中,可以将图像添加到内容元素。 In the Backend view everithing is working fine.在后端视图中,一切正常。 In the DB the reference of sys_file to my database table via sys_file_reference look good too.在数据库中,sys_file 通过 sys_file_reference 对我的数据库表的引用看起来也不错。 But when i make an {_all} in the template, the originalResource of the File is NULL.但是当我在模板中创建一个 {_all} 时,文件的 originalResource 为 NULL。

Can somone tell me, what I'm missing?有人能告诉我,我错过了什么吗?

Here is some code of my Extension: ext_tables.sql这是我的扩展的一些代码: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 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

<?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: 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;
    }
}

This is the Output of f:debug:这是 f:debug 的输出:
这是 f:debug 的输出:

Deprecation Log:弃用日志: 弃用日志

you can access the originalResource in the debug-ViewHelper if you call it directly:如果直接调用,可以访问 debug-ViewHelper 中的 originalResource:

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

Reason: https://forge.typo3.org/issues/66727#note-2原因: https : //forge.typo3.org/issues/66727#note-2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM