You are here

public static function ContentSyncMessage::resetClosed in Content Synchronization 8.2

Same name and namespace in other branches
  1. 8 src/Element/ContentSyncMessage.php \Drupal\content_sync\Element\ContentSyncMessage::resetClosed()
  2. 3.0.x src/Element/ContentSyncMessage.php \Drupal\content_sync\Element\ContentSyncMessage::resetClosed()

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\content_sync\Controller\ContentSyncElementController::close

1 call to ContentSyncMessage::resetClosed()
ContentSyncHelpManager::initHelp in src/ContentSyncHelpManager.php
Initialize help.

File

src/Element/ContentSyncMessage.php, line 227

Class

ContentSyncMessage
Provides a render element for message.

Namespace

Drupal\content_sync\Element

Code

public static function resetClosed($storage, $id) {
  $account = \Drupal::currentUser();
  $namespace = 'content_sync.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('content_sync', $account
        ->id(), $namespace) ?: [];
      unset($values[$id]);
      $user_data
        ->set('content_sync', $account
        ->id(), $namespace, $values);
  }
}