Programming Language PHP

Namespace Oro\Component\Layout\Loader\Generator

Class VisitContext

Method/Function setUpdateMethodBody

Total Examples 1

1 code examples of PHP Oro\Component\Layout\Loader\Generator\VisitContext::setUpdateMethodBody extracted from open source projects

Was this example useful?
0
                                                    public function startVisit(VisitContext $visitContext): void
    {
        $class = $visitContext->getClass();
        if (!\in_array(IsApplicableLayoutUpdateInterface::class, $class->getImplements())) {
            $class->addImplement(IsApplicableLayoutUpdateInterface::class);
        }

        $class->addMethod('isApplicable')
            ->addBody(\sprintf('return %s;', $this->expressionLanguage->compile($this->expression)))
            ->addParameter('context')->setType(ContextInterface::class);

        $oldUpdateMethodBody = $visitContext->getUpdateMethodBody();
        $visitContext->setUpdateMethodBody(
            <<<'CODE'
if (!$this->isApplicable($item->getContext())) {
    return;
}
CODE
        );
        $visitContext->appendToUpdateMethodBody($oldUpdateMethodBody);
    }