ModerationDashboardAddLinks.php in Moderation Dashboard 2.0.x
File
src/Plugin/Block/ModerationDashboardAddLinks.php
View source
<?php
namespace Drupal\moderation_dashboard\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ModerationDashboardAddLinks extends BlockBase implements ContainerFactoryPluginInterface {
protected $entityTypeManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'));
}
public function build() {
$build = [
'#theme' => 'item_list',
'#attributes' => [
'class' => [
'moderation-dashboard-add-links',
],
],
'#items' => [],
];
$control_handler = $this->entityTypeManager
->getAccessControlHandler('node');
foreach ($this->entityTypeManager
->getStorage('node_type')
->loadMultiple() as $type) {
if ($control_handler
->createAccess($type
->id())) {
$build['#items'][] = [
'#type' => 'link',
'#title' => $type
->label(),
'#url' => new Url('node.add', [
'node_type' => $type
->id(),
]),
];
}
}
return $build;
}
}