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
5f3cd8c3
Commit
5f3cd8c3
authored
Jul 24, 2020
by
Igor Biki
Browse files
ISTWCMS-3908: Adding new plugin to handle block restrictions for dashboard.
parent
1e55205c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
0 deletions
+94
-0
src/Plugin/LayoutBuilderRestriction/UWDashboardBlockRestriction.php
.../LayoutBuilderRestriction/UWDashboardBlockRestriction.php
+94
-0
No files found.
src/Plugin/LayoutBuilderRestriction/UWDashboardBlockRestriction.php
0 → 100644
View file @
5f3cd8c3
<?php
namespace
Drupal\uw_dashboard\Plugin\LayoutBuilderRestriction
;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
use
Drupal\layout_builder
\
OverridesSectionStorageInterface
;
use
Drupal\layout_builder_restrictions
\
Plugin\LayoutBuilderRestrictionBase
;
use
Drupal\layout_builder_restrictions
\
Traits\PluginHelperTrait
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* UW Dashboard Block Restriction Plugin.
*
* @LayoutBuilderRestriction(
* id = "uw_dashboard_block_restriction",
* title = @Translation("UW Dashboard Block Restriction"),
* description = @Translation("Restrict blocks/layouts for UW Dashboard"),
* )
*/
class
UWDashboardBlockRestriction
extends
LayoutBuilderRestrictionBase
{
use
PluginHelperTrait
;
/**
* Module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected
$moduleHandler
;
/**
* Database connection service.
*
* @var \Drupal\Core\Database\Connection
*/
protected
$database
;
/**
* @inheritDoc
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'module_handler'
),
$container
->
get
(
'database'
)
);
}
/**
* Constructs a Drupal\Component\Plugin\PluginBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* 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.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
ModuleHandlerInterface
$module_handler
,
Connection
$connection
)
{
$this
->
configuration
=
$configuration
;
$this
->
pluginId
=
$plugin_id
;
$this
->
pluginDefinition
=
$plugin_definition
;
$this
->
moduleHandler
=
$module_handler
;
$this
->
database
=
$connection
;
}
/**
* {@inheritDoc}
*/
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
]);
}
}
}
}
return
$definitions
;
}
}
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