Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lb_plus
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
lb_plus
Commits
bc5151be
Commit
bc5151be
authored
2 years ago
by
Francesco Pesenti
Browse files
Options
Downloads
Patches
Plain Diff
Fix copy/paste, check access on paste, fix drop alter
parent
dab32dda
No related branches found
Branches containing commit
Tags
7.98
Tags containing commit
1 merge request
!5
Fix copy/paste, check access on paste, fix drop alter
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lb_plus.module
+19
-9
19 additions, 9 deletions
lb_plus.module
src/Controller/LbPlusBlockController.php
+19
-5
19 additions, 5 deletions
src/Controller/LbPlusBlockController.php
with
38 additions
and
14 deletions
lb_plus.module
+
19
−
9
View file @
bc5151be
<?php
define
(
'LB_PLUS_TEMPLATE_PLACEHOLDER'
,
'Template:'
);
use
Drupal\Core\File\FileSystemInterface
;
use
Drupal\Core\Url
;
use
Drupal\lb_plus
\Entity\LbPlusBlockContentSettings
;
...
...
@@ -196,13 +194,25 @@ function lb_plus_form_block_content_type_form_submit($form, $form_state) {
* Implements hook_preprocess_HOOK().
*/
function
lb_plus_preprocess_layout
(
&
$variables
)
{
foreach
(
Element
::
children
(
$variables
[
'content'
])
as
$index
)
{
$element
=
&
$variables
[
'content'
][
$index
];
if
(
!
empty
(
$element
[
'layout_builder_add_block'
][
'link'
]))
{
$element
[
'layout_builder_add_block'
][
'link'
]
=
[
'#type'
=>
'item'
,
'#markup'
=>
t
(
'Drop a block here to add it'
),
];
// @todo: make this more safe.
$routes
=
[
'layout_builder.overrides.node.view'
,
'layout_builder.configure_section'
,
'lb_plus.paste_block'
,
'lb_plus.add_block'
,
'lb_plus.add_default_block'
,
];
$route_name
=
\Drupal
::
routeMatch
()
->
getRouteName
();
if
(
in_array
(
$route_name
,
$routes
))
{
foreach
(
Element
::
children
(
$variables
[
'content'
])
as
$index
)
{
$element
=
&
$variables
[
'content'
][
$index
];
if
(
!
empty
(
$element
[
'layout_builder_add_block'
][
'link'
]))
{
$element
[
'layout_builder_add_block'
][
'link'
]
=
[
'#type'
=>
'item'
,
'#markup'
=>
t
(
'Drop a block here to add it'
),
];
}
}
}
}
This diff is collapsed.
Click to expand it.
src/Controller/LbPlusBlockController.php
+
19
−
5
View file @
bc5151be
...
...
@@ -398,15 +398,18 @@ class LbPlusBlockController extends ChooseBlockController implements ContainerI
public
function
pasteBlock
(
SectionStorageInterface
$section_storage
=
NULL
,
$region
=
NULL
,
$delta
=
NULL
,
$plugin_id
=
NULL
)
{
$block
=
BlockContent
::
load
(
$plugin_id
);
if
(
$block
&&
$region
&&
$delta
)
{
$block_type_permissions
=
$this
->
config
->
get
(
'block_type_permissions'
);
$layout
=
$section_storage
->
getSection
(
$delta
)
->
getLayout
();
$layout_id
=
$layout
->
getPluginId
();
$access
=
!
empty
(
$block_type_permissions
[
$layout_id
][
$block
->
bundle
()]);
if
(
$block
&&
$region
&&
$delta
!==
FALSE
&&
$access
)
{
$cloned_entity
=
$block
->
createDuplicate
();
$label_key
=
\Drupal
::
entityTypeManager
()
->
getDefinition
(
'block_content'
)
->
getKey
(
'label'
);
$new_label
=
str_replace
(
LB_PLUS_TEMPLATE_PLACEHOLDER
,
''
,
$block
->
label
());
$cloned_entity
->
set
(
$label_key
,
trim
(
$new_label
));
$cloned_entity
->
set
(
$label_key
,
trim
(
$block
->
label
()));
$cloned_entity
->
setReusable
();
if
(
$cloned_entity
->
save
())
{
...
...
@@ -414,10 +417,21 @@ class LbPlusBlockController extends ChooseBlockController implements ContainerI
$component
=
new
SectionComponent
(
$this
->
uuidGenerator
->
generate
(),
$region
,
[
'id'
=>
'block_content:'
.
$cloned_entity
->
uuid
()]);
$section
->
appendComponent
(
$component
);
$this
->
layoutTempstoreRepository
->
set
(
$section_storage
);
return
$this
->
rebuildLayout
(
$section_storage
);
}
}
return
$this
->
rebuildLayout
(
$section_storage
);
$response
=
$this
->
rebuildLayout
(
$section_storage
);
$block_type
=
BlockContentType
::
load
(
$block
->
bundle
());
$message
=
$this
->
t
(
'The "@block_type" block type is not permitted for the "@section_type" layout section.'
,
[
'@block_type'
=>
$block_type
->
label
(),
'@section_type'
=>
$layout
->
getPluginDefinition
()
->
getLabel
(),
]);
$selector
=
'form.layout-builder-form'
;
$response
->
addCommand
(
new
MessageCommand
(
$message
,
$selector
,
[
'type'
=>
'error'
],
TRUE
));
$response
->
addCommand
(
new
ScrollTopCommand
(
$selector
));
return
$response
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment