WebformAccessTypeListBuilder.php in Webform 6.x
File
modules/webform_access/src/WebformAccessTypeListBuilder.php
View source
<?php
namespace Drupal\webform_access;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\webform\EntityListBuilder\WebformEntityListBuilderSortLabelTrait;
use Drupal\webform\EntityStorage\WebformEntityStorageTrait;
use Drupal\webform\Utility\WebformDialogHelper;
use Drupal\webform_access\Entity\WebformAccessGroup;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WebformAccessTypeListBuilder extends ConfigEntityListBuilder {
use WebformEntityListBuilderSortLabelTrait;
use WebformEntityStorageTrait;
protected $limit = FALSE;
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
$instance = parent::createInstance($container, $entity_type);
$instance->entityTypeManager = $container
->get('entity_type.manager');
return $instance;
}
public function render() {
$build = [];
$build['info'] = $this
->buildInfo();
$build += parent::render();
$build['table']['#sticky'] = TRUE;
$build['#attached']['library'][] = 'webform/webform.admin.dialog';
return $build;
}
protected function buildInfo() {
$total = $this
->getStorage()
->getQuery()
->count()
->execute();
if (!$total) {
return [];
}
return [
'#markup' => $this
->formatPlural($total, '@count access type', '@count access types'),
'#prefix' => '<div>',
'#suffix' => '</div>',
];
}
public function buildHeader() {
$header['label'] = $this
->t('Label');
$header['groups'] = [
'data' => $this
->t('Groups'),
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
];
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->toLink($entity
->label(), 'edit-form');
$entity_ids = $this
->getEntityStorage('webform_access_group')
->getQuery()
->condition('type', $entity
->id())
->execute();
$items = [];
if ($entity_ids) {
$webform_access_groups = WebformAccessGroup::loadMultiple($entity_ids);
foreach ($webform_access_groups as $webform_access_group) {
$items[] = $webform_access_group
->label();
}
}
$row['groups'] = [
'data' => [
'#theme' => 'item_list',
'#items' => $items,
],
];
return $row + parent::buildRow($entity);
}
public function getDefaultOperations(EntityInterface $entity, $type = 'edit') {
$operations = parent::getDefaultOperations($entity);
if (isset($operations['delete'])) {
$operations['delete']['attributes'] = WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NARROW);
}
return $operations;
}
public function buildOperations(EntityInterface $entity) {
return parent::buildOperations($entity) + [
'#prefix' => '<div class="webform-dropbutton">',
'#suffix' => '</div>',
];
}
}