Skip to content

Instantly share code, notes, and snippets.

@fabarea
Last active May 17, 2017 07:27
Show Gist options
  • Save fabarea/8aabe1f2679f7c6522f80641067411b5 to your computer and use it in GitHub Desktop.
Save fabarea/8aabe1f2679f7c6522f80641067411b5 to your computer and use it in GitHub Desktop.
Problem decoding URL with Neos

UPDATE: the solution here is to add a separator segment to tell Neos where the {node} path and the custom part starts / ends

http://abl-ch.dev/wohnen/wohnungsmarkt/wohnungsbewerbung/edit/application/008ce49e-fbed-4372-afde-73dc8330495d and ajust in the YAML configuration route.

uriPattern: '{node}/application/{--visol_ablch-applicationeditform.application}'

We want to decode this special URL that we can decompose into two parts:

http://abl-ch.dev/wohnen/wohnungsmarkt/wohnungsbewerbung/edit/008ce49e-fbed-4372-afde-73dc8330495d

  • /wohnen/wohnungsmarkt/wohnungsbewerbung/edit corresponds to a path of pages in Neos {node}
  • /008ce49e-fbed-4372-afde-73dc8330495d corresponds to a uuid and should be transmitted as string to MyAblController::applicationEditFormAction. Notice, we do not want the uuid to be converted to an object for this particular case.

Problem:

The URL is not decoded as expected. With the YAML configuration below, the ApplicationRoutePartHandler::findValueToMatch method is sucessfully returning a result. Same for ApplicationRoutePartHandler::matchValue which is correctly entering and returning a "true". But nothing more happens and the final output looks on the screen displays a 404. I tried debugging into TYPO3\Flow\Mvc\Routing\DynamicRoutePart but nothing caught my eyes.

Page Not Found
Sorry, the page you requested was not found.
#1303209195: No controller could be resolved which would match your request. 
Package key: "", controller name: "Standard". 
(GET http://abl-ch.dev/wohnen/wohnungsmarkt/wohnungsbewerbung/edit/008ce49e-fbed-4372-afde-73dc8330495d)
#
# Custom Application edit form route
#
-
name: 'Application edit form'
uriPattern: '{node}/{--visol_ablch-applicationeditform.application}'
defaults:
'@package': 'TYPO3.Neos'
'@controller': 'Frontend\Node'
'@format': 'html'
'@action': 'show'
'--visol_ablch-applicationeditform':
'@package': 'Visol.AblCh'
'@controller': 'MyAbl'
'@format': 'html'
'@action': 'applicationEditForm'
routeParts:
node:
handler: TYPO3\Neos\Routing\FrontendNodeRoutePartHandler
'--visol_ablch-applicationeditform.application':
handler: 'Visol\AblCh\Routing\ApplicationRoutePartHandler'
appendExceedingArguments: TRUE
<?php
namespace Visol\AblCh\Routing;
use TYPO3\Flow\Mvc\Routing\DynamicRoutePart;
use TYPO3\Flow\Annotations as Flow;
class ApplicationRoutePartHandler extends DynamicRoutePart
{
/**
* @param string $routePath
* @return bool|string
*/
protected function findValueToMatch($routePath)
{
// We return the last segment which is the uuid.
// Works until here!!
$segments = explode('/', $routePath);
return array_pop($segments);
}
/**
* @param string $requestPath
* @return bool
*/
protected function matchValue($requestPath)
{
// We make sure we have a $requestPath corresponding to a uuid
if (!preg_match('/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/', $requestPath)) {
return false;
}
// $this->value = ['application' => $requestPath];
$this->value = $requestPath;
// Works until here!!
return true;
}
/**
* Checks whether the route part matches the configured RegEx pattern.
* @return bool
*/
protected function resolveValue($value)
{
if (!is_string($value) && !preg_match('/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/', $value)) {
return false;
}
$this->value = $value;
return true;
}
}
<?php
namespace Visol\AblCh\Controller;
use TYPO3\Flow\Annotations as Flow;
/**
* A controller which allows for logging into an application
*/
class MyAblController extends ActionController
{
/**
* Displays the the application form
*
* @param string $application
*/
public function applicationEditFormAction($application)
{
// ...
// $application should stay a "string" here as a requirement
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment