Skip to content
Snippets Groups Projects
Verified Commit 387bb4eb authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3443118 by thejimbirch, longwave: Enum cases may need to change to UpperCamelCase

(cherry picked from commit 86456c90f1ed9ca36b83ba8d5c9f112e0e919e1b)
parent 3441e824
No related branches found
No related tags found
1 merge request!7908Recipes API on 10.3.x
......@@ -32,7 +32,7 @@ final class ActionMethod {
* logical sense.
*/
public function __construct(
public readonly Exists $exists = Exists::ERROR_IF_NOT_EXISTS,
public readonly Exists $exists = Exists::ErrorIfNotExists,
public readonly TranslatableMarkup|string $adminLabel = '',
public readonly bool|string $pluralize = TRUE
) {
......
......@@ -12,10 +12,10 @@
* This API is experimental.
*/
enum Exists {
case ERROR_IF_EXISTS;
case ERROR_IF_NOT_EXISTS;
case RETURN_EARLY_IF_EXISTS;
case RETURN_EARLY_IF_NOT_EXISTS;
case ErrorIfExists;
case ErrorIfNotExists;
case ReturnEarlyIfExists;
case ReturnEarlyIfNotExists;
/**
* Determines if an action should return early depending on $entity.
......@@ -33,10 +33,10 @@ enum Exists {
*/
public function returnEarly(string $configName, ?ConfigEntityInterface $entity): bool {
return match (TRUE) {
$this === self::RETURN_EARLY_IF_EXISTS && $entity !== NULL,
$this === self::RETURN_EARLY_IF_NOT_EXISTS && $entity === NULL => TRUE,
$this === self::ERROR_IF_EXISTS && $entity !== NULL => throw new ConfigActionException(sprintf('Entity %s exists', $configName)),
$this === self::ERROR_IF_NOT_EXISTS && $entity === NULL => throw new ConfigActionException(sprintf('Entity %s does not exist', $configName)),
$this === self::ReturnEarlyIfExists && $entity !== NULL,
$this === self::ReturnEarlyIfNotExists && $entity === NULL => TRUE,
$this === self::ErrorIfExists && $entity !== NULL => throw new ConfigActionException(sprintf('Entity %s exists', $configName)),
$this === self::ErrorIfNotExists && $entity === NULL => throw new ConfigActionException(sprintf('Entity %s does not exist', $configName)),
default => FALSE
};
}
......
......@@ -22,10 +22,10 @@ public function getDerivativeDefinitions($base_plugin_definition) {
// These derivatives apply to all entity types.
$base_plugin_definition['entity_types'] = ['*'];
$this->derivatives['ensure_exists'] = $base_plugin_definition + ['constructor_args' => ['exists' => Exists::RETURN_EARLY_IF_EXISTS]];
$this->derivatives['ensure_exists'] = $base_plugin_definition + ['constructor_args' => ['exists' => Exists::ReturnEarlyIfExists]];
$this->derivatives['ensure_exists']['admin_label'] = $this->t('Ensure entity exists');
$this->derivatives['create'] = $base_plugin_definition + ['constructor_args' => ['exists' => Exists::ERROR_IF_EXISTS]];
$this->derivatives['create'] = $base_plugin_definition + ['constructor_args' => ['exists' => Exists::ErrorIfExists]];
$this->derivatives['create']['admin_label'] = $this->t('Entity create');
return $this->derivatives;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment