class RecipeIsApplyingTestSubscriber

Records the isApplying flag when recipe-provided configuration is saved.

Hierarchy

  • class \Drupal\recipe_is_applying_test\EventSubscriber\RecipeIsApplyingTestSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RecipeIsApplyingTestSubscriber

1 string reference to 'RecipeIsApplyingTestSubscriber'
recipe_is_applying_test.services.yml in core/modules/system/tests/modules/recipe_is_applying_test/recipe_is_applying_test.services.yml
core/modules/system/tests/modules/recipe_is_applying_test/recipe_is_applying_test.services.yml
1 service uses RecipeIsApplyingTestSubscriber
recipe_is_applying_test.event_subscriber in core/modules/system/tests/modules/recipe_is_applying_test/recipe_is_applying_test.services.yml
Drupal\recipe_is_applying_test\EventSubscriber\RecipeIsApplyingTestSubscriber

File

core/modules/system/tests/modules/recipe_is_applying_test/src/EventSubscriber/RecipeIsApplyingTestSubscriber.php, line 17

Namespace

Drupal\recipe_is_applying_test\EventSubscriber
View source
class RecipeIsApplyingTestSubscriber implements EventSubscriberInterface {
  public function __construct(private KeyValueFactoryInterface $keyValueFactory) {
  }
  
  /**
   * Records the isApplying flag when the recipe's configuration is saved.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The configuration event.
   */
  public function onConfigSave(ConfigCrudEvent $event) : void {
    if ($event->getConfig()
      ->getName() === 'recipe_is_applying_test.settings') {
      $this->keyValueFactory
        ->get('recipe_is_applying_test')
        ->set('config_save', RecipeRunner::isApplying());
    }
  }
  
  /**
   * Records the isApplying flag when the recipe's applied event is triggered.
   *
   * @param \Drupal\Core\Recipe\RecipeAppliedEvent $event
   *   The recipe applied event.
   */
  public function onRecipeApplied(RecipeAppliedEvent $event) : void {
    if ($event->recipe->name === 'Recipe isApplying test') {
      $this->keyValueFactory
        ->get('recipe_is_applying_test')
        ->set('recipe_applied_event', RecipeRunner::isApplying());
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() : array {
    return [
      ConfigEvents::SAVE => 'onConfigSave',
      RecipeAppliedEvent::class => 'onRecipeApplied',
    ];
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.