Skip to content

Commit 30b3ab4

Browse files
authored
Surface some Conditions in Block Visibility (#1084) (for phasing out display contexts)
* let 'node_has_term' and 'node_is_islandora_object' be in block visibility conditions * add config field to NodeIsIslandoraObject condition Conditions only get applied in Block Visibility when there's a config change for that condition in the block config form, so it needs a field to configure. * more informative field description * some cleanup to config for NodeIsIslandoraObject Much thanks to @adam-vessey for helping to figure this out! * cleanup default config for MediaSourceHasMimetype Might as well get this cleaned up so it stops inserting itself in all the block configs where it's not relevant. * remove unused use statement
1 parent 461b801 commit 30b3ab4

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

islandora.module

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,6 @@ function islandora_form_block_form_alter(&$form, FormStateInterface $form_state,
509509
unset($form['visibility']['node_had_namespace']);
510510
unset($form['visibility']['node_has_ancestor']);
511511
unset($form['visibility']['node_has_parent']);
512-
unset($form['visibility']['node_has_term']);
513-
unset($form['visibility']['node_is_islandora_object']);
514512
unset($form['visibility']['node_referenced_by_node']);
515513
unset($form['visibility']['parent_node_has_term']);
516514
}

src/Plugin/Condition/MediaSourceHasMimetype.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function summary() {
8585
*/
8686
public function defaultConfiguration() {
8787
return array_merge(
88-
['mimetype' => []],
88+
['mimetype' => ""],
8989
parent::defaultConfiguration()
9090
);
9191
}

src/Plugin/Condition/NodeIsIslandoraObject.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
* id = "node_is_islandora_object",
1515
* label = @Translation("Node is an Islandora node"),
1616
* context_definitions = {
17-
* "node" = @ContextDefinition("entity:node", required = TRUE , label = @Translation("node"))
17+
* "node" = @ContextDefinition("entity:node",
18+
* required = FALSE,
19+
* label = @Translation("Node source"),
20+
* description = @Translation("The node source must be set for this condition to work as expected.")
21+
* )
1822
* }
1923
* )
2024
*/
@@ -56,6 +60,28 @@ public static function create(ContainerInterface $container, array $configuratio
5660
);
5761
}
5862

63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public function defaultConfiguration() {
67+
$defaults = parent::defaultConfiguration();
68+
69+
// XXX: There appear to be expectations in Drupal that there will be more
70+
// config to a plugin than just selecting the context mapping; however, it
71+
// is our only configuration. Due to these expectations, it would fail to
72+
// save our visibility settings. To work around, it seems to be sufficient
73+
// to dynamically declare our default configuration, such that the
74+
// difference from the default configuration can be detected upstream.
75+
// @see https://git.drupalcode.org/project/drupal/-/blob/d87ab76d397a2cfe0457997be4f2648c4760b2f5/core/lib/Drupal/Core/Condition/ConditionPluginCollection.php#L39-44
76+
if (!empty($this->configuration['context_mapping'])) {
77+
$defaults += [
78+
'context_mapping' => [],
79+
];
80+
}
81+
82+
return $defaults;
83+
}
84+
5985
/**
6086
* {@inheritdoc}
6187
*/

0 commit comments

Comments
 (0)