Retrieve editables value in Areabricks action()


#1

Hi,

In v4 it was possible to fetch an editables value in action.php with $this->view->textarea(‘test’)->getValue().

Is there any chance to achieve the same in v5? I need to get values out of the view in my Areabricks action() method.

Thx & BR,
Alex


#2

Found it: There is a method getDocumentTag() in all Areabricks.


#3

This was the shortest way I found to do that

Could anyone confirm if this is the only way of doing it? it seems a little long…

$this->getDocumentTag($info->getDocument(), 'href', 'mainNode')->getData()


#4

Was the only solution I found as well. I don’t think there is a shorter solution.

Personally I implemented a base areabrick which has magic getters to retrieve the tag. It makes the code a little bit shorter and you can use it like in the view

E.g. $this->input($document, ‘title’)


#5

Thanks @leuchtdiode!

Would you share that please? That looks exactly what I am looking for. I’m new to Pimcore so any extra help will help a lot.

Thanks!


#6

So here are the code snippets:

<?php
namespace Test;

use Pimcore\Extension\Document\Areabrick\AbstractTemplateAreabrick;

abstract class BaseAreabrick extends AbstractTemplateAreabrick
{
    /**
     * @param $name
     * @param $arguments
     * @return mixed
     */
    public function __call(
	    $name,
	    $arguments
    )
    {
	    // magic callable for editables (input, textarea, ...)
	    return $this->getDocumentTag($arguments[0], $name, $arguments[1]);
    }
}

<?php
namespace Test;

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

class MyAreabrick extends BaseAreabrick
{
    public function action(Info $info)
    {
	    $this->input($info->getDocument(), 'element-name'); // this will call the magic __call from BaseAreabrick which is a wrapper for getDocumentTag
    }
}

Of course one could check in the __call-method if an “allowed” element name are given (input, textarea, link, etc.), but as it’s the only code which is in there I didn’t do it.


#7

Thank you! @leuchtdiode!