madeyourday / contao-rocksolid-custom-elements

RockSolid Custom Elements Contao Extension
http://rocksolidthemes.com/de/contao/plugins/custom-content-elements
MIT License
48 stars 12 forks source link

New DCA Picker? #129

Closed ngdot closed 3 years ago

ngdot commented 3 years ago

Contao Version: 4.9.12

Hi, if I want to use the new picker as inputType for a custom element, I'm getting the error:

The table name must not be empty

[2021-03-03 14:52:14] request.CRITICAL: Uncaught PHP Exception Exception: "The table name must not be empty" at /**/web/vendor/contao/core-bundle/src/Resources/contao/library/Contao/DcaLoader.php line 50 {"exception":"[object] (Exception(code: 0): The table name must not be empty at /**/web/vendor/contao/core-bundle/src/Resources/contao/library/Contao/DcaLoader.php:50)"} []

This is my code:

'foo' => array(
    'label' => array(
        'Foo', 
        ''
    ),
    'inputType' => 'picker',
    'eval' => array(
        'tl_class' => 'clr w50'
    ),
)

I also tried adding 'foreignKey' => 'tl_content.id' and 'relation' => array('type'=>'hasOne', 'load'=>'lazy', 'table'=>'tl_content') same error.

It seems that RSCE doesnt support the new dca picker, any ideas or future plans?

ausi commented 3 years ago

You need to set eval.context because the relations are stored statically for each DCA and can therefore not be retrieved for “dynamic” fields: 'eval' => ['context' => 'dc.tl_content']

But it looks like there is an issue in the core too, because the value doesn’t get saved and the preview is not properly rendered.

These lines https://github.com/contao/contao/blob/29f2d850957bf626a9304423962f49fb706abd0f/core-bundle/src/Resources/contao/widgets/Picker.php#L177-L182 need to be replaced with something like this IMO:

if (substr($this->context ?? '', 0, 3) === 'dc.') 
{
    $strRelatedTable = substr($this->context, 3);
}
else 
{
    $strRelatedTable = $this->getRelatedTable();
}

if (!$strRelatedTable)
{
    return array_combine((array) $this->varValue, (array) $this->varValue);
}
ngdot commented 3 years ago

Yep, that's it! Works fine :) Thanks.

ausi commented 3 years ago

Should get fixed by https://github.com/contao/contao/pull/2837