Skip to content
Snippets Groups Projects
Commit 8ca43d84 authored by Igor Biki's avatar Igor Biki
Browse files

ISTWCMS-7020: Removing unused code for uw_dashboards allowed blocks.

parent 7965eb79
No related branches found
No related tags found
1 merge request!42ISTWCMS-7020: Removing unused code for uw_dashboards allowed blocks.
<?php
namespace Drupal\uw_dashboard\Form;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class for blocks allowed on the dashboard.
*/
class AllowedBlocksForm extends ConfigFormBase {
const SETTINGS = 'uw_dashboard.allowed_blocks';
/**
* The plugin manager block.
*
* @var \Drupal\Core\Block\BlockManagerInterface
*/
protected $blockManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.block')
);
}
/**
* UWDashboardBlockRestriction constructor.
*
* @param \Drupal\Core\Block\BlockManagerInterface $pluginManagerBlock
* The plugin manager block.
*/
public function __construct(BlockManagerInterface $pluginManagerBlock) {
$this->blockManager = $pluginManagerBlock;
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
static::SETTINGS,
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'uw_dashboard_block_restrictions';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$rows = [];
$config = $this->config(static::SETTINGS);
// Get list of blocks that could be displayed on dashboard override.
$definitions = $this->blockManager->getFilteredDefinitions('dashboard_override', [], ['section_storage' => NULL]);
// Sort definitions to be displayed on table select.
$grouped_definitions = $this->blockManager->getGroupedDefinitions($definitions);
foreach ($grouped_definitions as $group => $group_definitions) {
foreach ($group_definitions as $id => $definition) {
$rows[$id] = [
'label' => ucfirst($definition['admin_label']),
'group' => ucfirst($group),
];
}
}
$form['allowed_blocks'] = [
'#type' => 'tableselect',
'#header' => [
'label' => $this->t('Block label'),
'group' => $this->t('Group'),
],
'#sticky' => TRUE,
'#options' => $rows,
'#empty' => $this->t('No blocks found.'),
'#default_value' => $config->get('allowed_blocks') ?: [],
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$blocks = $form_state->getValue('allowed_blocks');
$selected = array_filter($blocks);
$this->configFactory->getEditable(static::SETTINGS)
->set('allowed_blocks', $selected)
->save();
parent::submitForm($form, $form_state);
}
}
......@@ -60,17 +60,6 @@ function uw_dashboard_toolbar_alter(&$items) {
$items['dashboards']['#weight'] = -15;
// Rename 'Dashboards' to 'Workbench'.
$items['dashboards']['tab']['#title'] = 'Workbench';
// Adding config form for user with permission to update it. This prevents
// menu item to be displayed and getting access denied by clicking on it.
$url = Url::fromRoute('uw_dashboard.allowed_blocks');
if ($url->access()) {
$items['dashboards']['tray']['dashboards']['#items'][] = [
'#type' => 'link',
'#title' => 'Allowed blocks',
'#url' => $url,
];
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment