You are here

private function CookieContentBlockerFilter::decodeSettings in Cookie Content Blocker 8

Decode a encoded settings string to a settings array.

Parameters

string $settings: The settings string to decode.

Return value

array The decoded settings or an empty array if decoding failed.

1 call to CookieContentBlockerFilter::decodeSettings()
CookieContentBlockerFilter::replaceTags in src/Plugin/Filter/CookieContentBlockerFilter.php
Replaces cookie content blocker tags for the given text.

File

src/Plugin/Filter/CookieContentBlockerFilter.php, line 142

Class

CookieContentBlockerFilter
Text filter that converts custom HTML tags into markup.

Namespace

Drupal\cookie_content_blocker\Plugin\Filter

Code

private function decodeSettings(string $settings) : array {

  // Check if we need to decode the settings first. This way we support
  // both base64 encoded strings and settings already in a JSON-string format.
  $decoded_settings = base64_decode($settings);
  $needs_decode = base64_encode($decoded_settings) === $settings;
  if ($needs_decode && is_string($decoded_settings)) {
    $settings = $decoded_settings;
  }
  $settings = Xss::filter($settings, []);
  $settings = json_decode($settings, TRUE);
  return $settings ?: [];
}