X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=inline;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FRouting%2FFormRoute.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FPlugin%2FDMU%2FRouting%2FFormRoute.php;h=b60727c19788f5953f65983771dc8004e02ce1ca;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hp=0000000000000000000000000000000000000000;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35;p=yaffs-website diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Routing/FormRoute.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Routing/FormRoute.php new file mode 100644 index 000000000..b60727c19 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Routing/FormRoute.php @@ -0,0 +1,109 @@ +formConverter = $form_converter; + } + + /** + * {@inheritdoc} + */ + public function getName(TargetInterface $target, RouteWrapper $route) { + $name = $target->id() . '.' . $this->unPrefix($route['page arguments'][0], $target->id()); + + $arguments = array_filter(array_slice($route['page arguments'], 1), 'is_string'); + if ($arguments) { + $name .= '_' . implode('_', $arguments); + } + + return $name; + } + + /** + * {@inheritdoc} + */ + protected function buildParameterMap(TargetInterface $target, RouteWrapper $route) { + $map = parent::buildParameterMap($target, $route); + + $indexer = $target->getIndexer('function'); + if ($indexer->has($route['page arguments'][0])) { + $builder = $indexer->get($route['page arguments'][0]); + $parameters = $this->bumpKeys(array_slice($builder->getParameters()->toArray(), 2), 2); + $arguments = $this->bumpKeys(array_slice($route['page arguments'], 1), 2); + $map->merge(new ParameterMap($route->getPath(), $parameters, $arguments)); + } + + return $map; + } + + /** + * Returns a copy of the input array with the keys increased by $offset. This + * only works on numerically indexed arrays; I don't know what it does to + * associative arrays, but probably nothing good. + * + * @param array $input + * The input array. + * + * @param int $offset + * The offset to add to the keys. + * + * @return array + */ + private function bumpKeys(array $input, $offset = 0) { + $output = []; + + foreach ($input as $key => $value) { + $output[ $key + $offset ] = $value; + } + + return $output; + } + + /** + * {@inheritdoc} + */ + public function buildRoute(TargetInterface $target, RouteWrapper $route) { + $controller = $this->formConverter->get($target, $route['page arguments'][0])->build(); + $target->getIndexer('class')->addFile($this->writeClass($target, $controller)); + } + + protected function getController(TargetInterface $target, RouteWrapper $route) { + return $this->formConverter->get($target, $route['page arguments'][0])->render(); + } + + /** + * {@inheritdoc} + */ + public function buildRouteDefinition(TargetInterface $target, RouteWrapper $route) { + $definition = parent::buildRouteDefinition($target, $route); + $definition->setDefault('_form', $this->getController($target, $route)->getName()->getAbsolutePath()); + + return $definition; + } + +}