Refactor dashboard block handling to always expect block plugin ID.
This commit is contained in:
parent
3ea20c1d63
commit
7092a0830f
|
@ -32,12 +32,9 @@ function hook_farm_dashboard_panes() {
|
||||||
'view' => 'my_view',
|
'view' => 'my_view',
|
||||||
'view_display_id' => 'block_1',
|
'view_display_id' => 'block_1',
|
||||||
|
|
||||||
// Specify a 'block' to automatically load a Block.
|
// Specify a block plugin ID to automatically load a Block.
|
||||||
'block' => 'my_block',
|
'block' => 'my_block',
|
||||||
|
|
||||||
// Specify a block plugin id to load custom Blocks.
|
|
||||||
'block_plugin' => 'my_block_plugin_id',
|
|
||||||
|
|
||||||
// Optional arguments to pass to the view or block.
|
// Optional arguments to pass to the view or block.
|
||||||
// This is useful if the view or block can be used in different contexts.
|
// This is useful if the view or block can be used in different contexts.
|
||||||
'args' => [
|
'args' => [
|
||||||
|
|
|
@ -125,37 +125,16 @@ class DashboardController extends ControllerBase {
|
||||||
// Or if a block is provided, display the block.
|
// Or if a block is provided, display the block.
|
||||||
elseif (!empty($pane['block'])) {
|
elseif (!empty($pane['block'])) {
|
||||||
|
|
||||||
/** @var \Drupal\block\Entity\Block $block */
|
|
||||||
$block = $this->entityTypeManager()->getStorage('block')->load($pane['block']);
|
|
||||||
|
|
||||||
// Set the block plugin config if provided.
|
|
||||||
if (!empty($args)) {
|
|
||||||
$block->getPlugin()->setConfiguration($args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the block plugin displays the label by default, set the title.
|
|
||||||
$block_config = $block->getPlugin()->getConfiguration();
|
|
||||||
if ($block_config['label_display']) {
|
|
||||||
$title = $block->label();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the block's weight by default.
|
|
||||||
$weight = $block->getWeight();
|
|
||||||
|
|
||||||
// Build the blocks renderable output.
|
|
||||||
$output = $this->entityTypeManager()->getViewBuilder('block')->view($block);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Or if a plugin block id is provided, display the block.
|
|
||||||
elseif (!empty($pane['block_plugin'])) {
|
|
||||||
// Render plugin block if is set.
|
// Render plugin block if is set.
|
||||||
$block_plugin = $this->blockManager->createInstance($pane['block_plugin'], $args);
|
$block = $this->blockManager->createInstance($pane['block'], $args);
|
||||||
if ($block_plugin) {
|
if ($block) {
|
||||||
|
|
||||||
// Check block access.
|
// Check block access.
|
||||||
$access_result = $block_plugin->access($this->currentUser);
|
$access_result = $block->access($this->currentUser);
|
||||||
if ($access_result == TRUE) {
|
if ($access_result == TRUE) {
|
||||||
|
|
||||||
// Builds renderable array of the block.
|
// Builds renderable array of the block.
|
||||||
$output = $block_plugin->build();
|
$output = $block->build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
langcode: en
|
|
||||||
status: true
|
|
||||||
id: dashboard_test
|
|
||||||
theme: claro
|
|
||||||
weight: 1000
|
|
||||||
provider: null
|
|
||||||
plugin: dashboard_test_block
|
|
||||||
settings:
|
|
||||||
label: 'Dashboard test block label'
|
|
||||||
provider: farm_ui_dashboard_test
|
|
||||||
label_display: '1'
|
|
||||||
visibility: { }
|
|
|
@ -11,7 +11,7 @@
|
||||||
function farm_ui_dashboard_test_farm_dashboard_panes() {
|
function farm_ui_dashboard_test_farm_dashboard_panes() {
|
||||||
return [
|
return [
|
||||||
'dashboard_block' => [
|
'dashboard_block' => [
|
||||||
'block' => 'dashboard_test',
|
'block' => 'dashboard_test_block',
|
||||||
],
|
],
|
||||||
'dashboard_view' => [
|
'dashboard_view' => [
|
||||||
'view' => 'dashboard_test_view',
|
'view' => 'dashboard_test_view',
|
||||||
|
|
|
@ -45,7 +45,6 @@ class DashboardTest extends FarmBrowserTestBase {
|
||||||
$this->assertSession()->statusCodeEquals(200);
|
$this->assertSession()->statusCodeEquals(200);
|
||||||
|
|
||||||
// Assert that the test block was added.
|
// Assert that the test block was added.
|
||||||
$this->assertSession()->pageTextContains('Dashboard test block label');
|
|
||||||
$this->assertSession()->pageTextContains('This is the dashboard test block.');
|
$this->assertSession()->pageTextContains('This is the dashboard test block.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
langcode: en
|
|
||||||
status: false
|
|
||||||
dependencies:
|
|
||||||
enforced:
|
|
||||||
module:
|
|
||||||
- farm_ui_dashboard
|
|
||||||
module:
|
|
||||||
- farm_map
|
|
||||||
theme:
|
|
||||||
- claro
|
|
||||||
id: dashboard_map
|
|
||||||
theme: claro
|
|
||||||
region: content
|
|
||||||
weight: -100
|
|
||||||
provider: null
|
|
||||||
plugin: map_block
|
|
||||||
settings:
|
|
||||||
id: dashboard_map
|
|
||||||
map_type: dashboard
|
|
||||||
label: 'Dashboard map'
|
|
||||||
provider: farm_ui_dashboard
|
|
||||||
label_display: '0'
|
|
||||||
visibility: { }
|
|
|
@ -15,7 +15,10 @@ use Drupal\Core\Link;
|
||||||
function farm_ui_map_farm_dashboard_panes() {
|
function farm_ui_map_farm_dashboard_panes() {
|
||||||
return [
|
return [
|
||||||
'dashboard_map' => [
|
'dashboard_map' => [
|
||||||
'block' => 'dashboard_map',
|
'block' => 'map_block',
|
||||||
|
'args' => [
|
||||||
|
'map_type' => 'dashboard',
|
||||||
|
],
|
||||||
'region' => 'top',
|
'region' => 'top',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
langcode: en
|
|
||||||
status: false
|
|
||||||
dependencies:
|
|
||||||
module:
|
|
||||||
- farm_ui_metrics
|
|
||||||
theme:
|
|
||||||
- claro
|
|
||||||
id: farm_metrics
|
|
||||||
theme: claro
|
|
||||||
region: content
|
|
||||||
weight: 0
|
|
||||||
provider: null
|
|
||||||
plugin: farm_metrics_block
|
|
||||||
settings:
|
|
||||||
id: farm_metrics_block
|
|
||||||
label: 'Metrics'
|
|
||||||
provider: farm_ui_metrics
|
|
||||||
label_display: '0'
|
|
||||||
visibility: { }
|
|
|
@ -11,7 +11,7 @@
|
||||||
function farm_ui_metrics_farm_dashboard_panes() {
|
function farm_ui_metrics_farm_dashboard_panes() {
|
||||||
return [
|
return [
|
||||||
'metrics' => [
|
'metrics' => [
|
||||||
'block' => 'farm_metrics',
|
'block' => 'farm_metrics_block',
|
||||||
'title' => t('Metrics'),
|
'title' => t('Metrics'),
|
||||||
'region' => 'second',
|
'region' => 'second',
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue