You are here

class CaptchaCachedSettingsSubscriber in CAPTCHA 8

A subscriber clearing the cached definitions when saving captcha settings.

Hierarchy

Expanded class hierarchy of CaptchaCachedSettingsSubscriber

1 string reference to 'CaptchaCachedSettingsSubscriber'
captcha.services.yml in ./captcha.services.yml
captcha.services.yml
1 service uses CaptchaCachedSettingsSubscriber
captcha.config_subscriber in ./captcha.services.yml
Drupal\captcha\EventSubscriber\CaptchaCachedSettingsSubscriber

File

src/EventSubscriber/CaptchaCachedSettingsSubscriber.php, line 13

Namespace

Drupal\captcha\EventSubscriber
View source
class CaptchaCachedSettingsSubscriber implements EventSubscriberInterface {

  /**
   * The Element info.
   *
   * @var \Drupal\Core\Render\ElementInfoManagerInterface
   */
  protected $elementInfo;

  /**
   * CaptchaCachedSettingsSubscriber constructor.
   *
   * @param \Drupal\Core\Render\ElementInfoManagerInterface $elementInfo
   *   Constructor.
   */
  public function __construct(ElementInfoManagerInterface $elementInfo) {
    $this->elementInfo = $elementInfo;
  }

  /**
   * Clearing the cached definitions whenever the settings are modified.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The Event to process.
   */
  public function onSave(ConfigCrudEvent $event) {

    // Changing the Captcha settings means that any page might result in other
    // settings for captcha so the cached definitions need to be cleared.
    if ($event
      ->getConfig()
      ->getName() === 'captcha.settings') {
      $this->elementInfo
        ->clearCachedDefinitions();
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[ConfigEvents::SAVE][] = [
      'onSave',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CaptchaCachedSettingsSubscriber::$elementInfo protected property The Element info.
CaptchaCachedSettingsSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
CaptchaCachedSettingsSubscriber::onSave public function Clearing the cached definitions whenever the settings are modified.
CaptchaCachedSettingsSubscriber::__construct public function CaptchaCachedSettingsSubscriber constructor.