X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FRest%2FDisableCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FRest%2FDisableCommand.php;h=3ed293f6c67d850151c7ee7971bf0e228f0f3f17;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Rest/DisableCommand.php b/vendor/drupal/console/src/Command/Rest/DisableCommand.php new file mode 100644 index 000000000..3ed293f6c --- /dev/null +++ b/vendor/drupal/console/src/Command/Rest/DisableCommand.php @@ -0,0 +1,133 @@ +configFactory = $configFactory; + $this->pluginManagerRest = $pluginManagerRest; + parent::__construct(); + } + + /** + * @DrupalCommand( + * dependencies = { + * “rest" + * } + * ) + */ + 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); + } +}