Skip to content
Snippets Groups Projects
Commit 85c71e0f authored by Joseph Olstad's avatar Joseph Olstad
Browse files

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
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment