library_manager-8.x-1.0/src/Controller/LibraryDefinitionListBuilder.php

src/Controller/LibraryDefinitionListBuilder.php
<?php

namespace Drupal\library_manager\Controller;

use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;

/**
 * Provides a listing of library definitions.
 */
class LibraryDefinitionListBuilder extends ConfigEntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['id'] = $this->t('Machine name');
    $header['target'] = $this->t('New/Override');
    $header['version'] = $this->t('Version');
    $header['load'] = $this->t('Load');
    $header['override_by_visibility'] = $this->t('Override by visibility');
    $header['status'] = $this->t('Enabled');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    if ($entity->get('target')) {
      $load_row = '';
    } elseif ($entity->get('load')) {
      $load_row = $this->t('Yes');
    } else {
      $load_row = $this->t('No');
    }
    /** @var \Drupal\library_manager\LibraryDefinitionInterface $entity */
    $row['id'] = $entity->id();
    $row['target'] = ($target = $entity->get('target')) ? 'Override:\''.$target.'\'' : 'New:\'library_manager/'.$entity->id().'\'';
    $row['version'] = $entity->get('version');
    $row['load'] = $load_row;
    $row['override_by_visibility'] = $entity->get('override_by_visibility') ? $this->t('Yes') : $this->t('No');
    $row['status'] = $entity->get('status') ? $this->t('Yes') : $this->t('No');
    return $row + parent::buildRow($entity);
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);
    $operations['duplicate'] = [
      'title' => $this->t('Duplicate'),
      'weight' => 50,
      'url' => $entity->toUrl('duplicate-form'),
    ];
    return $operations;
  }

}

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

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