From b57e33d5748d80d1a85624e834595203ba227f26 Mon Sep 17 00:00:00 2001 From: milkovsky Date: Thu, 11 Feb 2016 18:11:04 +0100 Subject: [PATCH 1/8] Change rules config to have multiple events. --- config/schema/rules.schema.yml | 36 +++++++++++++++---- src/Engine/RulesComponent.php | 11 +++--- src/Entity/ReactionRuleConfig.php | 18 ++++++---- src/Entity/ReactionRuleStorage.php | 18 ++++++---- .../GenericEventSubscriber.php | 2 +- src/Form/ReactionRuleAddForm.php | 3 +- src/Form/ReactionRuleEditForm.php | 17 +++++---- tests/src/Kernel/EventIntegrationTest.php | 2 +- 8 files changed, 73 insertions(+), 34 deletions(-) diff --git a/config/schema/rules.schema.yml b/config/schema/rules.schema.yml index 4e15b874..d225fb4a 100644 --- a/config/schema/rules.schema.yml +++ b/config/schema/rules.schema.yml @@ -49,9 +49,21 @@ rules.reaction.*: label: type: label label: 'Label' - event: - type: string - label: 'Event' + events: + type: sequence + label: 'Events' + sequence: + type: mapping + label: 'Event' + mapping: + event_name: + type: string + label: 'Name' + configuration: + type: sequence + label: 'Configuration' + sequence: + type: mapping module: type: string label: 'Module' @@ -194,9 +206,21 @@ rules_expression.rules_reaction_rule: uuid: type: string label: 'UUID' - event: - type: string - label: 'Event' + events: + type: sequence + label: 'Events' + sequence: + type: mapping + label: 'Event' + mapping: + event_name: + type: string + label: 'Name' + configuration: + type: sequence + label: 'Configuration' + sequence: + type: mapping conditions: type: rules_expression.[id] label: 'Conditions' diff --git a/src/Engine/RulesComponent.php b/src/Engine/RulesComponent.php index 2788ab59..e65377a4 100644 --- a/src/Engine/RulesComponent.php +++ b/src/Engine/RulesComponent.php @@ -125,11 +125,12 @@ public function getContextDefinitions() { */ public function addContextDefinitionsFrom(ConfigEntityInterface $rules_config) { if ($rules_config instanceof ReactionRuleConfig) { - $event_name = $rules_config->getEvent(); - // @todo Use setter injection for the service. - $event_definition = \Drupal::service('plugin.manager.rules_event')->getDefinition($event_name); - foreach ($event_definition['context'] as $context_name => $context_definition) { - $this->addContextDefinition($context_name, $context_definition); + foreach ($rules_config->getEvents() as $event) { + // @todo Use setter injection for the service. + $event_definition = \Drupal::service('plugin.manager.rules_event')->getDefinition($event['event_name']); + foreach ($event_definition['context'] as $context_name => $context_definition) { + $this->addContextDefinition($context_name, $context_definition); + } } } return $this; diff --git a/src/Entity/ReactionRuleConfig.php b/src/Entity/ReactionRuleConfig.php index d86c8a0a..c3d34423 100644 --- a/src/Entity/ReactionRuleConfig.php +++ b/src/Entity/ReactionRuleConfig.php @@ -36,7 +36,7 @@ * config_export = { * "id", * "label", - * "event", + * "events", * "module", * "description", * "tag", @@ -121,11 +121,15 @@ class ReactionRuleConfig extends ConfigEntityBase { protected $module = 'rules'; /** - * The event name this reaction rule is reacting on. + * The events this reaction rule is reacting on. * - * @var string + * Events array, key - numeric index, value - event array with next structure: + * - event_name: string with the event machine name. + * - configuration: an array containing the event configuration. + * + * @var array */ - protected $event; + protected $events; /** * Sets a Rules expression instance for this Reaction rule. @@ -208,10 +212,10 @@ public function getTag() { } /** - * Returns the event on which this rule will trigger. + * Returns the array of events on which this rule will trigger. */ - public function getEvent() { - return $this->event; + public function getEvents() { + return $this->events; } /** diff --git a/src/Entity/ReactionRuleStorage.php b/src/Entity/ReactionRuleStorage.php index 1de2c0cf..7a4f88b9 100644 --- a/src/Entity/ReactionRuleStorage.php +++ b/src/Entity/ReactionRuleStorage.php @@ -83,9 +83,10 @@ public static function createInstance(ContainerInterface $container, EntityTypeI protected function getRegisteredEvents() { $events = []; foreach ($this->loadMultiple() as $rules_config) { - $event = $rules_config->getEvent(); - if ($event && !isset($events[$event])) { - $events[$event] = $event; + foreach ($rules_config->getEvents() as $event) { + if ($event && !isset($events[$event['event_name']])) { + $events[$event['event_name']] = $event['event_name']; + } } } return $events; @@ -106,10 +107,13 @@ public function save(EntityInterface $entity) { // After the reaction rule is saved, we need to rebuild the container, // otherwise the reaction rule will not fire. However, we can do an - // optimization: if the event was already registered before, we do not have - // to rebuild the container. - if (empty($events_before[$entity->getEvent()])) { - $this->drupalKernel->rebuildContainer(); + // optimization: if every event was already registered before, we do not + // have to rebuild the container. + foreach ($entity->getEvents() as $event) { + if (empty($events_before[$event['event_name']])) { + $this->drupalKernel->rebuildContainer(); + break; + } } return $return; diff --git a/src/EventSubscriber/GenericEventSubscriber.php b/src/EventSubscriber/GenericEventSubscriber.php index 9f591b9c..f4a03c8d 100644 --- a/src/EventSubscriber/GenericEventSubscriber.php +++ b/src/EventSubscriber/GenericEventSubscriber.php @@ -125,7 +125,7 @@ public function onRulesEvent(Event $event, $event_name) { // another rule. foreach ($triggered_events as $triggered_event) { // @todo Only load active reaction rules here. - $configs = $storage->loadByProperties(['event' => $triggered_event]); + $configs = $storage->loadByProperties(['events.*.event_name' => $triggered_event]); // Loop over all rules and execute them. foreach ($configs as $config) { diff --git a/src/Form/ReactionRuleAddForm.php b/src/Form/ReactionRuleAddForm.php index 2fb521bd..ab26b69b 100644 --- a/src/Form/ReactionRuleAddForm.php +++ b/src/Form/ReactionRuleAddForm.php @@ -65,7 +65,8 @@ public function form(array $form, FormStateInterface $form_state) { } } - $form['event'] = [ + $form['events']['#tree'] = TRUE; + $form['events'][]['event_name'] = [ '#type' => 'select', '#title' => $this->t('React on event'), '#options' => $options, diff --git a/src/Form/ReactionRuleEditForm.php b/src/Form/ReactionRuleEditForm.php index 8e47d496..9e8b936c 100644 --- a/src/Form/ReactionRuleEditForm.php +++ b/src/Form/ReactionRuleEditForm.php @@ -48,12 +48,17 @@ public static function create(ContainerInterface $container) { public function form(array $form, FormStateInterface $form_state) { $this->addLockInformation($form); - $event_name = $this->entity->getEvent(); - $event_definition = $this->eventManager->getDefinition($event_name); - $form['event']['#markup'] = $this->t('Event: @label (@name)', [ - '@label' => $event_definition['label'], - '@name' => $event_name, - ]); + foreach ($this->entity->getEvents() as $key => $event) { + $event_definition = $this->eventManager->getDefinition($event['event_name']); + $form['event'][$key] = [ + '#type' => 'item', + '#title' => $this->t('Events') . ':', + '#markup' => $this->t('@label (@name)', [ + '@label' => $event_definition['label'], + '@name' => $event['event_name'], + ]), + ]; + } $form_handler = $this->entity->getExpression()->getFormHandler(); $form = $form_handler->form($form, $form_state); return parent::form($form, $form_state); diff --git a/tests/src/Kernel/EventIntegrationTest.php b/tests/src/Kernel/EventIntegrationTest.php index a13f551c..c21a2161 100644 --- a/tests/src/Kernel/EventIntegrationTest.php +++ b/tests/src/Kernel/EventIntegrationTest.php @@ -161,7 +161,7 @@ public function testInitEvent() { $config_entity = $this->storage->create([ 'id' => 'test_rule', 'expression_id' => 'rules_rule', - 'event' => KernelEvents::REQUEST, + 'events' => [['event_name' => KernelEvents::REQUEST]], 'configuration' => $rule->getConfiguration(), ]); $config_entity->save(); From 7d0d7e2bc2ab0657f1538ad50916edfc1e404f69 Mon Sep 17 00:00:00 2001 From: milkovsky Date: Thu, 11 Feb 2016 18:26:01 +0100 Subject: [PATCH 2/8] Tests for multiple events. --- tests/src/Kernel/EventIntegrationTest.php | 42 ++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/tests/src/Kernel/EventIntegrationTest.php b/tests/src/Kernel/EventIntegrationTest.php index c21a2161..50cfc73c 100644 --- a/tests/src/Kernel/EventIntegrationTest.php +++ b/tests/src/Kernel/EventIntegrationTest.php @@ -54,7 +54,7 @@ public function testUserLoginEvent() { $config_entity = $this->storage->create([ 'id' => 'test_rule', 'expression_id' => 'rules_rule', - 'event' => 'rules_user_login', + 'events' => [['event_name' => 'rules_user_login']], 'configuration' => $rule->getConfiguration(), ]); $config_entity->save(); @@ -81,7 +81,7 @@ public function testUserLogoutEvent() { $config_entity = $this->storage->create([ 'id' => 'test_rule', 'expression_id' => 'rules_rule', - 'event' => 'rules_user_logout', + 'events' => [['event_name' => 'rules_user_logout']], 'configuration' => $rule->getConfiguration(), ]); $config_entity->save(); @@ -108,7 +108,7 @@ public function testCronEvent() { $config_entity = $this->storage->create([ 'id' => 'test_rule', 'expression_id' => 'rules_rule', - 'event' => 'rules_system_cron', + 'events' => [['event_name' => 'rules_system_cron']], 'configuration' => $rule->getConfiguration(), ]); $config_entity->save(); @@ -134,7 +134,7 @@ public function testSystemLoggerEvent() { $config_entity = $this->storage->create([ 'id' => 'test_rule', 'expression_id' => 'rules_rule', - 'event' => 'rules_system_logger_event', + 'events' => [['event_name' => 'rules_system_logger_event']], 'configuration' => $rule->getConfiguration(), ]); $config_entity->save(); @@ -185,4 +185,38 @@ public function testInitEvent() { $this->assertRulesLogEntryExists('action called'); } + /** + * Test that rules config supports multiple events. + */ + public function testMultipleEvents() { + $rule = $this->expressionManager->createRule(); + $rule->addCondition('rules_test_true'); + $rule->addAction('rules_test_log'); + + $config_entity = $this->storage->create([ + 'id' => 'test_rule', + 'expression_id' => 'rules_rule', + 'events' => [ + ['event_name' => 'rules_user_login'], + ['event_name' => 'rules_user_logout'], + ], + 'configuration' => $rule->getConfiguration(), + ]); + $config_entity->save(); + + // The logger instance has changed, refresh it. + $this->logger = $this->container->get('logger.channel.rules'); + + $account = User::create(['name' => 'test_user']); + // Invoke the hook manually which should trigger the rules_user_login event. + rules_user_login($account); + // Invoke the hook manually which should trigger the rules_user_logout + // event. + rules_user_logout($account); + + // Test that the action in the rule logged something. + $this->assertRulesLogEntryExists('action called'); + $this->assertRulesLogEntryExists('action called', 1); + } + } From 87dca7d0d323776b23bb823a49dfca3f1045c118 Mon Sep 17 00:00:00 2001 From: milkovsky Date: Mon, 15 Feb 2016 11:40:56 +0100 Subject: [PATCH 3/8] PR fixes. --- config/schema/rules.schema.yml | 32 ----------------------- src/Engine/RulesComponent.php | 4 +-- src/Entity/ReactionRuleConfig.php | 25 ++++++++++++++++-- src/Entity/ReactionRuleStorage.php | 10 +++---- src/Form/ReactionRuleEditForm.php | 6 ++--- tests/src/Kernel/EventIntegrationTest.php | 10 +++---- 6 files changed, 38 insertions(+), 49 deletions(-) diff --git a/config/schema/rules.schema.yml b/config/schema/rules.schema.yml index d225fb4a..75cbcb76 100644 --- a/config/schema/rules.schema.yml +++ b/config/schema/rules.schema.yml @@ -196,38 +196,6 @@ rules_expression.rules_rule: type: rules_expression.[id] label: 'Actions' -rules_expression.rules_reaction_rule: - type: rules_expression - label: "Reaction Rule" - mapping: - id: - type: string - label: 'Plugin ID' - uuid: - type: string - label: 'UUID' - events: - type: sequence - label: 'Events' - sequence: - type: mapping - label: 'Event' - mapping: - event_name: - type: string - label: 'Name' - configuration: - type: sequence - label: 'Configuration' - sequence: - type: mapping - conditions: - type: rules_expression.[id] - label: 'Conditions' - actions: - type: rules_expression.[id] - label: 'Actions' - rules.context.definition: type: mapping label: 'Context definition' diff --git a/src/Engine/RulesComponent.php b/src/Engine/RulesComponent.php index e65377a4..0d720f2a 100644 --- a/src/Engine/RulesComponent.php +++ b/src/Engine/RulesComponent.php @@ -125,9 +125,9 @@ public function getContextDefinitions() { */ public function addContextDefinitionsFrom(ConfigEntityInterface $rules_config) { if ($rules_config instanceof ReactionRuleConfig) { - foreach ($rules_config->getEvents() as $event) { + foreach ($rules_config->getEventNames() as $event_name) { // @todo Use setter injection for the service. - $event_definition = \Drupal::service('plugin.manager.rules_event')->getDefinition($event['event_name']); + $event_definition = \Drupal::service('plugin.manager.rules_event')->getDefinition($event_name); foreach ($event_definition['context'] as $context_name => $context_definition) { $this->addContextDefinition($context_name, $context_definition); } diff --git a/src/Entity/ReactionRuleConfig.php b/src/Entity/ReactionRuleConfig.php index c3d34423..fce61480 100644 --- a/src/Entity/ReactionRuleConfig.php +++ b/src/Entity/ReactionRuleConfig.php @@ -123,7 +123,8 @@ class ReactionRuleConfig extends ConfigEntityBase { /** * The events this reaction rule is reacting on. * - * Events array, key - numeric index, value - event array with next structure: + * Events array. The array is numerically indexed and contains arrays with the + * following structure: * - event_name: string with the event machine name. * - configuration: an array containing the event configuration. * @@ -212,12 +213,32 @@ public function getTag() { } /** - * Returns the array of events on which this rule will trigger. + * Gets configuration of all events the rule is reacting on. + * + * @return array + * The events array. The array is numerically indexed and contains arrays + * with the following structure: + * - event_name: string with the event machine name. + * - configuration: an array containing the event configuration. */ public function getEvents() { return $this->events; } + /** + * Gets fully qualified names of all events the rule is reacting on. + * + * @return string[] + * The array of fully qualified event names of the rule. + */ + public function getEventNames() { + $names = []; + foreach ($this->events as $event) { + $names[] = $event['event_name']; + } + return $names; + } + /** * {@inheritdoc} */ diff --git a/src/Entity/ReactionRuleStorage.php b/src/Entity/ReactionRuleStorage.php index 7a4f88b9..50dacac8 100644 --- a/src/Entity/ReactionRuleStorage.php +++ b/src/Entity/ReactionRuleStorage.php @@ -83,9 +83,9 @@ public static function createInstance(ContainerInterface $container, EntityTypeI protected function getRegisteredEvents() { $events = []; foreach ($this->loadMultiple() as $rules_config) { - foreach ($rules_config->getEvents() as $event) { - if ($event && !isset($events[$event['event_name']])) { - $events[$event['event_name']] = $event['event_name']; + foreach ($rules_config->getEventNames() as $event_name) { + if (!isset($events[$event_name])) { + $events[$event_name] = $event_name; } } } @@ -109,8 +109,8 @@ public function save(EntityInterface $entity) { // otherwise the reaction rule will not fire. However, we can do an // optimization: if every event was already registered before, we do not // have to rebuild the container. - foreach ($entity->getEvents() as $event) { - if (empty($events_before[$event['event_name']])) { + foreach ($entity->getEventNames() as $event_name) { + if (empty($events_before[$event_name])) { $this->drupalKernel->rebuildContainer(); break; } diff --git a/src/Form/ReactionRuleEditForm.php b/src/Form/ReactionRuleEditForm.php index 9e8b936c..311be4ef 100644 --- a/src/Form/ReactionRuleEditForm.php +++ b/src/Form/ReactionRuleEditForm.php @@ -48,14 +48,14 @@ public static function create(ContainerInterface $container) { public function form(array $form, FormStateInterface $form_state) { $this->addLockInformation($form); - foreach ($this->entity->getEvents() as $key => $event) { - $event_definition = $this->eventManager->getDefinition($event['event_name']); + foreach ($this->entity->getEventNames() as $key => $event_name) { + $event_definition = $this->eventManager->getDefinition($event_name); $form['event'][$key] = [ '#type' => 'item', '#title' => $this->t('Events') . ':', '#markup' => $this->t('@label (@name)', [ '@label' => $event_definition['label'], - '@name' => $event['event_name'], + '@name' => $event_name, ]), ]; } diff --git a/tests/src/Kernel/EventIntegrationTest.php b/tests/src/Kernel/EventIntegrationTest.php index 50cfc73c..686be03d 100644 --- a/tests/src/Kernel/EventIntegrationTest.php +++ b/tests/src/Kernel/EventIntegrationTest.php @@ -196,12 +196,12 @@ public function testMultipleEvents() { $config_entity = $this->storage->create([ 'id' => 'test_rule', 'expression_id' => 'rules_rule', - 'events' => [ - ['event_name' => 'rules_user_login'], - ['event_name' => 'rules_user_logout'], - ], - 'configuration' => $rule->getConfiguration(), ]); + $config_entity->set('events', [ + ['event_name' => 'rules_user_login'], + ['event_name' => 'rules_user_logout'], + ]); + $config_entity->set('configuration', $rule->getConfiguration()); $config_entity->save(); // The logger instance has changed, refresh it. From cb7f7623505c6bc67c6f21b17404f8ce4c07f648 Mon Sep 17 00:00:00 2001 From: milkovsky Date: Tue, 16 Feb 2016 10:04:38 +0100 Subject: [PATCH 4/8] Code formatting. --- src/Entity/ReactionRuleConfig.php | 8 ++++---- src/Form/ReactionRuleEditForm.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Entity/ReactionRuleConfig.php b/src/Entity/ReactionRuleConfig.php index fce61480..7b8c1ddc 100644 --- a/src/Entity/ReactionRuleConfig.php +++ b/src/Entity/ReactionRuleConfig.php @@ -125,8 +125,8 @@ class ReactionRuleConfig extends ConfigEntityBase { * * Events array. The array is numerically indexed and contains arrays with the * following structure: - * - event_name: string with the event machine name. - * - configuration: an array containing the event configuration. + * - event_name: String with the event machine name. + * - configuration: An array containing the event configuration. * * @var array */ @@ -218,8 +218,8 @@ public function getTag() { * @return array * The events array. The array is numerically indexed and contains arrays * with the following structure: - * - event_name: string with the event machine name. - * - configuration: an array containing the event configuration. + * - event_name: String with the event machine name. + * - configuration: An array containing the event configuration. */ public function getEvents() { return $this->events; diff --git a/src/Form/ReactionRuleEditForm.php b/src/Form/ReactionRuleEditForm.php index 311be4ef..b41df04e 100644 --- a/src/Form/ReactionRuleEditForm.php +++ b/src/Form/ReactionRuleEditForm.php @@ -52,7 +52,7 @@ public function form(array $form, FormStateInterface $form_state) { $event_definition = $this->eventManager->getDefinition($event_name); $form['event'][$key] = [ '#type' => 'item', - '#title' => $this->t('Events') . ':', + '#title' => $this->t('Events:'), '#markup' => $this->t('@label (@name)', [ '@label' => $event_definition['label'], '@name' => $event_name, From 944aa09ca1c2b37d8b8fe93343c2cac983a82c33 Mon Sep 17 00:00:00 2001 From: milkovsky Date: Thu, 18 Feb 2016 16:46:11 +0100 Subject: [PATCH 5/8] After merge fix. --- src/Entity/ReactionRuleConfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entity/ReactionRuleConfig.php b/src/Entity/ReactionRuleConfig.php index 565c6c13..830169d2 100644 --- a/src/Entity/ReactionRuleConfig.php +++ b/src/Entity/ReactionRuleConfig.php @@ -174,7 +174,7 @@ public function getExpression() { */ public function getComponent() { $component = RulesComponent::create($this->getExpression()); - $component->addContextDefinitionsForEvents([$this->getEvent()]); + $component->addContextDefinitionsForEvents($this->getEventNames()); return $component; } From 9ead81eecc9ad76ad5dfd909da195780f52822d1 Mon Sep 17 00:00:00 2001 From: milkovsky Date: Thu, 18 Feb 2016 16:53:14 +0100 Subject: [PATCH 6/8] Initialize events []. --- src/Entity/ReactionRuleConfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entity/ReactionRuleConfig.php b/src/Entity/ReactionRuleConfig.php index 830169d2..4b7395c3 100644 --- a/src/Entity/ReactionRuleConfig.php +++ b/src/Entity/ReactionRuleConfig.php @@ -130,7 +130,7 @@ class ReactionRuleConfig extends ConfigEntityBase { * * @var array */ - protected $events; + protected $events = []; /** * Sets a Rules expression instance for this Reaction rule. From d179fcf23453762d13a0aecb34ef5fa43a099d01 Mon Sep 17 00:00:00 2001 From: milkovsky Date: Fri, 26 Feb 2016 12:02:17 +0100 Subject: [PATCH 7/8] Fixed expression set in rules handler test. --- .../src/Kernel/ConfigurableEventHandlerTest.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/src/Kernel/ConfigurableEventHandlerTest.php b/tests/src/Kernel/ConfigurableEventHandlerTest.php index 28c2bfa3..57eb1534 100644 --- a/tests/src/Kernel/ConfigurableEventHandlerTest.php +++ b/tests/src/Kernel/ConfigurableEventHandlerTest.php @@ -93,9 +93,11 @@ public function testConfigurableEventHandler() { ); $config_entity1 = $this->storage->create([ 'id' => 'test_rule1', - 'expression_id' => 'rules_rule', - 'event' => 'rules_entity_presave:node--page', - ])->setExpression($rule1); + ]); + $config_entity1->set('events', [ + ['event_name' => 'rules_entity_presave:node--page'], + ]); + $config_entity1->set('expression', $rule1->getConfiguration()); $config_entity1->save(); // Create rule2 with the 'rules_entity_presave:node' event. @@ -106,9 +108,11 @@ public function testConfigurableEventHandler() { ); $config_entity2 = $this->storage->create([ 'id' => 'test_rule2', - 'expression_id' => 'rules_rule', - 'event' => 'rules_entity_presave:node', - ])->setExpression($rule2); + ]); + $config_entity2->set('events', [ + ['event_name' => 'rules_entity_presave:node'], + ]); + $config_entity2->set('expression', $rule2->getConfiguration()); $config_entity2->save(); // The logger instance has changed, refresh it. From 5eea48cc3233b38018f2b5d3007aff3d5fc2f3cd Mon Sep 17 00:00:00 2001 From: milkovsky Date: Fri, 26 Feb 2016 12:07:49 +0100 Subject: [PATCH 8/8] Fix testMultipleEvents test. --- tests/src/Kernel/EventIntegrationTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/src/Kernel/EventIntegrationTest.php b/tests/src/Kernel/EventIntegrationTest.php index f70f91c4..7bc7e5d3 100644 --- a/tests/src/Kernel/EventIntegrationTest.php +++ b/tests/src/Kernel/EventIntegrationTest.php @@ -190,13 +190,12 @@ public function testMultipleEvents() { $config_entity = $this->storage->create([ 'id' => 'test_rule', - 'expression_id' => 'rules_rule', ]); $config_entity->set('events', [ ['event_name' => 'rules_user_login'], ['event_name' => 'rules_user_logout'], ]); - $config_entity->set('configuration', $rule->getConfiguration()); + $config_entity->set('expression', $rule->getConfiguration()); $config_entity->save(); // The logger instance has changed, refresh it.