Domain.php in GoogleTagManager 8
File
src/Plugin/Condition/Domain.php
View source
<?php
namespace Drupal\google_tag\Plugin\Condition;
use Drupal\google_tag\ConditionBase;
use Drupal\domain\DomainNegotiator;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Domain extends ConditionBase implements ContainerFactoryPluginInterface {
protected $domainNegotiator;
public function __construct(DomainNegotiator $domain_negotiator, EntityStorageInterface $storage_manager, array $configuration, $plugin_id, $plugin_definition) {
$this->toggle = 'domain_toggle';
$this->list = 'domain_list';
$this->singular = 'domain';
$this->plural = 'domains';
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->domainNegotiator = $domain_negotiator;
$this->options = array_map('\\Drupal\\Component\\Utility\\Html::escape', $storage_manager
->loadOptionsList());
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('domain.negotiator'), $container
->get('entity_type.manager')
->getStorage('domain'), $configuration, $plugin_id, $plugin_definition);
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
if (isset($form['context_mapping']['entity:domain']['#title'])) {
$form['context_mapping']['entity:domain']['#title'] = $this
->t('Select the Domain context');
$form['context_mapping']['entity:domain']['#description'] = $this
->t('This value must be set to "Active domain" for the context to work.');
}
return $form;
}
public function summary() {
$this->values = array_intersect_key($this->options, $this->configuration['domain_list']);
return parent::summary();
}
public function getCacheContexts() {
$contexts = parent::getCacheContexts();
$contexts[] = 'url.site';
return $contexts;
}
public function contextToEvaluate() {
$domain = $this
->getContextValue('entity:domain');
if (!$domain) {
$domain = $this->domainNegotiator
->getActiveDomain();
}
if (empty($domain)) {
return FALSE;
}
return $domain
->id();
}
}
Classes
Name |
Description |
Domain |
Provides a 'Domain' condition. |