FlagListsFlagListBuilder.php in Flag Lists 4.0.x
File
src/FlagListsFlagListBuilder.php
View source
<?php
namespace Drupal\flag_lists;
use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\UserInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\flag\Controller\FlagListBuilder;
class FlagListsFlagListBuilder extends FlagListBuilder {
protected $configFactory;
protected $flagListsService;
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity_type.manager')
->getStorage($entity_type
->id()), $container
->get('config.factory'), $container
->get('flaglists'));
}
public function __construct(ConfigEntityType $entity_type, EntityStorageInterface $storage, ConfigFactoryInterface $config_factory, FlagListsService $flag_lists_service) {
parent::__construct($entity_type, $storage);
$this->configFactory = $config_factory;
$this->flagListsService = $flag_lists_service;
}
public function buildHeader() {
$total = parent::buildHeader();
$header['flagListUsage'] = $this
->t('Flag Lists Usage');
$header['creator'] = $this
->t('Creator');
$first_array = array_splice($total, 0, 5);
$total = array_merge($first_array, $header, $total);
return $total;
}
public function buildRow(EntityInterface $entity) {
$row['flagListUsage']['#markup'] = $this
->t('-');
$row['creator']['#markup'] = $this
->t('-');
$total = parent::buildRow($entity);
if (!empty($this->flagListsService
->getFlagForListById($entity
->id()))) {
$row['flagListUsage']['#markup'] = $this
->t('Template');
}
if (!empty($this->flagListsService
->getflaggingCollectionIdByRelated($entity
->id()))) {
$config = $this->configFactory
->get('flag_lists.settings');
if ($config
->get('hide_collections') == 1) {
return NULL;
}
$row['flagListUsage']['#markup'] = $this
->t('Flagging Collection');
$flaggingCollectionId = $this->flagListsService
->getflaggingCollectionIdByRelated($entity
->id());
$flaggingCollectionId = array_key_first($flaggingCollectionId);
$row['creator']['#markup'] = $this->flagListsService
->getFlaggingCollectionById($flaggingCollectionId)
->getOwner()
->getDisplayName();
$flaggingCollectionId = implode("|", $this->flagListsService
->getflaggingCollectionIdByRelated($entity
->id()));
$firstItem['view']['title'] = $this
->t('View');
$firstItem['view']['weight'] = 10;
$firstItem['view']['url'] = Url::fromRoute('entity.flagging_collection.canonical', [
'flagging_collection' => $flaggingCollectionId,
]);
$subTotal = $firstItem + $total['operations']['data']['#links'];
$total['operations']['data']['#links'] = $subTotal;
unset($total['operations']['data']['#links']['edit']);
unset($total['operations']['data']['#links']['disable']);
unset($total['operations']['data']['#links']['delete']);
unset($total['operations']['data']['#links']['reset']);
unset($total['operations']['data']['#links']['manage-fields']);
unset($total['operations']['data']['#links']['manage-form-display']);
unset($total['operations']['data']['#links']['manage-display']);
}
$first_array = array_splice($total, 0, 5);
$total = array_merge($first_array, $row, $total);
return $total;
}
}