Is it possible?
From the docs:
The
conditional
field type is used to conditionally display some other fields base on a condition.
The term “fields” is quite ambiguous, but my first interpretation is “input fields” which excludes “tabs”.
The final verdict might be given by the Grav-team…
Alternative ‘conditional’ approach:
You didn’t share the intention of using a ‘conditional tab’, so maybe the following alternative might not work in your use-case.
You could display a tab conditionally by conditionally publishing the overriding blueprint.
Usually a plugin publishes its blueprints in the event onPageGetBlueprints
. E.g.:
public function onGetPageBlueprints(Event $event) {
$types = $event->types;
$types->scanBlueprints('plugin://' . $this->name . '/blueprints');
}
To publish the blueprint conditionally you could:
- Subscribe to event
onPageGetBlueprints
only when condition is met.if ($condition) { $this->enable([ 'onGetPageBlueprints' => ['onGetPageBlueprints', 0], ]); }
- Or you could wrap the code inside
onPageGetBlueprints
with an if-statement:public function onGetPageBlueprints(Event $event) { if ($condition) { $types = $event->types; $types->scanBlueprints('plugin://' . $this->name . '/blueprints'); } }
IMHO, this approach is much cleaner and less error-prone than messing around in YAML form definitions.