Skip to content

Commit

Permalink
[rest:disable] Fix rest disable functionality (#2916)
Browse files Browse the repository at this point in the history
  • Loading branch information
edutrul authored and enzolutions committed Nov 11, 2016
1 parent a2a3523 commit bc32b76
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions src/Command/Rest/DisableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class DisableCommand extends Command
use RestTrait;

/**
* @var ConfigFactory
*/
* @var ConfigFactory
*/
protected $configFactory;

/**
* @var ResourcePluginManager
*/
* @var ResourcePluginManager
*/
protected $pluginManagerRest;

/**
Expand All @@ -53,7 +53,6 @@ public function __construct(
parent::__construct();
}


/**
* @DrupalCommand(
* dependencies = {
Expand Down Expand Up @@ -96,23 +95,38 @@ protected function execute(InputInterface $input, OutputInterface $output)
$rest_resources_ids,
$this->translator
);
$input->setArgument('resource-id', $resource_id);
$rest_settings = $this->getRestDrupalConfig();

unset($rest_settings[$resource_id]);

$config = $this->configFactory->getEditable('rest.settings');

$config->set('resources', $rest_settings);
$config->save();

$io->success(
sprintf(
$this->trans('commands.rest.disable.messages.success'),
$resource_id
)
);
$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;
}

return 0;
/**
* 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);
}

}

0 comments on commit bc32b76

Please sign in to comment.