You are here

class DefaultProcessor in Cookie Content Blocker 8

Class DefaultProcessor.

Applies defaults to the blocker element as configured in settings. Makes sure the element is wrapped as well.

@package Drupal\cookie_content_blocker\ElementProcessor

Hierarchy

Expanded class hierarchy of DefaultProcessor

1 string reference to 'DefaultProcessor'
cookie_content_blocker.services.yml in ./cookie_content_blocker.services.yml
cookie_content_blocker.services.yml
1 service uses DefaultProcessor
cookie_content_blocker.element.processor.default in ./cookie_content_blocker.services.yml
Drupal\cookie_content_blocker\ElementProcessor\DefaultProcessor

File

src/ElementProcessor/DefaultProcessor.php, line 17

Namespace

Drupal\cookie_content_blocker\ElementProcessor
View source
class DefaultProcessor extends ElementProcessorBase {

  /**
   * The config factory service.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  private $configFactory;

  /**
   * Constructs a DefaultProcessor object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory service.
   */
  public function __construct(ConfigFactoryInterface $config_factory) {
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(array $element) : bool {
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function processElement(array $element) : array {
    $config = $this->configFactory
      ->get('cookie_content_blocker.settings');
    $element['#theme_wrappers'] = $element['#theme_wrappers'] ?? [];
    $element['#theme_wrappers'][] = 'cookie_content_blocker_wrapper';
    if (!is_array($element['#cookie_content_blocker'])) {
      $element['#cookie_content_blocker'] = [];
    }
    $defaults = [
      'blocked_message' => $config
        ->get('blocked_message'),
      'show_button' => $config
        ->get('show_button'),
      'button_text' => $config
        ->get('button_text'),
      'enable_click' => $config
        ->get('enable_click_consent_change'),
      'show_placeholder' => TRUE,
      'preview' => [],
    ];
    $element['#cookie_content_blocker'] = array_merge($defaults, $element['#cookie_content_blocker']);
    return $element;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DefaultProcessor::$configFactory private property The config factory service.
DefaultProcessor::applies public function Declares if the route processor applies to the given element. Overrides ElementProcessorBase::applies
DefaultProcessor::processElement public function Processes the element. Overrides ElementProcessorBase::processElement
DefaultProcessor::__construct public function Constructs a DefaultProcessor object.
ElementProcessorBase::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.