ApiDocListBuilder.php in Apigee API Catalog 8
File
src/Entity/ListBuilder/ApiDocListBuilder.php
View source
<?php
namespace Drupal\apigee_api_catalog\Entity\ListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Link;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ApiDocListBuilder extends EntityListBuilder {
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity_type.manager')
->getStorage($entity_type
->id()));
}
public function render() {
$build['description'] = [
'#markup' => $this
->t('Manage your API documentation. You can manage the fields on the <a href=":url">API Docs settings page</a>.', [
':url' => Url::fromRoute('entity.apidoc.settings')
->toString(),
]),
];
$build['table'] = parent::render();
return $build;
}
public function buildHeader() {
$header['id'] = $this
->t('ID');
$header['name'] = $this
->t('Name');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['id'] = $entity
->id();
$row['name'] = $entity
->toLink();
return $row + parent::buildRow($entity);
}
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
if ($entity
->access('reimport')) {
$operations['reimport_spec'] = [
'title' => $this
->t('Re-import OpenAPI spec'),
'weight' => 15,
'url' => $this
->ensureDestination($entity
->toUrl('reimport-spec-form')),
];
}
return $operations;
}
}