headless_cms-1.0.3/modules/headless_cms_notify/src/Controller/HeadlessNotifyTransportListBuilder.php

modules/headless_cms_notify/src/Controller/HeadlessNotifyTransportListBuilder.php
<?php

declare(strict_types=1);

namespace Drupal\headless_cms_notify\Controller;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides a listing of headless_cms_notify transports.
 */
class HeadlessNotifyTransportListBuilder extends ConfigEntityListBuilder {

  /**
   * A configuration object.
   */
  protected ImmutableConfig $config;

  public function __construct(
    EntityTypeInterface $entity_type,
    EntityStorageInterface $storage,
    ConfigFactoryInterface $config_factory,
  ) {
    parent::__construct($entity_type, $storage);
    $this->config = $config_factory->get('headless_cms_notify.settings');
  }

  /**
   * {@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('config.factory')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['label'] = $this->t('Label');
    $header['transport_plugin'] = $this->t('Transport Plugin');

    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    /** @var \Drupal\headless_cms_notify\Entity\HeadlessNotifyTransport $entity */

    $row['label'] = $entity->label();

    // Render encryption method row.
    if ($transport = $entity->getTransportPlugin()) {
      $row['transport_plugin'] = $transport->getLabel();
    }
    else {
      $row['transport_plugin'] = $this->t('Error loading transport plugin');
    }

    return $row + parent::buildRow($entity);
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultOperations(EntityInterface $entity) {
    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
    $operations = parent::getDefaultOperations($entity);

    return $operations;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    $build = parent::render();
    $build['table']['#empty'] = $this->t('No transports are available. <a href=":link">Add a transport</a>.', [':link' => Url::fromRoute('entity.headless_notify_transport.add_form')->toString()]);
    return $build;
  }

}

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

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