You are here

public static function YamlFormMessage::resetClosed in YAML Form 8

Reset message closed via User Data or State API.

Parameters

string $storage: The storage mechanism save message closed.

string $id: The ID of the message.

See also

\Drupal\yamlform\Controller\YamlFormElementController::close

1 call to YamlFormMessage::resetClosed()
YamlFormHelpManager::initHelp in src/YamlFormHelpManager.php
Initialize help.

File

src/Element/YamlFormMessage.php, line 227

Class

YamlFormMessage
Provides a render element for message.

Namespace

Drupal\yamlform\Element

Code

public static function resetClosed($storage, $id) {
  $account = \Drupal::currentUser();
  $namespace = 'yamlform.element.message';
  switch ($storage) {
    case self::STORAGE_STATE:

      /** @var \Drupal\Core\State\StateInterface $state */
      $state = \Drupal::service('state');
      $values = $state
        ->get($namespace, []);
      unset($values[$id]);
      $state
        ->set($namespace, $values);
      break;
    case self::STORAGE_USER:

      /** @var \Drupal\user\UserDataInterface $user_data */
      $user_data = \Drupal::service('user.data');
      $values = $user_data
        ->get('yamlform', $account
        ->id(), $namespace) ?: [];
      unset($values[$id]);
      $user_data
        ->set('yamlform', $account
        ->id(), $namespace, $values);
  }
}