taxonomy_menu_sync-1.0.4/src/TaxonomyMenuSyncListBuilder.php

src/TaxonomyMenuSyncListBuilder.php
<?php

namespace Drupal\taxonomy_menu_sync;

use Drupal\Component\Serialization\Json;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Url;

/**
 * Provides a list controller for taxonomy_menu_sync entity.
 */
class TaxonomyMenuSyncListBuilder extends EntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['label'] = $this->t('Name');
    $header['is_synced'] = $this->t('Is synced');
    $header['updated'] = $this->t('Updated');
    $header['created'] = $this->t('Created');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    /** @var \Drupal\taxonomy_menu_sync\Entity\TaxonomyMenuSync $entity */
    $date_format = 'D, d M Y H:i:s';
    $row['label'] = $entity->toLink()->toString();
    $row['is_synced'] = $entity->isSynced() ? $this->t('Yes') : $this->t('No');
    $row['updated'] = \DateTime::createFromFormat('U', $entity->getUpdatedTime())->format($date_format);
    $row['created'] = \DateTime::createFromFormat('U', $entity->getCreatedTime())->format($date_format);
    $operations = parent::buildRow($entity);
    $operations['operations']['data']['#links']['sync'] = [
      'title' => $this->t('Synchronize'),
      'url' => Url::fromRoute('taxonomy_menu_sync.sync', ['taxonomy_menu_sync' => $entity->id()]),
      'attributes' => [
        'class' => ['use-ajax'],
        'data-dialog-type' => 'modal',
        'data-dialog-options' => Json::encode([
          'width' => 880,
        ]),
      ],
    ];
    return $row + $operations;
  }

}

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

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