class Blocks in DRD Agent 8.3
Same name and namespace in other branches
- 4.0.x src/Agent/Action/Blocks.php \Drupal\drd_agent\Agent\Action\Blocks
Provides a 'Blocks' code.
Hierarchy
- class \Drupal\drd_agent\Agent\Action\Base implements ContainerInjectionInterface, BaseInterface
- class \Drupal\drd_agent\Agent\Action\Blocks
Expanded class hierarchy of Blocks
File
- src/
Agent/ Action/ Blocks.php, line 12
Namespace
Drupal\drd_agent\Agent\ActionView source
class Blocks extends Base {
/**
* Collect all available blocks and return them as a list.
*
* @return array
* List of block indexed by provider and ID, showing their label as value.
*/
private function listBlocks() : array {
$block_list = [];
try {
$blb = BlockListBuilder::createInstance($this->container, $this->entityTypeManager
->getDefinition('block'));
/** @var \Drupal\block\BlockInterface[] $blocks */
$blocks = $blb
->load();
foreach ($blocks as $id => $block) {
$definition = $block
->getPlugin()
->getPluginDefinition();
$block_list[$definition['provider']][$id] = $block
->label();
}
} catch (PluginNotFoundException $e) {
// Ignore.
}
return $block_list;
}
/**
* Load and return the rendered block.
*
* @param string $delta
* ID of the block from the given provider.
*
* @return \Drupal\Component\Render\MarkupInterface|array
* Rendered result of the block or an empty array.
*/
private function renderBlock($delta) {
try {
$blb = BlockListBuilder::createInstance($this->container, $this->entityTypeManager
->getDefinition('block'));
} catch (PluginNotFoundException $e) {
return [];
}
/** @var \Drupal\block\BlockInterface[] $blocks */
$blocks = $blb
->load();
if (isset($blocks[$delta])) {
$block = $blocks[$delta];
$build = $block
->getPlugin()
->build();
/** @noinspection NullPointerExceptionInspection */
return $this->container
->get('renderer')
->renderPlain($build);
}
return [];
}
/**
* {@inheritdoc}
*/
public function execute() {
if (!$this->moduleHandler
->moduleExists('block')) {
return [];
}
$args = $this
->getArguments();
if (!empty($args['module']) && !empty($args['delta'])) {
return [
'data' => $this
->renderBlock($args['delta']),
];
}
return $this
->listBlocks();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Base:: |
protected | property | ||
Base:: |
private | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | Crypt object for this DRD request. | |
Base:: |
protected | property | ||
Base:: |
private | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
private | function | Authenticate the request or throw an exception. | |
Base:: |
public | function |
Authorize the DRD instance, all validations have passed successfully. Overrides BaseInterface:: |
|
Base:: |
public | function | Callback to authorize a DRD instance with a given secret. | |
Base:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
Base:: |
public | function |
Get the arguments for this request. Overrides BaseInterface:: |
|
Base:: |
public | function |
Get authorised Crypt object or FALSE if none is available. Overrides BaseInterface:: |
|
Base:: |
public | function |
Get an array of database connection information. Overrides BaseInterface:: |
|
Base:: |
public | function |
Get the debug mode. Overrides BaseInterface:: |
|
Base:: |
public | function |
Overrides BaseInterface:: |
|
Base:: |
public | function |
Overrides BaseInterface:: |
|
Base:: |
public | function |
Validate a one-time-token. Overrides BaseInterface:: |
|
Base:: |
public | function |
Change current session to user 1. Overrides BaseInterface:: |
|
Base:: |
private | function | Read and decode the input from the POST request. | |
Base:: |
public | function |
Overrides BaseInterface:: |
|
Base:: |
public | function | Main callback to execute an action. | |
Base:: |
constant | |||
Base:: |
constant | |||
Base:: |
constant | |||
Base:: |
public | function |
Set the debug mode. Overrides BaseInterface:: |
|
Base:: |
private | function | Recursivly convert request arguments to an array. | |
Base:: |
public | function |
Logging if in debug mode. Overrides BaseInterface:: |
|
Base:: |
public | function | Base constructor. | |
Blocks:: |
public | function |
Execute an action. Overrides Base:: |
|
Blocks:: |
private | function | Collect all available blocks and return them as a list. | |
Blocks:: |
private | function | Load and return the rendered block. |