Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
access_unpublished_linked_nodes
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
access_unpublished_linked_nodes
Commits
85c71e0f
Commit
85c71e0f
authored
5 months ago
by
Joseph Olstad
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3466963
by joseph.olstad: Cleanup as a followup to issue number 3464352
parent
b5b5617a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/AccessUnpublishedHelper.php
+0
-40
0 additions, 40 deletions
src/AccessUnpublishedHelper.php
with
0 additions
and
40 deletions
src/AccessUnpublishedHelper.php
+
0
−
40
View file @
85c71e0f
...
...
@@ -53,9 +53,6 @@ class AccessUnpublishedHelper {
// Remove script tags from the content.
$contentWithoutScripts
=
preg_replace
(
'/<script\b[^>]*>.*?<\/script>/is'
,
''
,
$content
);
// Process embedded blocks.
$contentWithoutScripts
=
self
::
processEmbeddedBlocks
(
$contentWithoutScripts
);
// Use DOMDocument to parse the remaining content and modify links.
$dom
=
new
\DOMDocument
();
@
$dom
->
loadHTML
(
mb_convert_encoding
(
$contentWithoutScripts
,
'HTML-ENTITIES'
,
'UTF-8'
));
...
...
@@ -222,42 +219,5 @@ class AccessUnpublishedHelper {
return
TRUE
;
}
/**
* Processes embedded blocks in the content.
*
* @param string $content
* The content to process.
*
* @return string
* The content with embedded blocks rendered.
*/
public
static
function
processEmbeddedBlocks
(
$content
)
{
if
(
!
\Drupal
::
moduleHandler
()
->
moduleExists
(
'embed_block'
))
{
return
$content
;
}
preg_match_all
(
'/{block:(?<plugin_id>[^}].*)}/'
,
$content
,
$matches
,
PREG_SET_ORDER
);
$processed
=
[];
foreach
(
$matches
as
$found
)
{
if
(
!
isset
(
$processed
[
$found
[
'plugin_id'
]]))
{
try
{
/** @var \Drupal\Core\Block\BlockPluginInterface $block_plugin */
$block_plugin
=
\Drupal
::
service
(
'plugin.manager.block'
)
->
createInstance
(
$found
[
'plugin_id'
]);
if
(
$block_plugin
->
access
(
\Drupal
::
currentUser
()))
{
$build
=
$block_plugin
->
build
();
$block_content
=
\Drupal
::
service
(
'renderer'
)
->
render
(
$build
);
}
else
{
$block_content
=
''
;
}
$content
=
str_replace
(
$found
[
0
],
$block_content
,
$content
);
}
catch
(
\Drupal\Component\Plugin\Exception\PluginException
$exception
)
{
// The plugin doesn't exist, do not touch the placeholder.
}
$processed
[
$found
[
'plugin_id'
]]
=
TRUE
;
}
}
return
$content
;
}
}
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