You are here

class EntityImportStatusListBuilder in Entity Share 8.3

Provides a listing of Import status entities.

Hierarchy

Expanded class hierarchy of EntityImportStatusListBuilder

File

modules/entity_share_client/src/EntityImportStatusListBuilder.php, line 22

Namespace

Drupal\entity_share_client
View source
class EntityImportStatusListBuilder extends EntityListBuilder {

  /**
   * The format for the import time.
   *
   * Long format, with seconds.
   */
  const IMPORT_DATE_FORMAT = 'F j, Y - H:i:s';

  /**
   * The date formatter service.
   *
   * @var \Drupal\Core\Datetime\DateFormatterInterface
   */
  protected $dateFormatter;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
   */
  protected $entityTypeBundleInfo;

  /**
   * The language manager.
   *
   * @var \Drupal\Core\Language\LanguageManagerInterface
   */
  protected $languageManager;

  /**
   * Constructs a new UserListBuilder object.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type definition.
   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
   *   The entity storage class.
   * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
   *   The date formatter service.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
   *   The entity type bundle info.
   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
   *   The language manager.
   */
  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, LanguageManagerInterface $language_manager) {
    parent::__construct($entity_type, $storage);
    $this->dateFormatter = $date_formatter;
    $this->entityTypeManager = $entity_type_manager;
    $this->entityTypeBundleInfo = $entity_type_bundle_info;
    $this->languageManager = $language_manager;
  }

  /**
   * {@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('date.formatter'), $container
      ->get('entity_type.manager'), $container
      ->get('entity_type.bundle.info'), $container
      ->get('language_manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header = [];
    $header['id'] = $this
      ->t('ID');
    $header['entity_uuid'] = $this
      ->t('Entity UUID');
    $header['entity_id'] = $this
      ->t('Entity ID');
    $header['langcode'] = $this
      ->t('Language');
    $header['entity_label'] = $this
      ->t('Link to entity');
    $header['entity_type_id'] = $this
      ->t('Entity type');
    $header['entity_bundle'] = $this
      ->t('Bundle');
    $header['remote_website'] = $this
      ->t('Remote');
    $header['channel_id'] = $this
      ->t('Channel');
    $header['last_import'] = $this
      ->t('Last import');
    $header['policy'] = $this
      ->t('Policy');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $row = [];
    $row['id'] = $entity
      ->id();

    // Load the imported entity.
    $imported_entity_storage = $this->entityTypeManager
      ->getStorage($entity->entity_type_id->value);
    $imported_entity = $imported_entity_storage
      ->load($entity->entity_id->value);

    // Basic keys of imported entity.
    $row['entity_uuid'] = $entity->entity_uuid->value;
    $row['entity_id'] = $entity->entity_id->value;
    $row['langcode'] = $this->languageManager
      ->getLanguage($entity->langcode->value)
      ->getName();

    // Label and link to entity should respect the language.

    /** @var \Drupal\Core\Entity\ContentEntityInterface $imported_entity_translation */
    $imported_entity_translation = $imported_entity
      ->getTranslation($entity->langcode->value);
    try {
      $row['entity_label'] = $imported_entity_translation
        ->toLink($imported_entity_translation
        ->label());
    } catch (UndefinedLinkTemplateException $exception) {
      $row['entity_label'] = $imported_entity_translation
        ->label();
    }

    // Label of entity type.
    $row['entity_type_id'] = $imported_entity_storage
      ->getEntityType()
      ->getLabel();

    // Imported entity's bundle.
    $bundle_info = $this->entityTypeBundleInfo
      ->getBundleInfo($entity->entity_type_id->value);
    $row['entity_bundle'] = $bundle_info[$entity->entity_bundle->value]['label'] ?? $entity->entity_bundle->value;

    // Remote website.
    $remote = $this->entityTypeManager
      ->getStorage('remote')
      ->load($entity->remote_website->value);
    $row['remote_website'] = $remote
      ->label();

    // Machine name of the import channel.
    $row['channel_id'] = $entity->channel_id->value;

    // Last import time.
    $row['last_import'] = $this->dateFormatter
      ->format($entity
      ->getLastImport(), 'custom', self::IMPORT_DATE_FORMAT);

    // Label of the import policy (or raw value if illegal).
    $available_policies = EntityImportStatus::getAvailablePolicies();
    $row['policy'] = $available_policies[$entity
      ->getPolicy()] ?? $entity
      ->getPolicy();
    return $row + parent::buildRow($entity);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EntityHandlerBase::$moduleHandler protected property The module handler to invoke hooks on. 2
EntityHandlerBase::moduleHandler protected function Gets the module handler. 2
EntityHandlerBase::setModuleHandler public function Sets the module handler for this handler.
EntityImportStatusListBuilder::$dateFormatter protected property The date formatter service.
EntityImportStatusListBuilder::$entityTypeBundleInfo protected property The entity type manager.
EntityImportStatusListBuilder::$entityTypeManager protected property The entity type manager.
EntityImportStatusListBuilder::$languageManager protected property The language manager.
EntityImportStatusListBuilder::buildHeader public function Builds the header row for the entity listing. Overrides EntityListBuilder::buildHeader
EntityImportStatusListBuilder::buildRow public function Builds a row for an entity in the entity listing. Overrides EntityListBuilder::buildRow
EntityImportStatusListBuilder::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityListBuilder::createInstance
EntityImportStatusListBuilder::IMPORT_DATE_FORMAT constant The format for the import time.
EntityImportStatusListBuilder::__construct public function Constructs a new UserListBuilder object. Overrides EntityListBuilder::__construct
EntityListBuilder::$entityType protected property Information about the entity type.
EntityListBuilder::$entityTypeId protected property The entity type ID.
EntityListBuilder::$limit protected property The number of entities to list per page, or FALSE to list all entities. 3
EntityListBuilder::$storage protected property The entity storage class. 1
EntityListBuilder::buildOperations public function Builds a renderable list of operation links for the entity. 2
EntityListBuilder::ensureDestination protected function Ensures that a destination is present on the given URL.
EntityListBuilder::getDefaultOperations protected function Gets this list's default operations. 2
EntityListBuilder::getEntityIds protected function Loads entity IDs using a pager sorted by the entity id. 4
EntityListBuilder::getLabel Deprecated protected function Gets the label of an entity.
EntityListBuilder::getOperations public function Provides an array of information to build a list of operation links. Overrides EntityListBuilderInterface::getOperations 2
EntityListBuilder::getStorage public function Gets the entity storage. Overrides EntityListBuilderInterface::getStorage
EntityListBuilder::getTitle protected function Gets the title of the page. 1
EntityListBuilder::load public function Loads entities of this type from storage for listing. Overrides EntityListBuilderInterface::load 4
EntityListBuilder::render public function Builds the entity listing as renderable array for table.html.twig. Overrides EntityListBuilderInterface::render 16
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.