X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FShared%2FRestTrait.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FShared%2FRestTrait.php;h=0c5c3c70bb350aa1da7ed581daf67f6788adbf44;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Shared/RestTrait.php b/vendor/drupal/console/src/Command/Shared/RestTrait.php new file mode 100644 index 000000000..0c5c3c70b --- /dev/null +++ b/vendor/drupal/console/src/Command/Shared/RestTrait.php @@ -0,0 +1,80 @@ +getRestDrupalConfig(); + + $resources = $this->pluginManagerRest->getDefinitions(); + + + $enabled_resources = array_combine(array_keys($config), array_keys($config)); + $available_resources = ['enabled' => [], 'disabled' => []]; + + foreach ($resources as $id => $resource) { + $status = in_array($id, $enabled_resources) ? 'enabled' : 'disabled'; + $available_resources[$status][$id] = $resource; + } + + // Sort the list of resources by label. + $sort_resources = function ($resource_a, $resource_b) { + return strcmp($resource_a['label'], $resource_b['label']); + }; + if (!empty($available_resources['enabled'])) { + uasort($available_resources['enabled'], $sort_resources); + } + if (!empty($available_resources['disabled'])) { + uasort($available_resources['disabled'], $sort_resources); + } + + if (isset($available_resources[$rest_status])) { + return [$rest_status => $available_resources[$rest_status]]; + } + + return $available_resources; + } + + public function getRestDrupalConfig() + { + if ($this->configFactory) { + return $this->configFactory->get('rest.settings')->get('resources') ?: []; + } + + return null; + } + + /** + * @param $rest + * @param $rest_resources_ids + * @param $translator + * + * @return mixed + */ + public function validateRestResource($rest, $rest_resources_ids, $translator) + { + if (in_array($rest, $rest_resources_ids)) { + return $rest; + } else { + throw new \InvalidArgumentException( + sprintf( + $translator->trans('commands.rest.disable.messages.invalid-rest-id'), + $rest + ) + ); + } + } +}