Commit 860a40b3 authored by Igor Biki's avatar Igor Biki
Browse files

ISTWCMS-3908: Code clean up.

parent 7ef1e68a
......@@ -22,13 +22,18 @@ class AllowedBlocks extends LayoutBuilderRestrictionBase {
use PluginHelperTrait;
/** @var ConfigFactoryInterface */
/** @var \Drupal\Core\Config\ConfigFactoryInterface */
protected $configFactory;
/**
* @inheritDoc
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
public static function create(
ContainerInterface $container,
array $configuration,
$plugin_id,
$plugin_definition
) {
return new static(
$configuration,
$plugin_id,
......@@ -49,7 +54,12 @@ class AllowedBlocks extends LayoutBuilderRestrictionBase {
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* Config factory to load blocks allowed to be displayed on dashboard.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $configFactory) {
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
ConfigFactoryInterface $configFactory
) {
$this->configuration = $configuration;
$this->pluginId = $plugin_id;
$this->pluginDefinition = $plugin_definition;
......@@ -61,21 +71,19 @@ class AllowedBlocks extends LayoutBuilderRestrictionBase {
*/
public function alterBlockDefinitions(array $definitions, array $context) {
// Respect restrictions on allowed blocks specified by the section storage.
$allowed_blocks = $this->configFactory->get('uw_dashboard.allowed_blocks')->get('allowed_blocks');
$allowed_blocks = $this->configFactory->get('uw_dashboard.allowed_blocks')
->get('allowed_blocks');
$allowed_block_definitions = [];
if (isset($context['section_storage'])) {
$default = $context['section_storage'];
if ($allowed_blocks && $default->getPluginId() === 'dashboards') {
foreach ($allowed_blocks as $key => $allowed_block) {
if (isset($definitions[$key])) {
$allowed_block_definitions[$key] = $definitions[$key];
}
if ($allowed_blocks && isset($context['section_storage']) && $context['section_storage']->getPluginId() === 'dashboards') {
foreach ($allowed_blocks as $key => $allowed_block) {
if (isset($definitions[$key])) {
$allowed_block_definitions[$key] = $definitions[$key];
}
}
}
return $allowed_block_definitions ?: $definitions;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment