Skip to content

Instantly share code, notes, and snippets.

@kitsunet
Created February 11, 2013 13:45
Show Gist options
  • Select an option

  • Save kitsunet/4754493 to your computer and use it in GitHub Desktop.

Select an option

Save kitsunet/4754493 to your computer and use it in GitHub Desktop.
TargetNodeAspect to route Conference package plugins to configured nodes. A configuration (in Settings.yaml) looks like this: (Package name is TYPO3.Conference, if you adapt the Aspect to your package you need to adapt the settings path.) TYPO3: Conference: targetNodeMappings: 'typo3_typo3_typoscript_plugin': - package: TYPO3.Conference controll…
<?php
namespace TYPO3\Conference\Aspect;
/* *
* This script belongs to the FLOW3 package "Conference". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License, or (at your *
* option) any later version. *
* *
* This script is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
* General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with the script. *
* If not, see http://www.gnu.org/licenses/lgpl.html *
* *
* The TYPO3 project - inspiring people to share! *
* */
use TYPO3\Flow\Annotations as Flow;
/**
* @Flow\Aspect
*/
class TargetNodeAspect {
/**
* @var \TYPO3\TYPO3CR\Domain\Repository\NodeRepository
* @Flow\Inject
*/
protected $nodeRepository;
/**
* @var \TYPO3\Neos\Routing\NodeObjectConverter
* @Flow\Inject
*/
protected $nodeObjectConverter;
/**
* @var array
*/
protected $settings;
/**
* Injects the configuration settings
*
* @param array $settings
* @return void
*/
public function injectSettings(array $settings) {
$this->settings = $settings;
}
/**
*
* @Flow\Before("method(TYPO3\Flow\Mvc\Routing\UriBuilder->build())")
* @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point
* @return void
*/
public function addTargetNodeToArguments(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint) {
if (!isset($this->settings['targetNodeMappings']) || !is_array($this->settings['targetNodeMappings'])) {
return;
}
$uriBuilder = $joinPoint->getProxy();
$arguments = $joinPoint->getMethodArgument('arguments');
foreach ($this->settings['targetNodeMappings'] as $pluginNamespace => $pluginTargetNodeMappings) {
$pluginNamespace = '--' . $pluginNamespace;
if (!isset($arguments[$pluginNamespace]) || !is_array($arguments[$pluginNamespace])) {
continue;
}
$pluginArguments = $arguments[$pluginNamespace];
foreach ($pluginTargetNodeMappings as $pluginTargetNodeMapping) {
if (isset($pluginTargetNodeMapping['package'])
&& (!isset($pluginArguments['@package']) || strtolower($pluginArguments['@package']) !== strtolower($pluginTargetNodeMapping['package']))) {
continue;
}
if (isset($pluginTargetNodeMapping['controller'])
&& (!isset($pluginArguments['@controller']) || strtolower($pluginArguments['@controller']) !== strtolower($pluginTargetNodeMapping['controller']))) {
continue;
}
if (isset($pluginTargetNodeMapping['action'])
&& (!isset($pluginArguments['@action']) || strtolower($pluginArguments['@action']) !== strtolower($pluginTargetNodeMapping['action']))) {
continue;
}
$nodeIdentifier = $pluginTargetNodeMapping['targetNode'];
$node = $this->nodeRepository->findOneByIdentifier($nodeIdentifier);
if ($node === NULL) {
throw new \TYPO3\Flow\Exception('no node with identifier "' . $nodeIdentifier . '" found', 1334172725);
}
$arguments['node'] = $node;
$arguments['@package'] = 'TYPO3.TYPO3';
$arguments['@controller'] = 'Frontend\Node';
$arguments['@format'] = 'html';
$arguments['@action'] = 'show';
$uriBuilder->setArguments($arguments);
return;
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment