GroupMenuContentListBuilder.php in Group Menu 8
File
src/GroupMenuContentListBuilder.php
View source
<?php
namespace Drupal\groupmenu;
use Drupal\Core\Entity\EntityInterface;
use Drupal\group\Entity\Controller\GroupContentListBuilder;
use Drupal\group\Entity\GroupContentType;
class GroupMenuContentListBuilder extends GroupContentListBuilder {
protected function getEntityIds() {
$plugin_id = 'group_menu:menu';
$group_content_types = GroupContentType::loadByContentPluginId($plugin_id);
if (empty($group_content_types)) {
return [];
}
$query = $this
->getStorage()
->getQuery();
$query
->condition('type', array_keys($group_content_types), 'IN');
$query
->condition('gid', $this->group
->id());
if ($this->limit) {
$query
->pager($this->limit);
}
$query
->sort($this->entityType
->getKey('id'));
return $query
->execute();
}
public function buildHeader() {
$header = [
'id' => $this
->t('ID'),
'label' => $this
->t('Menu'),
];
$row = $header + parent::buildHeader();
unset($row['entity_type'], $row['plugin']);
return $row;
}
public function buildRow(EntityInterface $entity) {
$row['id'] = $entity
->id();
$row['label']['data'] = $entity
->getEntity()
->toLink(NULL, 'edit-form');
$row = $row + parent::buildRow($entity);
unset($row['entity_type'], $row['plugin']);
return $row;
}
public function render() {
$build = parent::render();
$build['table']['#empty'] = $this
->t("There are no menus related to this group yet.");
return $build;
}
protected function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
if (!isset($operations['view']) && $entity
->access('view')) {
$operations['view'] = [
'title' => $this
->t('View relation'),
'weight' => 1,
'url' => $entity
->toUrl(),
];
}
$destination = $this->redirectDestination
->getAsArray();
foreach ($operations as $key => $operation) {
$operations[$key]['query'] = $destination;
}
if ($entity
->getEntity()
->access('update')) {
$operations['edit-entity'] = [
'title' => $this
->t('Edit menu'),
'weight' => 102,
'url' => $entity
->getEntity()
->toUrl(),
];
}
if ($entity
->getEntity()
->access('delete')) {
$operations['delete-entity'] = [
'title' => $this
->t('Delete menu'),
'weight' => 103,
'url' => $entity
->getEntity()
->toUrl('delete-form'),
];
}
return $operations;
}
}