Neos\Eel\Utility::evaluateEelExpression PHP Method

evaluateEelExpression() public static method

Evaluate an Eel expression.
public static evaluateEelExpression ( string $expression, Neos\Eel\EelEvaluatorInterface $eelEvaluator, array $contextVariables, array $defaultContextConfiguration = [] ) : mixed
$expression string
$eelEvaluator Neos\Eel\EelEvaluatorInterface
$contextVariables array
$defaultContextConfiguration array
return mixed
    public static function evaluateEelExpression($expression, EelEvaluatorInterface $eelEvaluator, array $contextVariables, array $defaultContextConfiguration = [])
    {
        $matches = null;
        if (!preg_match(Package::EelExpressionRecognizer, $expression, $matches)) {
            throw new Exception('The EEL expression "' . $expression . '" was not a valid EEL expression. Perhaps you forgot to wrap it in ${...}?', 1410441849);
        }
        $defaultContextVariables = self::getDefaultContextVariables($defaultContextConfiguration);
        $contextVariables = array_merge($defaultContextVariables, $contextVariables);
        if (isset($contextVariables['q'])) {
            throw new Exception('Context variable "q" not allowed, as it is already reserved for FlowQuery use.', 1410441819);
        }
        $contextVariables['q'] = function ($element) {
            return new FlowQuery\FlowQuery(is_array($element) || $element instanceof \Traversable ? $element : [$element]);
        };
        $context = new ProtectedContext($contextVariables);
        $context->whitelist('q');
        return $eelEvaluator->evaluate($matches['exp'], $context);
    }

Usage Example

 /**
  * Render a node label
  *
  * @param NodeInterface $node
  * @param boolean $crop This argument is deprecated as of Neos 1.2 and will be removed. Don't rely on this behavior and crop labels in the view.
  * @return string
  */
 public function getLabel(NodeInterface $node, $crop = true)
 {
     $label = Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, array('node' => $node), $this->defaultContextConfiguration);
     if ($crop === false) {
         return $label;
     }
     $croppedLabel = Functions::substr($label, 0, 30);
     return $croppedLabel . (strlen($croppedLabel) < strlen($label) ? ' …' : '');
 }
All Usage Examples Of Neos\Eel\Utility::evaluateEelExpression