protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $io->newLine(); $io->comment($this->trans('commands.router.rebuild.messages.rebuilding')); $this->routerBuilder->rebuild(); $io->success($this->trans('commands.router.rebuild.messages.completed')); }
/** * Gets the real route provider service and rebuilds the router id necessary. * * @return \Drupal\Core\Routing\RouteProviderInterface * The route provider service. */ protected function getRouteProvider() { if (!$this->rebuilt) { $this->routeBuilder->rebuild(); $this->rebuilt = TRUE; } return $this->routeProvider; }
/** * {@inheritdoc} */ public function submitForm(array &$form, formstateinterface $form_state) { $methods = $form_state->getValue('methods'); $resource_id = $form_state->getValue('resource_id'); $resources = \Drupal::config('rest.settings')->get('resources') ?: array(); // Reset the resource configuration. $resources[$resource_id] = array(); foreach ($methods as $method => $settings) { if ($settings[$method] == TRUE) { $resources[$resource_id][$method] = array(); // Check for selected formats. $formats = array_keys(array_filter($settings['settings']['formats'])); if (!empty($formats)) { $resources[$resource_id][$method]['supported_formats'] = $formats; } // Check for selected authentication providers. $auth = array_keys(array_filter($settings['settings']['auth'])); if (!empty($auth)) { $resources[$resource_id][$method]['supported_auth'] = $auth; } } } $config = \Drupal::configFactory()->getEditable('rest.settings'); $config->set('resources', $resources); $config->save(); // Rebuild routing cache. $this->routeBuilder->rebuild(); drupal_set_message(t('The resource was updated successfully.')); // Redirect back to the listing. $form_state->setRedirectUrl(new Url('restui.list')); }
/** * Disables a resource. * * @param string $resource_id * The identifier or the REST resource. * @param \Symfony\Component\HttpFoundation\Request $request * The current request. * * @return \Drupal\Core\Ajax\AjaxResponse|\Symfony\Component\HttpFoundation\RedirectResponse * Redirects back to the listing page. * * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException * Access is denied, if the token is invalid or missing. */ public function disable($resource_id, Request $request) { if (!\Drupal::csrfToken()->validate($request->query->get('token'), 'restui_disable')) { throw new AccessDeniedHttpException(); } $config = \Drupal::configFactory()->getEditable('rest.settings'); $resources = $config->get('resources') ?: array(); $plugin = $this->resourcePluginManager->getInstance(array('id' => $resource_id)); if (!empty($plugin)) { // disable the resource. unset($resources[$resource_id]); $config->set('resources', $resources); $config->save(); // Rebuild routing cache. $this->routeBuilder->rebuild(); drupal_set_message(t('The resource was disabled successfully.')); } // Redirect back to the page. return new RedirectResponse($this->urlGenerator->generate('restui.list', array(), TRUE)); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->routeBuilder->rebuild(); drupal_set_message($this->t('The menu router has been rebuilt.')); $form_state->setRedirect('<front>'); }