Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
WCMS
uw_dashboard
Commits
6d2de0b9
Commit
6d2de0b9
authored
Jul 27, 2020
by
Igor Biki
Browse files
ISTWCMS-3908: Adding link to dashboard tray and renaming classes.
parent
eeb368e4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
43 deletions
+41
-43
src/Form/AllowedBlocksForm.php
src/Form/AllowedBlocksForm.php
+1
-1
src/Plugin/LayoutBuilderRestriction/AllowedBlocks.php
src/Plugin/LayoutBuilderRestriction/AllowedBlocks.php
+24
-38
uw_dashboard.module
uw_dashboard.module
+13
-1
uw_dashboard.routing.yml
uw_dashboard.routing.yml
+3
-3
No files found.
src/Form/
UWDashboardBlockRestriction
.php
→
src/Form/
AllowedBlocksForm
.php
View file @
6d2de0b9
...
...
@@ -9,7 +9,7 @@ use Drupal\Core\Form\ConfigFormBase;
use
Drupal\Core\Form\FormStateInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
class
UWDashboardBlockRestriction
extends
ConfigFormBase
{
class
AllowedBlocksForm
extends
ConfigFormBase
{
const
SETTINGS
=
'uw_dashboard.allowed_blocks'
;
/** @var \Drupal\Core\Block\BlockManagerInterface */
...
...
src/Plugin/LayoutBuilderRestriction/
UWDashboardBlockRestriction
.php
→
src/Plugin/LayoutBuilderRestriction/
AllowedBlocks
.php
View file @
6d2de0b9
...
...
@@ -4,9 +4,7 @@
namespace
Drupal\uw_dashboard\Plugin\LayoutBuilderRestriction
;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
use
Drupal\layout_builder
\
OverridesSectionStorageInterface
;
use
Drupal\Core\Config\ConfigFactoryInterface
;
use
Drupal\layout_builder_restrictions
\
Plugin\LayoutBuilderRestrictionBase
;
use
Drupal\layout_builder_restrictions
\
Traits\PluginHelperTrait
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
...
...
@@ -20,23 +18,12 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* description = @Translation("Restrict blocks/layouts for UW Dashboard"),
* )
*/
class
UWDashboardBlockRestriction
extends
LayoutBuilderRestrictionBase
{
class
AllowedBlocks
extends
LayoutBuilderRestrictionBase
{
use
PluginHelperTrait
;
/**
* Module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected
$moduleHandler
;
/**
* Database connection service.
*
* @var \Drupal\Core\Database\Connection
*/
protected
$database
;
/** @var ConfigFactoryInterface */
protected
$configFactory
;
/**
* @inheritDoc
...
...
@@ -46,8 +33,7 @@ class UWDashboardBlockRestriction extends LayoutBuilderRestrictionBase {
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'module_handler'
),
$container
->
get
(
'database'
)
$container
->
get
(
'config.factory'
)
);
}
...
...
@@ -60,17 +46,14 @@ class UWDashboardBlockRestriction extends LayoutBuilderRestrictionBase {
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
* @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
,
ModuleHandlerInterface
$module_handler
,
Connection
$connection
)
{
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
ConfigFactoryInterface
$configFactory
)
{
$this
->
configuration
=
$configuration
;
$this
->
pluginId
=
$plugin_id
;
$this
->
pluginDefinition
=
$plugin_definition
;
$this
->
moduleHandler
=
$module_handler
;
$this
->
database
=
$connection
;
$this
->
configFactory
=
$configFactory
;
}
/**
...
...
@@ -78,18 +61,21 @@ class UWDashboardBlockRestriction extends LayoutBuilderRestrictionBase {
*/
public
function
alterBlockDefinitions
(
array
$definitions
,
array
$context
)
{
// Respect restrictions on allowed blocks specified by the section storage.
// if (isset($context['section_storage'])) {
// $default = $context['section_storage'];
//
// if ($default->getPluginId() === 'dashboards') {
// foreach ($definitions as $key => $single_definition) {
// if (strpos($key, 'uw') === FALSE) {
// unset($definitions[$key]);
// }
// }
// }
// }
$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
];
}
}
}
}
return
$definitions
;
return
$allowed_block_definitions
?:
$definitions
;
}
}
uw_dashboard.module
View file @
6d2de0b9
...
...
@@ -5,6 +5,8 @@
* UW Dashboard module file.
*/
use
Drupal\Core\Link
;
use
Drupal\Core\Url
;
use
Drupal\views\ViewExecutable
;
/**
...
...
@@ -55,4 +57,14 @@ function uw_dashboard_preprocess_views_view_field(&$variables) {
function
uw_dashboard_toolbar_alter
(
&
$items
)
{
// Move the 'Dashboards' link at the left of the tooltar.
$items
[
'dashboards'
][
'#weight'
]
=
-
15
;
}
\ No newline at end of file
// 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.
if
(
\
Drupal
::
currentUser
()
->
hasPermission
(
'administer dashboards'
))
{
$items
[
'dashboards'
][
'tray'
][
'dashboards'
][
'#items'
][]
=
[
'#type'
=>
'link'
,
'#title'
=>
'Allowed blocks'
,
'#url'
=>
Url
::
fromRoute
(
'uw_dashboard.allowed_blocks'
),
];
}
}
uw_dashboard.routing.yml
View file @
6d2de0b9
uw_dashboard.
uw_dashboard_
allowed_blocks
:
uw_dashboard.allowed_blocks
:
path
:
'
/dashboard/allowed_blocks'
defaults
:
_form
:
'
\Drupal\uw_dashboard\Form\
UWDashboardBlockRestriction
'
_title
:
'
Blocks
allowed
on
Dashboard'
_form
:
'
\Drupal\uw_dashboard\Form\
AllowedBlocksForm
'
_title
:
'
Blocks
allowed
on
the
Dashboard'
requirements
:
_permission
:
'
administer
dashboards'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment