Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inline_entity_form
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
inline_entity_form
Merge requests
!38
Issue
#3002175
: Custom blocks created in inline forms should not be reusable
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#3002175
: Custom blocks created in inline forms should not be reusable
issue/inline_entity_form-3002175:3002175-custom-blocks-created
into
8.x-1.x
Overview
0
Commits
4
Pipelines
0
Changes
7
Open
Oleh Shevchuk
requested to merge
issue/inline_entity_form-3002175:3002175-custom-blocks-created
into
8.x-1.x
3 years ago
Overview
0
Commits
4
Pipelines
0
Changes
7
Expand
Closes
#3002175
Edited
3 years ago
by
Oleh Shevchuk
0
0
Merge request reports
Compare
8.x-1.x
version 5
30e668ac
1 year ago
version 4
d1cfa035
2 years ago
version 3
efd080ab
2 years ago
version 2
308692df
2 years ago
version 1
9cbe473d
3 years ago
8.x-1.x (HEAD)
and
latest version
latest version
ca228c78
4 commits,
9 months ago
version 5
30e668ac
2 commits,
1 year ago
version 4
d1cfa035
1 commit,
2 years ago
version 3
efd080ab
2 commits,
2 years ago
version 2
308692df
2 commits,
2 years ago
version 1
9cbe473d
1 commit,
3 years ago
7 files
+
391
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
Search (e.g. *.vue) (Ctrl+P)
src/EventSubscriber/SetInlineBlockDependencyNested.php
0 → 100644
+
103
−
0
Options
<?php
namespace
Drupal\inline_entity_form\EventSubscriber
;
use
Drupal\block_content
\BlockContentEvents
;
use
Drupal\block_content
\BlockContentInterface
;
use
Drupal\block_content
\Event\BlockContentGetDependencyEvent
;
use
Drupal\Core\Routing\RouteMatchInterface
;
use
Drupal\node\ContextProvider\NodeRouteContext
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
/**
* Override Layout Builder SetInlineBlockDependencyWithContextTranslation.
*
* Handles handle nested blocks.
*
* This is copied from the version in layout_builder_at, except for skipping
* the test isBlockRevisionUsedInEntity().
*/
class
SetInlineBlockDependencyNested
implements
EventSubscriberInterface
{
/**
* The currently active route match object.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected
RouteMatchInterface
$routeMatch
;
/**
* The node route context service.
*
* @var \Drupal\node\ContextProvider\NodeRouteContext
*/
protected
NodeRouteContext
$nodeRouteContext
;
/**
* Constructs event subscriber.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The currently active route match object.
* @param \Drupal\node\ContextProvider\NodeRouteContext $node_route_context
* The node route context service.
*/
public
function
__construct
(
RouteMatchInterface
$route_match
,
NodeRouteContext
$node_route_context
)
{
$this
->
routeMatch
=
$route_match
;
$this
->
nodeRouteContext
=
$node_route_context
;
}
/**
* Handles the BlockContentEvents::INLINE_BLOCK_GET_DEPENDENCY event.
*
* @param \Drupal\block_content\Event\BlockContentGetDependencyEvent $event
* The event.
*
* @throws \Drupal\Component\Plugin\Exception\ContextException
*/
public
function
onGetDependency
(
BlockContentGetDependencyEvent
$event
)
{
if
(
$dependency
=
$this
->
getInlineBlockDependency
(
$event
->
getBlockContentEntity
()))
{
$event
->
setAccessDependency
(
$dependency
);
}
}
/**
* {@inheritdoc}
*/
public
static
function
getSubscribedEvents
()
{
return
[
BlockContentEvents
::
BLOCK_CONTENT_GET_DEPENDENCY
=>
[
'onGetDependency'
,
-
100
,
],
];
}
/**
* Get the access dependency of an inline block.
*
* @param \Drupal\block_content\BlockContentInterface $block_content
* The block content entity.
*
* @return \Drupal\Core\Entity\EntityInterface|null
* Returns the entity dependency.
*
* @throws \Drupal\Component\Plugin\Exception\ContextException
*/
protected
function
getInlineBlockDependency
(
BlockContentInterface
$block_content
)
{
// @todo Find a better way to get child blocks dependencies.
// Try to extract the node route context.
$contexts
=
$this
->
nodeRouteContext
->
getRuntimeContexts
([]);
/** @var \Drupal\Core\Plugin\Context\Context $nodeContext */
$nodeContext
=
$contexts
[
'node'
];
$entity
=
$nodeContext
->
getContextValue
();
// If we couldn't retrieve the node from the route then we try to get the
// section storage.
if
(
!
$entity
)
{
$entity
=
$this
->
routeMatch
->
getParameter
(
'section_storage'
);
}
return
$entity
;
}
}
Loading