Created
July 17, 2013 16:00
-
-
Save fubhy/6021940 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ public function convert($definition, $name, array $defaults, Request $request) { | |
+ // Only continue if there is a value for the given parameter. | |
+ if (!isset($defaults[$name])) { | |
+ return; | |
+ } | |
+ $entity_type = substr($definition['type'], strlen('entity:')); | |
+ if ($storage = $this->entityManager->getStorageController($entity_type)) { | |
+ return $storage->load($defaults[$name]); | |
+ } | |
+ } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function process(array &$variables, Route $route, array &$converted) { | |
$variable_names = $route->compile()->getVariables(); | |
$options = $route->getOptions(); | |
$configuredTypes = isset($options['converters']) ? $options['converters'] : array(); | |
$entityTypes = array_keys($this->entityManager->getDefinitions()); | |
foreach ($variable_names as $name) { | |
// Do not process this variable if it's already marked as converted. | |
if (in_array($name, $converted)) { | |
continue; | |
} | |
// Obtain entity type to convert to from the route configuration or just | |
// use the variable name as default. | |
if (array_key_exists($name, $configuredTypes)) { | |
$type = $configuredTypes[$name]; | |
} | |
else { | |
$type = $name; | |
} | |
if (in_array($type, $entityTypes)) { | |
$value = $variables[$name]; | |
$storageController = $this->entityManager->getStorageController($type); | |
$entity = $storageController->load($value); | |
$variables[$name] = $entity; | |
// Mark this variable as converted. | |
$converted[] = $name; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment