cleaned all unused modules
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
name: 'REST Config'
|
||||
type: module
|
||||
description: 'Get site configiration through rest api'
|
||||
core_version_requirement: ^8.8 || ^9.2
|
||||
package: 'Custom'
|
||||
dependencies:
|
||||
- rest
|
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains rest_config.module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function rest_config_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
// Main module help for the rest_config module.
|
||||
case 'help.page.rest_config':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('Get site configiration through rest api') . '</p>';
|
||||
return $output;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
@@ -1,106 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\rest_config\Plugin\rest\resource;
|
||||
|
||||
use Drupal\Core\Session\AccountProxyInterface;
|
||||
use Drupal\rest\ModifiedResourceResponse;
|
||||
use Drupal\rest\Plugin\ResourceBase;
|
||||
use Drupal\rest\ResourceResponse;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
/**
|
||||
* Provides a resource to get configurations values.
|
||||
*
|
||||
* @RestResource(
|
||||
* id = "config_rest_resource",
|
||||
* label = @Translation("Config rest resource"),
|
||||
* uri_paths = {
|
||||
* "canonical" = "/config/{file}/{key}"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class ConfigRestResource extends ResourceBase {
|
||||
|
||||
/**
|
||||
* A current user instance.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountProxyInterface
|
||||
*/
|
||||
protected $currentUser;
|
||||
|
||||
/**
|
||||
* Constructs a new ConfigRestResource object.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param array $serializer_formats
|
||||
* The available serialization formats.
|
||||
* @param \Psr\Log\LoggerInterface $logger
|
||||
* A logger instance.
|
||||
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
|
||||
* A current user instance.
|
||||
*/
|
||||
public function __construct(
|
||||
array $configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
array $serializer_formats,
|
||||
LoggerInterface $logger,
|
||||
AccountProxyInterface $current_user) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger);
|
||||
|
||||
$this->currentUser = $current_user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->getParameter('serializer.formats'),
|
||||
$container->get('logger.factory')->get('rest_config'),
|
||||
$container->get('current_user')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds to GET requests.
|
||||
*
|
||||
* @return \Drupal\rest\ResourceResponse
|
||||
* The HTTP response object.
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
|
||||
* Throws exception expected.
|
||||
*/
|
||||
public function get($file = null, $key = null) {
|
||||
|
||||
// You must to implement the logic of your REST Resource here.
|
||||
// Use current user after pass authentication to validate access.
|
||||
if (!$this->currentUser->hasPermission('access content')) {
|
||||
throw new AccessDeniedHttpException();
|
||||
}
|
||||
|
||||
$data = [];
|
||||
if($file && $key){
|
||||
$config = \Drupal::config($file);
|
||||
if($config){
|
||||
$value = $config->get($key);
|
||||
$data[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$response = new ResourceResponse($data, 200);
|
||||
$response->addCacheableDependency($data);
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user