codefog / contao-haste

Haste is a collection of tools and classes to ease working with Contao
http://codefog.pl/extension/haste.html
MIT License
43 stars 24 forks source link

Haste\Model\Relations::getRelation should check if `relation` for field is array #110

Closed fatcrobat closed 7 years ago

fatcrobat commented 7 years ago

In contao 4.4.3 i discovered when using pageTree picker in tl_module, where jumpTo field in dca is true, without any configuration.

In Haste\Model\Relations::getRelation on line 649 you access the relation via $arrField = &$GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['relation'];

The method should catch those behaviors by changing the line to:

if (!is_array($GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['relation'])) {
    static::$arrRelationsCache[$strCacheKey] = $varRelation;
    return static::$arrRelationsCache[$strCacheKey];
}

$arrField = &$GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['relation'];
qzminski commented 7 years ago

Sorry, I don't get what you mean. Can you elaborate?

fatcrobat commented 7 years ago

I am using contao 4.4.4 and when i try to change the rootPage with the DCAPicker on my navigation module i get the following error:

Warning: Cannot use a scalar value as an array
in vendor/codefog/contao-haste/library/Haste/Model/Relations.php (line 648)

$strCacheKey = $strTable . '_' . $strField;        
if (!isset(static::$arrRelationsCache[$strCacheKey])) {            
    $varRelation = false;            

    $arrField = &$GLOBALS['TL_DCA'][$strTable]['fields'][$strField]['relation'];           

    if (is_array($arrField) && isset($arrField['table']) && $arrField['type'] == 'haste-ManyToMany') {
        $varRelation = [];              

        // The relations table

I debugged the action and discovered, that $GLOBALS['TL_DCA']['tl_module']['fields']['rootPage'] was not an array, but 1. This only happens within the DCAPicker when you change the page selection for example and apply your changes.

aschempp commented 7 years ago

Looks like a Contao/extension bug to me, but I bypassed it in Haste in 2e7c02cadc42581aa1a1b475efbf9f7bc2991eb4