globalParams -Areablock


#1

PIMCORE v5.4.4
Hi!
I’m trying to use globalParams in my areablock,
https://pimcore.com/docs/5.x/Development_Documentation/Documents/Editables/Areablock/index.html#page_Integrate-an-Areablock-in-a-Template

But I get the following ERROR when i add globalParams to my Areabrick:

Warning: Invalid argument supplied for foreach()

Any help please!?
Regards M.Ali


#2

I think I found the issue for this, globalParams expect the value to be an array not a string, exactly as params if we look at the code at https://github.com/pimcore/pimcore/commit/0e0cc388ef705e780d3d7e9190b2366ba83451d4

like:

“globalParams” => [
“myGlobalParam” => [“Global param value”]
],

But the return vill be an array and not a string:
array1:[ 0 => "Global param value" ]


#3

The outputEditmodeOptions should have a one more if else sats:

vendor/pimcore/pimcore/models/Document/Tag/Areablock.php

protected function outputEditmodeOptions(array $options, $return = false)
    {
        // clean up invalid brick editmode options
        if (array_key_exists('options', $options)) {
            foreach (['params', 'globalParams'] as $paramKey) {
                if (array_key_exists($paramKey, $options['options'])) {
                    $validOptions = ['forceEditInView', 'editWidth', 'editHeight'];
                    foreach ($options['options'][$paramKey] as $brickName => $params) {

                        if ($paramKey == 'globalParams') {
                            if (!in_array($brickName, $validOptions)) {
                                unset($options['options'][$paramKey][$brickName]);
                            }
                        } else {
                            foreach ($params as $key => $val) {
                                if (!in_array($key, $validOptions)) {
                                    unset($options['options'][$paramKey][$brickName][$key]);
                                }
                            }
                        }
                    }
                }
            }
        }

        parent::outputEditmodeOptions($options, $return);
    }

Now it is working fine for me!


#4

I hope Pimcore kan get it fix with next release !