configFactory = $configFactory; $this->pluginManagerRest = $pluginManagerRest; parent::__construct(); } protected function configure() { $this ->setName('rest:disable') ->setDescription($this->trans('commands.rest.disable.description')) ->addArgument( 'resource-id', InputArgument::OPTIONAL, $this->trans('commands.rest.debug.arguments.resource-id') ); } protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $resource_id = $input->getArgument('resource-id'); $rest_resources = $this->getRestResources(); $rest_resources_ids = array_merge( array_keys($rest_resources['enabled']), array_keys($rest_resources['disabled']) ); if (!$resource_id) { $resource_id = $io->choice( $this->trans('commands.rest.disable.arguments.resource-id'), $rest_resources_ids ); } $this->validateRestResource( $resource_id, $rest_resources_ids, $this->translator ); $resources = \Drupal::service('entity_type.manager') ->getStorage('rest_resource_config')->loadMultiple(); if ($resources[$this->getResourceKey($resource_id)]) { $routeBuilder = \Drupal::service('router.builder'); $resources[$this->getResourceKey($resource_id)]->delete(); // Rebuild routing cache. $routeBuilder->rebuild(); $io->success( sprintf( $this->trans('commands.rest.disable.messages.success'), $resource_id ) ); return true; } $message = sprintf($this->trans('commands.rest.disable.messages.already-disabled'), $resource_id); $io->info($message); return true; } /** * The key used in the form. * * @param string $resource_id * The resource ID. * * @return string * The resource key in the form. */ protected function getResourceKey($resource_id) { return str_replace(':', '.', $resource_id); } }