Question

I was just extending an existing Typo3 4.7 Extension with two own Model classes. It runs quite well, Backendforms look like expected BUT when I try to access some SubObjects of my Model Classes in the templates via Object Accessor {class.subclass.attribute} I am not able to access the attribute. The problem that showed me, is that the Object for the Attribute "mainColor" for example in the Object Storage is a HashCode, which contains the Actual Object I want to access ( the object following the hashcode is the correct related object from the database ).

Does anyone of you have an Idea where the problem might be ?

If any more Code Snippets are needed, I will deliver them. But since I really don't know where the problem comes from, I prefer to not deliver a wall of Code.

Domain/Model/Cluster.php

/**
 * Main Color of Cluster
 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Alp_Domain_Model_ColorCombination> $mainColor
 */
protected $mainColor;

/**
 * Subcolors of Cluster
 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Alp_Domain_Model_ColorCombination> $subColors
 */
protected $subColors;

/**
 * Constructor
 * @return void
 */
public function __construct() {
    $this->initStorageObjects();
}

/**
 * Initializes all Tx_Extbase_Persistence_ObjectStorage properties.
 * @return void
 */
protected function initStorageObjects() {
    $this->subColors = new Tx_Extbase_Persistence_ObjectStorage();
    $this->mainColor = new Tx_Extbase_Persistence_ObjectStorage();
}

TCA/Cluster.php

'sub_colors' => array(
    'exclude' => 1,
    'label' => 'Sub-Colors',
    'config' => array(
        // edited
        'type' => 'inline',

        'internal_type' => 'db',
        'allowed' => 'tx_alp_domain_model_colorcombination',
        'foreign_table' => 'tx_alp_domain_model_colorcombination',
        'MM' => 'tx_alp_cluster_subcolorcombination_mm',
        'MM_opposite_field' => 'parent_cluster',
        'size' => 6,
        'autoSizeMax' => 30,
        'maxitems' => 9999,
        'multiple' => 0,
        'selectedListStyle' => 'width:250px;',
        'wizards' => array(
            '_PADDING' => 5,
            '_VERTICAL' => 1,
            'suggest' => array(
                'type' => 'suggest',
            ),
        ),
    ),
),

Fluid Debug Output can be found here:

http://i60.tinypic.com/28kluub.jpg

Thanks for any help :( And sorry for my bad English and this is my first question here, hope I did it right ;)

Was it helpful?

Solution

Unless you have a 1:1 relation from a model to a sub model, you cannot access the sub model because the sub model is an ObjectStorage.

Example:

Domain/Model/Cluster.php

/**
 * Main Color of Cluster
 * @var Tx_Alp_Domain_Model_ColorCombination $mainColor
 */
protected $mainColor;

This means that the Cluster model has exacly one main color (mind the annotation), this is a 1:1 relation.

Therefore using {cluster.mainColor.property} will work.

What you are doing is:

Domain/Model/Cluster.php

/**
 * Main Color of Cluster
 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Alp_Domain_Model_ColorCombination> $mainColor
 */
protected $mainColor;

This means that every Cluster can have multiple main colors, this is a 1:n relation. Therefore you must iterate through the mainColors (and call the property $mainColors):

<f:for each="{cluster.mainColors}" as="mainColor">
   {mainColor.property}
</f:for>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top