Verified Commit 95a28486 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3455113 by b_sharpe, ankitv18, alexpott, pooja_sharma, phenaproxima,...

Issue #3455113 by b_sharpe, ankitv18, alexpott, pooja_sharma, phenaproxima, thejimbirch: Rename ensure_exists to createIfNotExists, and camel-case simpleConfigUpdate for consistency

(cherry picked from commit 9cd7babd)
parent 7608e93e
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -53,6 +53,22 @@
 */
class ConfigActionManager extends DefaultPluginManager {

  /**
   * Information about all deprecated plugin IDs.
   *
   * @var string[]
   */
  private static array $deprecatedPluginIds = [
    'entity_create:ensure_exists' => [
      'replacement' => 'entity_create:createIfNotExists',
      'message' => 'The plugin ID "entity_create:ensure_exists" is deprecated in drupal:10.3.1 and will be removed in drupal:12.0.0. Use "entity_create:createIfNotExists" instead. See https://www.drupal.org/node/3458273.',
    ],
    'simple_config_update' => [
      'replacement' => 'simpleConfigUpdate',
      'message' => 'The plugin ID "simple_config_update" is deprecated in drupal:10.3.1 and will be removed in drupal:12.0.0. Use "simpleConfigUpdate" instead. See https://www.drupal.org/node/3458273.',
    ],
  ];

  /**
   * Constructs a new \Drupal\Core\Config\Action\ConfigActionManager object.
   *
@@ -218,4 +234,28 @@ protected function getShorthandActionIdsForEntityType(string $entityType): array
    return $map;
  }

  /**
   * {@inheritdoc}
   */
  public function alterDefinitions(&$definitions): void {
    // Adds backwards compatibility for plugins that have been renamed.
    foreach (self::$deprecatedPluginIds as $legacy => $new_plugin_id) {
      $definitions[$legacy] = $definitions[$new_plugin_id['replacement']];
    }
    parent::alterDefinitions($definitions);
  }

  /**
   * {@inheritdoc}
   */
  public function createInstance($plugin_id, array $configuration = []) {
    $instance = parent::createInstance($plugin_id, $configuration);
    // Trigger deprecation notices for renamed plugins.
    if (array_key_exists($plugin_id, self::$deprecatedPluginIds)) {
      // phpcs:ignore Drupal.Semantics.FunctionTriggerError
      @trigger_error(self::$deprecatedPluginIds[$plugin_id]['message'], E_USER_DEPRECATED);
    }
    return $instance;
  }

}
+2 −2
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@ 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::ReturnEarlyIfExists]];
    $this->derivatives['ensure_exists']['admin_label'] = $this->t('Ensure entity exists');
    $this->derivatives['createIfNotExists'] = $base_plugin_definition + ['constructor_args' => ['exists' => Exists::ReturnEarlyIfExists]];
    $this->derivatives['createIfNotExists']['admin_label'] = $this->t('Create entity if it does not exist');

    $this->derivatives['create'] = $base_plugin_definition + ['constructor_args' => ['exists' => Exists::ErrorIfExists]];
    $this->derivatives['create']['admin_label'] = $this->t('Entity create');
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
 *   This API is experimental.
 */
#[ConfigAction(
  id: 'simple_config_update',
  id: 'simpleConfigUpdate',
  admin_label: new TranslatableMarkup('Simple configuration update'),
)]
final class SimpleConfigUpdate implements ConfigActionPluginInterface, ContainerFactoryPluginInterface {
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ config:
  actions:
    user.role.administrator:
      # If this role already exists, then this action has no effect. If it doesn't exist, we'll create it with the following values.
      ensure_exists:
      createIfNotExists:
        id: administrator
        label: Administrator
        weight: 3
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ config:
  actions:
    user.role.content_editor:
      # If this role already exists, then this action has no effect. If it doesn't exist, we'll create it with the following values.
      ensure_exists:
      createIfNotExists:
        id: content_editor
        label: 'Content editor'
        weight: 2
Loading