forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestDisableCommand.php
More file actions
61 lines (49 loc) · 1.95 KB
/
Copy pathRestDisableCommand.php
File metadata and controls
61 lines (49 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* @file
* Contains \Drupal\AppConsole\Command\RestDisableCommand.
*/
namespace Drupal\AppConsole\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class RestDisableCommand extends ContainerAwareCommand
{
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'));
$this->addDependency('rest');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();
$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 = $dialog->askAndValidate(
$output,
$dialog->getQuestion($this->trans('commands.rest.disable.arguments.resource-id'), ''),
function ($resource_id) use ($rest_resources_ids) {
return $this->validateRestResource($resource_id, $rest_resources_ids, $this->getTranslator());
},
false,
'',
$rest_resources_ids
);
}
$this->validateRestResource($resource_id, $rest_resources_ids, $this->getTranslator());
$input->setArgument('resource-id', $resource_id);
$rest_settings = $this->getRestDrupalConfig();
unset($rest_settings[$resource_id]);
$config = $this->getConfigFactory()
->getEditable('rest.settings');
$config->set('resources', $rest_settings);
$config->save();
}
}