/** * Evaluate an Eel expression. * * @param string $expression The Eel expression to evaluate * @param NodeInterface $node * @param string $propertyName * @param mixed $value * @return mixed The result of the evaluated Eel expression * @throws \TYPO3\Eel\Exception */ protected function evaluateEelExpression($expression, NodeInterface $node, $propertyName, $value) { if ($this->defaultContextVariables === NULL) { $this->defaultContextVariables = EelUtility::getDefaultContextVariables($this->settings['defaultContext']); } $contextVariables = array_merge($this->defaultContextVariables, array('node' => $node, 'propertyName' => $propertyName, 'value' => $value)); return EelUtility::evaluateEelExpression($expression, $this->eelEvaluator, $contextVariables); }
/** * 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 = \TYPO3\Eel\Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, array('node' => $node), $this->defaultContextConfiguration); if ($crop === false) { return $label; } $croppedLabel = \TYPO3\Flow\Utility\Unicode\Functions::substr($label, 0, 30); return $croppedLabel . (strlen($croppedLabel) < strlen($label) ? ' …' : ''); }
protected function computeStateInternally(&$adjustedState, $context) { foreach ($adjustedState as $key => &$value) { if (is_array($value)) { $this->computeStateInternally($value, $context); } elseif (is_string($value) && substr($value, 0, 2) === '${' && substr($value, -1) === '}') { $value = Utility::evaluateEelExpression($value, $this->eelEvaluator, $context, $this->defaultContext); } } }
/** * {@inheritdoc} * * @param \TYPO3\Eel\FlowQuery\FlowQuery $flowQuery * @param array $arguments * @return void */ public function evaluate(\TYPO3\Eel\FlowQuery\FlowQuery $flowQuery, array $arguments) { if (!isset($arguments[0]) || empty($arguments[0])) { throw new \TYPO3\Eel\FlowQuery\FlowQueryException('No Eel expression provided', 1332492243); } if (!isset($arguments[1]) || empty($arguments[1])) { $previousValue = null; } else { $previousValue = $arguments[1]; } $expression = '${' . $arguments[0] . '}'; $context = $flowQuery->getContext(); foreach ($context as $key => $element) { $contextVariables = array('previousValue' => $previousValue, 'currentValue' => $element, 'index' => $key, 'array' => $context); $previousValue = \TYPO3\Eel\Utility::evaluateEelExpression($expression, $this->eelEvaluator, $contextVariables); } return $previousValue; }
/** * Get variables from configuration that should be set in the context by default. * For example Eel helpers are made available by this. * * @return array Array with default context variable objects. */ protected function getDefaultContextVariables() { if ($this->defaultContextVariables === null) { $this->defaultContextVariables = array(); if (isset($this->settings['defaultContext']) && is_array($this->settings['defaultContext'])) { $this->defaultContextVariables = EelUtility::getDefaultContextVariables($this->settings['defaultContext']); } $this->defaultContextVariables['request'] = $this->controllerContext->getRequest(); } return $this->defaultContextVariables; }
/** * Record events for entity changes. * * Note: this method is registered as an Doctrine event listener in the settings of this package. * * TODO: Update/Delete of Entities * * @param OnFlushEventArgs $eventArgs * @return void * @throws \TYPO3\Eel\Exception */ public function onFlush(OnFlushEventArgs $eventArgs) { if (!$this->eventEmittingService->isEnabled()) { return; } $entityManager = $eventArgs->getEntityManager(); $unitOfWork = $entityManager->getUnitOfWork(); foreach ($unitOfWork->getScheduledEntityInsertions() as $entity) { $className = get_class($entity); if (isset($this->monitorEntitiesSetting[$className])) { $entityMonitoringConfiguration = $this->monitorEntitiesSetting[$className]; if (isset($entityMonitoringConfiguration['events']['created'])) { $this->initializeAccountIdentifier(); $data = array(); foreach ($entityMonitoringConfiguration['data'] as $key => $eelExpression) { $data[$key] = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, array('entity' => $entity)); } $event = $this->eventEmittingService->emit($entityMonitoringConfiguration['events']['created'], $data); $unitOfWork->computeChangeSet($entityManager->getClassMetadata('TYPO3\\Neos\\EventLog\\Domain\\Model\\Event'), $event); } } } foreach ($unitOfWork->getScheduledEntityDeletions() as $entity) { $className = get_class($entity); if (isset($this->monitorEntitiesSetting[$className])) { $entityMonitoringConfiguration = $this->monitorEntitiesSetting[$className]; if (isset($entityMonitoringConfiguration['events']['deleted'])) { $this->initializeAccountIdentifier(); $data = array(); foreach ($entityMonitoringConfiguration['data'] as $key => $eelExpression) { $data[$key] = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, array('entity' => $entity)); } $event = $this->eventEmittingService->emit($entityMonitoringConfiguration['events']['deleted'], $data); $unitOfWork->computeChangeSet($entityManager->getClassMetadata('TYPO3\\Neos\\EventLog\\Domain\\Model\\Event'), $event); } } } }
/** * @param AbstractNodeData $nodeData * @param NodeType $nodeType * @param MetaDataCollection $metaDataCollection * @throws \TYPO3\Eel\Exception */ protected function mapMetaDataToNodeData(AbstractNodeData $nodeData, NodeType $nodeType, MetaDataCollection $metaDataCollection) { if ($this->defaultContextVariables === NULL) { $this->defaultContextVariables = EelUtility::getDefaultContextVariables($this->settings['defaultEelContext']); } foreach ($nodeType->getProperties() as $propertyName => $propertyConfiguration) { $contextVariables = array_merge($this->defaultContextVariables, $metaDataCollection->toArray()); if (isset($propertyConfiguration['mapping'])) { $nodeData->setProperty($propertyName, EelUtility::evaluateEelExpression($propertyConfiguration['mapping'], $this->eelEvaluator, $contextVariables)); } } }
/** * @param Asset $asset * @param MetaDataCollection $metaDataCollection */ public function mapMetaData(Asset $asset, MetaDataCollection $metaDataCollection) { $contextVariables = array_merge($this->defaultContextVariables, $metaDataCollection->toArray()); if (isset($this->metaDataMappingConfiguration['title'])) { $asset->setTitle(substr((string) EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['title'], $this->eelEvaluator, $contextVariables), 0, 255)); } if (isset($this->metaDataMappingConfiguration['caption'])) { $asset->setCaption((string) EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['caption'], $this->eelEvaluator, $contextVariables)); } if (isset($this->metaDataMappingConfiguration['tags'])) { $tagLabels = EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['tags'], $this->eelEvaluator, $contextVariables); $tagLabels = array_unique($tagLabels); $tags = new ArrayCollection(); foreach ($tagLabels as $tagLabel) { if (trim($tagLabel) !== '') { $tags->add($this->getOrCreateTag(trim($tagLabel))); } } $asset->setTags($tags); } if (isset($this->metaDataMappingConfiguration['collections'])) { $collectionTitles = EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['collections'], $this->eelEvaluator, $contextVariables); $collectionTitles = array_unique($collectionTitles); $collections = new ArrayCollection(); foreach ($collectionTitles as $collectionTitle) { if (trim($collectionTitle) !== '') { $collections->add($this->getOrCreateCollection(trim($collectionTitle))); } } $asset->setAssetCollections($collections); } if (!$this->persistenceManager->isNewObject($asset)) { $this->assetRepository->update($asset); } }