iframe_consent-1.0.x-dev/src/IframeConsentDomainListBuilder.php

src/IframeConsentDomainListBuilder.php
<?php

namespace Drupal\iframe_consent;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\iframe_consent\Service\IframeConsentHelper;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides a list controller for the domains entity type.
 */
class IframeConsentDomainListBuilder extends EntityListBuilder {

  /**
   * The iframe consent settings service.
   *
   * @var \Drupal\iframe_consent\Service\IframeConsentHelper
   */
  protected $iframeConsentHelper;

  /**
   * IframeConsentDomainListBuilder constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type definition.
   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
   *   The entity storage.
   * @param \Drupal\iframe_consent\Service\IframeConsentHelper $iframeConsentHelper
   *   The iframe consent settings service.
   */
  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, IframeConsentHelper $iframeConsentHelper) {
    parent::__construct($entity_type, $storage);
    $this->iframeConsentHelper = $iframeConsentHelper;
  }

  /**
   * {@inheritdoc}
   */
  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    return new static(
      $entity_type,
      $container->get('entity_type.manager')->getStorage($entity_type->id()),
      $container->get('iframe_consent.helper')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function buildHeader(): array {
    $header['id'] = $this->t('ID');
    $header['domain'] = $this->t('Domain');
    $header['consent_groups'] = $this->t('Consent groups');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity): array {
    /** @var \Drupal\iframe_consent\IframeConsentDomainInterface $entity */
    $row['id'] = $entity->id();
    $row['domain'] = $entity->label();
    $row['consent_groups'] = implode(', ', $this->iframeConsentHelper->getDomainConsentGroups($entity));
    return $row + parent::buildRow($entity);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc