You are here

public static function YamlFormMessage::setClosed in YAML Form 8

Set 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::setClosed()
YamlFormElementController::close in src/Controller/YamlFormElementController.php
Returns response for message close using user or state storage.

File

src/Element/YamlFormMessage.php, line 196

Class

YamlFormMessage
Provides a render element for message.

Namespace

Drupal\yamlform\Element

Code

public static function setClosed($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, []);
      $values[$id] = TRUE;
      $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) ?: [];
      $values[$id] = TRUE;
      $user_data
        ->set('yamlform', $account
        ->id(), $namespace, $values);
  }
}