You are here

function cookie_content_blocker_element_original_content in Cookie Content Blocker 8

Retrieves the original content for a render element.

Parameters

array $element: The element.

Return value

\Drupal\Component\Render\MarkupInterface|string The markup content.

Throws

\Exception

1 call to cookie_content_blocker_element_original_content()
cookie_content_blocker_preprocess_cookie_content_blocker_wrapper in ./cookie_content_blocker.module
Implements hook_preprocess_HOOK() for cookie_content_blocker_wrapper().

File

./cookie_content_blocker.module, line 112
Contains the main module code for Cookie content blocker.

Code

function cookie_content_blocker_element_original_content(array $element) {
  if (isset($element['#cookie_content_blocker']['original_content'])) {

    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = Drupal::service('renderer');
    return Markup::create(preg_replace('/(<[\\/]?script)/', '$1fake', is_array($element['#cookie_content_blocker']['original_content']) ? (string) $renderer
      ->render($element['#cookie_content_blocker']['original_content']) : $element['#cookie_content_blocker']['original_content']));
  }
  return Markup::create(preg_replace('/(<[\\/]?script)/', '$1fake', $element['#children']));
}