class DashboardController in Content Planner 8
Class DashboardController.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\content_planner\Controller\DashboardController
Expanded class hierarchy of DashboardController
File
- src/
Controller/ DashboardController.php, line 16
Namespace
Drupal\content_planner\ControllerView source
class DashboardController extends ControllerBase {
/**
* Drupal\Core\Database\Driver\mysql\Connection definition.
*
* @var \Drupal\Core\Database\Driver\mysql\Connection
*/
protected $database;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The dashboard settings service.
*
* @var \Drupal\content_planner\DashboardSettingsService
*/
protected $dashboardSettingsService;
/**
* The dashboard service.
*
* @var \Drupal\content_planner\DashboardService
*/
protected $dashboardService;
/**
* The dashboard block plugin manager.
*
* @var \Drupal\content_planner\DashboardBlockPluginManager
*/
protected $dashboardBlockPluginManager;
/**
* Constructs a new DashboardController object.
*/
public function __construct(Connection $database, ConfigFactoryInterface $config_factory, DashboardSettingsService $dashboard_settings_service, DashboardService $dashboard_service, DashboardBlockPluginManager $dashboard_block_plugin_manager) {
$this->database = $database;
$this->configFactory = $config_factory;
$this->dashboardSettingsService = $dashboard_settings_service;
$this->dashboardService = $dashboard_service;
$this->dashboardBlockPluginManager = $dashboard_block_plugin_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('database'), $container
->get('config.factory'), $container
->get('content_planner.dashboard_settings_service'), $container
->get('content_planner.dashboard_service'), $container
->get('content_planner.dashboard_block_plugin_manager'));
}
/**
* Showdashboard.
*
* @return array
* The content planner dashboard render array.
*/
public function showDashboard() {
// Check if Content Calendar or Kanban is enabled.
if (!$this->dashboardService
->isContentCalendarEnabled() && !$this->dashboardService
->isContentKanbanEnabled()) {
$this
->messenger()
->addMessage($this
->t('This dashboard can only be used with Content Calendar or Content Kanban enabled'), 'error');
return [];
}
// Get enabled blocks.
$blocks = $this->dashboardSettingsService
->getBlockConfigurations();
// If there are no blocks enabled, display error message.
if (!$blocks) {
$this
->messenger()
->addMessage($this
->t('Dashboard is not configured yet. Please do this in the Settings tab.'), 'error');
return [];
}
// Get registered Plugins.
$plugins = $this->dashboardBlockPluginManager
->getDefinitions();
// Build blocks.
$block_builds = $this
->buildBlocks($blocks, $plugins);
$build = [
'#theme' => 'content_planner_dashboard',
'#blocks' => $block_builds,
'#attached' => [
'library' => [
'content_planner/dashboard',
],
],
];
return $build;
}
/**
* Build blocks.
*
* @param array $blocks
* The blocks to render.
* @param array $plugins
* The block plugins.
*
* @return array
* Array of content block render arrays.
*/
protected function buildBlocks(array &$blocks, array &$plugins) {
$block_builds = [];
// Loop over every enabled block.
foreach ($blocks as $block_id => $block) {
// If a Dashboard Block plugin exists.
if (array_key_exists($block_id, $plugins)) {
/* @var $instance \Drupal\content_planner\DashboardBlockInterface */
$instance = $this->dashboardBlockPluginManager
->createInstance($block_id, $block);
if (\Drupal::currentUser()
->hasPermission('administer content planner dashboard settings')) {
$has_permission = TRUE;
}
else {
$has_permission = FALSE;
}
// Build block render array.
if ($block_build = $instance
->build()) {
$block_builds[$block_id] = [
'#theme' => 'content_planner_dashboard_block',
'#css_id' => str_replace('_', '-', $block_id),
'#block_id' => $block_id,
'#name' => isset($block['title']) && $block['title'] ? $block['title'] : $instance
->getName(),
'#has_permission' => $has_permission,
'#block' => $block_build,
'#weight' => $block['weight'],
];
}
}
}
return $block_builds;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
DashboardController:: |
protected | property |
The config factory. Overrides ControllerBase:: |
|
DashboardController:: |
protected | property | The dashboard block plugin manager. | |
DashboardController:: |
protected | property | The dashboard service. | |
DashboardController:: |
protected | property | The dashboard settings service. | |
DashboardController:: |
protected | property | Drupal\Core\Database\Driver\mysql\Connection definition. | |
DashboardController:: |
protected | function | Build blocks. | |
DashboardController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
DashboardController:: |
public | function | Showdashboard. | |
DashboardController:: |
public | function | Constructs a new DashboardController object. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |