Accessing editable variable in brick controller

1k Views Asked by At

I would like to use a value of my editable in my brick controller. How can I do this?

view.html.php

<?php
/**
 * @var \Pimcore\Templating\PhpEngine $this
 * @var \Pimcore\Templating\PhpEngine $view
 * @var \Pimcore\Templating\GlobalVariables $app
 */
?>    
<?php echo $this->numeric("parentId"); ?>

Controller

<?php

namespace AppBundle\Document\Areabrick;

use Pimcore\Model\Document\Tag\Area\Info;

class GalleryCaroussel extends AbstractAreabrick {
    public function action(Info $info){
    }
}

How can I access the numeric variable "parentId" in my controller? I've tryied it with alle possible methods of the injected Info object. But nothing seems to work.

Also on the official site is nothing documented.

I'm using pimcore v. 5.

1

There are 1 best solutions below

2
On BEST ANSWER

EDIT: This is a much better and easier way to do this than the one I initially posted below:

$field = $this->getDocumentTag($info->getDocument(), 'numeric', 'parentId');

I am leaving this here in case someone wants to understand how the names are built:

$view = $info->getView();
$document = $view->get('document');

/** @var \Pimcore\Document\Tag\NamingStrategy\NestedNamingStrategy $strategy */
$strategy = $this->container->get('pimcore.document.tag.naming.strategy');

$brickName = $info->getTag()->getName();
$index = $info->index + 1;
$editableName = 'parentId';
$brickType = $this->id;

$elementId = $strategy->buildChildElementTagName($editableName, $brickType, [$brickName], $index);
$element = $document->getElement($elementId);
$editableValue = $element->number;