skinr-8.x-2.0-alpha2/skinr_ui/src/Controller/SkinListBuilder.php

skinr_ui/src/Controller/SkinListBuilder.php
<?php

namespace Drupal\skinr_ui\Controller;

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

/**
 * Returns responses for devel module routes.
 */
class SkinListBuilder extends ConfigEntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['id'] = [
      'data' => $this->t('Machine name'),
      'class' => ['skinr-ui-name'],
    ];
    $header['element_type'] = [
      'data' => $this->t('Type'),
      'class' => ['skinr-ui-type'],
    ];
    $header['element'] = [
      'data' => $this->t('Element'),
      'class' => ['skinr-ui-element'],
    ];
    $header['theme'] = [
      'data' => $this->t('Theme'),
      'class' => ['skinr-ui-theme'],
    ];
    $header['label'] = [
      'data' => $this->t('Skin'),
      'class' => ['skinr-ui-skin'],
    ];
    // $header['storage'] = array(
    //   'data' => $this->t('Storage'),
    //   'class' => array('skinr-ui-storage'),
    // );
    $header['status'] = [
      'data' => $this->t('Status'),
      'class' => ['skinr-ui-status'],
    ];

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

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    $row['label'] = [
      'data' => $this->getLabel($entity),
    ];
    $row['element_type'] = [
      'data' => $entity->elementTypeLabel(),
      'class' => ['skin-table-filter-text-source'],
    ];
    $row['element'] = [
      'data' => $entity->elementLabel(),
      'class' => ['skin-table-filter-text-source'],
    ];
    $row['theme'] = [
      'data' => $entity->themeLabel(),
      'class' => ['skin-table-filter-text-source'],
    ];
    $row['skin'] = [
      'data' => $entity->skinLabel(),
      'class' => ['skin-table-filter-text-source'],
    ];
    // $row['storage'] = $entity->getStorage();
    $row['status'] = $entity->status() ? t('Enabled') : t('Disabled');

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

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

    // Override edit link.
    // @todo
    if (isset($operations['edit'])) {
      // dpm($operations['edit']);.
    }

    return $operations;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    $entities = $this->load();
    $list['#type'] = 'container';
    $list['#attributes']['id'] = 'skin-entity-list';

    $list['#attached']['library'][] = 'core/drupal.ajax';
    $list['#attached']['library'][] = 'skinr_ui/skinr_ui.listing';

    $form['filters'] = [
      '#type' => 'container',
      '#attributes' => [
        'class' => ['table-filter', 'js-show'],
      ],
    ];

    $list['filters']['text'] = [
      '#type' => 'search',
      '#title' => $this->t('Filter'),
      '#title_display' => 'invisible',
      '#size' => 40,
      '#placeholder' => $this->t('Filter by view name or description'),
      '#attributes' => [
        'class' => ['skin-filter-text'],
        'data-table' => '.skin-listing-table',
        'autocomplete' => 'off',
        'title' => $this->t('Enter a part of the skin name or description to filter by.'),
      ],
    ];

    $list['enabled']['heading']['#markup'] = '<h2>' . $this->t('Enabled', [], ['context' => 'Plural']) . '</h2>';
    $list['disabled']['heading']['#markup'] = '<h2>' . $this->t('Disabled', [], ['context' => 'Plural']) . '</h2>';
    foreach (['enabled', 'disabled'] as $status) {
      $list[$status]['#type'] = 'container';
      $list[$status]['#attributes'] = ['class' => ['skin-list-section', $status]];
      $list[$status]['table'] = [
        '#type' => 'table',
        '#attributes' => [
          'class' => ['skin-listing-table'],
        ],
        '#header' => $this->buildHeader(),
        '#rows' => [],
      ];
      foreach ($entities as $entity) {
        if ($entity->status() != ($status == 'enabled' ? TRUE : FALSE)) {
          continue;
        }
        $list[$status]['table']['#rows'][$entity->id()] = $this->buildRow($entity);
      }
    }
    // @todo Use a placeholder for the entity label if this is abstracted to
    // other entity types.
    $list['enabled']['table']['#empty'] = $this->t('There are no enabled skins.');
    $list['disabled']['table']['#empty'] = $this->t('There are no disabled skins.');

    return $list;
  }

}

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

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