class ServiceEndpointResources in Services 9.0.x
Same name and namespace in other branches
- 8.4 src/Controller/ServiceEndpointResources.php \Drupal\services\Controller\ServiceEndpointResources
Class \Drupal\services\Controller\ServiceEndpointManageResource.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\services\Controller\ServiceEndpointResources
Expanded class hierarchy of ServiceEndpointResources
File
- src/
Controller/ ServiceEndpointResources.php, line 15
Namespace
Drupal\services\ControllerView source
class ServiceEndpointResources extends ControllerBase {
/**
* Service definition plugin manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface.
*/
protected $pluginManager;
/**
* Constructor for \Drupal\services\Form\ServiceEndpointResourceForm.
*/
public function __construct(PluginManagerInterface $plugin_manager) {
$this->pluginManager = $plugin_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.services.service_definition'));
}
/**
* List service resources.
*
* @param \Drupal\services\ServiceEndpointInterface|null $service_endpoint
* A service endpoint entity.
*
* @return array
* An renderable array.
*/
public function displayList(ServiceEndpointInterface $service_endpoint = NULL) {
$build = [];
foreach ($this
->getCategoryDefinitions($service_endpoint) as $category => $definitions) {
if (!isset($category)) {
continue;
}
$build[$category] = [
'#type' => 'details',
'#title' => $this
->t('@category', [
'@category' => $category,
]),
'#tree' => TRUE,
];
$rows = [];
foreach ($definitions as $plugin_id => $definition) {
$row = $this
->buildRow($service_endpoint, $definition);
$row['operations']['data'] = [
'#type' => 'dropbutton',
'#links' => $this
->buildOperationLinks($service_endpoint, $plugin_id),
];
$rows[] = $row;
}
$build[$category]['table'] = array(
'#type' => 'table',
'#rows' => $rows,
'#header' => $this
->buildHeader(),
'#empty' => $this
->t('No service definitions exist'),
);
}
return $build;
}
/**
* Build service resource table header.
*
* @return array
* An array of table headers.
*/
protected function buildHeader() {
return [
'title' => $this
->t('Definition'),
'endpoint' => $this
->t('Endpoint'),
'operations' => $this
->t('Operations'),
];
}
/**
* Build service resource table rows.
*
* @return array
* An array of row items.
*/
protected function buildRow(ServiceEndpointInterface $service_endpoint, array $definition) {
$row = [];
$row['title']['data'] = [
'#markup' => $definition['title'],
];
$row['endpoint']['data'] = [
'#markup' => $definition['path'],
];
return $row;
}
/**
* Build service resource operations links.
*
* @param \Drupal\services\ServiceEndpointInterface $service_endpoint
* An service endpoint object.
* @param string $plugin_id
* An service plugin identifier.
*
* @return array
* An array of operations links.
*/
protected function buildOperationLinks(ServiceEndpointInterface $service_endpoint, $plugin_id) {
$links = [];
$links['configure'] = [
'title' => $this
->t('Enable'),
'url' => Url::fromRoute('entity.service_endpoint_resource.config_form', [
'plugin_id' => $plugin_id,
'service_endpoint' => $service_endpoint
->id(),
]),
'attributes' => $this
->getModalAttributes(),
];
if ($service_resource = $service_endpoint
->loadResourceProvider($plugin_id)) {
if ($service_resource
->hasLinkTemplate('delete-form')) {
$links['disable'] = [
'title' => $this
->t('Disable'),
'url' => $service_resource
->toUrl('delete-form'),
'attributes' => $this
->getModalAttributes(),
];
}
$links['configure']['title'] = $this
->t('Configure');
}
return $links;
}
/**
* Get service definitions grouped by category.
*
* @return array
* An array of resource definitions keyed by category.
*/
protected function getCategoryDefinitions() {
$definitions = [];
foreach ($this->pluginManager
->getDefinitions() as $plugin_id => $definition) {
if (!isset($definition['category'])) {
continue;
}
$category = $definition['category']
->render();
$definitions[$category][$plugin_id] = $definition;
}
ksort($definitions);
return $definitions;
}
/**
* Get AJAX modal attributes.
*
* @return array
* An array of modal attributes.
*/
protected function getModalAttributes() {
return [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 800,
]),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function | Returns a redirect response object for the specified route. | |
ControllerBase:: |
protected | function | Returns the state storage service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
ServiceEndpointResources:: |
protected | property | Service definition plugin manager. | |
ServiceEndpointResources:: |
protected | function | Build service resource table header. | |
ServiceEndpointResources:: |
protected | function | Build service resource operations links. | |
ServiceEndpointResources:: |
protected | function | Build service resource table rows. | |
ServiceEndpointResources:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
ServiceEndpointResources:: |
public | function | List service resources. | |
ServiceEndpointResources:: |
protected | function | Get service definitions grouped by category. | |
ServiceEndpointResources:: |
protected | function | Get AJAX modal attributes. | |
ServiceEndpointResources:: |
public | function | Constructor for \Drupal\services\Form\ServiceEndpointResourceForm. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |