Add a requiresEntity boolean to quick form plugins to optionally prevent creating default instances.
This commit is contained in:
parent
9811f7c7f7
commit
554afce229
|
@ -52,4 +52,11 @@ class QuickForm extends Plugin {
|
|||
*/
|
||||
public $permissions;
|
||||
|
||||
/**
|
||||
* Require a quick form instance entity to instantiate.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $requiresEntity;
|
||||
|
||||
}
|
||||
|
|
|
@ -105,6 +105,13 @@ class QuickFormBase extends PluginBase implements QuickFormInterface, ContainerF
|
|||
return $this->pluginDefinition['helpText'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function requiresEntity() {
|
||||
return $this->pluginDefinition['requiresEntity'] ?? FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -71,6 +71,14 @@ interface QuickFormInterface extends FormInterface {
|
|||
*/
|
||||
public function getPermissions();
|
||||
|
||||
/**
|
||||
* Whether the plugin requires a quick form instance configuration entity.
|
||||
*
|
||||
* @return bool
|
||||
* Boolean.
|
||||
*/
|
||||
public function requiresEntity();
|
||||
|
||||
/**
|
||||
* Checks access for the quick form.
|
||||
*
|
||||
|
|
|
@ -64,9 +64,10 @@ class QuickFormInstanceManager implements QuickFormInstanceManagerInterface {
|
|||
$instances += $entities;
|
||||
}
|
||||
|
||||
// If there are no config entities, create a new (unsaved) config entity
|
||||
// with default values from the plugin.
|
||||
else {
|
||||
// Or, if this plugin does not require a quick form instance configuration
|
||||
// entity, then add a new (unsaved) config entity with default values from
|
||||
// the plugin.
|
||||
elseif (empty($plugin['requiresEntity'])) {
|
||||
$instances[$plugin['id']] = QuickFormInstance::create(['id' => $plugin['id'], 'plugin' => $plugin['id']]);
|
||||
}
|
||||
}
|
||||
|
@ -86,9 +87,15 @@ class QuickFormInstanceManager implements QuickFormInstanceManagerInterface {
|
|||
return $entity;
|
||||
}
|
||||
|
||||
// Otherwise, create a new (unsaved) config entity with default values from
|
||||
// Or, if this plugin does not require a quick form instance configuration
|
||||
// entity, then add a new (unsaved) config entity with default values from
|
||||
// the plugin.
|
||||
return QuickFormInstance::create(['id' => $id, 'plugin' => $id]);
|
||||
elseif (empty($plugin['requiresEntity'])) {
|
||||
return QuickFormInstance::create(['id' => $id, 'plugin' => $id]);
|
||||
}
|
||||
|
||||
// No quick form could be instantiated.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue