/** * @inheritdoc */ protected function buildRoutes() { LoggerRegistry::debug('{class}::buildRoutes(), mounted to "{mountedUrl}"', array('class' => (new \ReflectionClass($this))->getShortName(), 'mountedUrl' => $this->getMountedUrl())); $routes = new RouteCollection(); // Check for an index controller and add a route for the module root. if ((new \ReflectionObject($this))->hasMethod('indexController')) { $routes->add('index', new Route($this->getMountedUrl())); } // Load routes from file. $filename = sprintf('%s/%s/%s', $this->getModuleRoot(), ResourceLocations::RESOURCES_DIRECTORY, self::FILENAME_ROUTES); $container = new Configuration($this->getConfigLoader()); $container->merge($filename); // Add a route for each record in the routes file. foreach ($container->all() as $name => $parameters) { $defaults = array(); $requirements = array(); $options = array(); $path = sprintf('%s/%s', $this->getMountedUrl(), $this->config(sprintf('routes.%s', $name), $name)); foreach ($parameters ?: array() as $parameter) { $parameterName = $parameter['name']; $path = sprintf('%s/{%s}', $path, $parameterName); if (isset($parameter['default'])) { $defaults[$parameterName] = $parameter['default']; } if (isset($parameter['requirements'])) { $requirements[$parameterName] = $parameter['requirements']; } if (isset($parameter['options'])) { $options[$parameterName] = $parameter['options']; } } $routes->add($name, new Route($path, $defaults, $requirements, $options)); } return $routes; }
/** * @param string $formKey * @param string $formUrl * @param ConfigurableInterface $module * @param string[] $paths * * @return FormInterface|null */ protected function loadFormFromDefinitions($formKey, $formUrl, ConfigurableInterface $module, array $paths) { $path = FileUtilities::firstExistingPath($paths); if (!empty($path)) { // Setup the configuration container for the form definition. $config = new Configuration($this->formsModule->getConfigLoader()); $config->addProcessor(new ArrayTokenProcessor($this->getValues($formKey), 'data')); $config->addProcessor(new EngineTokenProcessor($this->formsModule->getEngine(), 'engine')); $config->addProcessor(new ConfigTokenProcessor($this->formsModule->getEngine(), 'engine-config')); $config->addProcessor(new ConfigTokenProcessor($module, 'config')); // Merge the configuration defaults and form definition file contents. $config->merge($this->baseConfig); $config->merge(array('form-url' => $formUrl)); $config->merge($path); // Build and return the form $builder = new FormBuilder($this->formsModule, $formKey); return $builder->buildForm($config->all()); } return null; }