You are here

HomeboxListBuilder.php in Homebox 8

Namespace

Drupal\homebox

File

src/HomeboxListBuilder.php
View source
<?php

namespace Drupal\homebox;

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

/**
 * Provides a listing of Homebox entities.
 */
class HomeboxListBuilder extends ConfigEntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['label'] = $this
      ->t('Homebox');
    $header['id'] = $this
      ->t('Machine name');
    return $header + parent::buildHeader();
  }

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

    // You probably want a few more properties here...
    return $row + parent::buildRow($entity);
  }

  /**
   * Gets this list's default operations.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity the operations are for.
   *
   * @return array
   *   The array structure is identical to the return value of
   *   self::getOperations().
   */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);
    if ($entity
      ->access('update') && $entity
      ->hasLinkTemplate('settings-form')) {
      $operations['layout'] = [
        'title' => $this
          ->t('Settings'),
        'weight' => 20,
        'url' => $this
          ->ensureDestination(Url::fromRoute('homebox.settings_form', [
          'homebox' => $entity
            ->id(),
        ])),
      ];
    }
    return $operations;
  }

}

Classes

Namesort descending Description
HomeboxListBuilder Provides a listing of Homebox entities.