You are here

public function LockrKeyProvider::setKeyValue in Lockr 8.2

Same name and namespace in other branches
  1. 8.4 src/Plugin/KeyProvider/LockrKeyProvider.php \Drupal\lockr\Plugin\KeyProvider\LockrKeyProvider::setKeyValue()
  2. 8.3 src/Plugin/KeyProvider/LockrKeyProvider.php \Drupal\lockr\Plugin\KeyProvider\LockrKeyProvider::setKeyValue()
  3. 4.x src/Plugin/KeyProvider/LockrKeyProvider.php \Drupal\lockr\Plugin\KeyProvider\LockrKeyProvider::setKeyValue()

Sets the value of a key.

Parameters

\Drupal\key\KeyInterface $key: The key whose value will be set.

string $key_value: The key value.

Return value

bool TRUE if successful, FALSE if unsuccessful.

Overrides KeyProviderSettableValueInterface::setKeyValue

File

src/Plugin/KeyProvider/LockrKeyProvider.php, line 125
Contains Drupal\lockr\Plugin\KeyProvider\LockrKeyProvider.

Class

LockrKeyProvider
Adds a key provider that allows a key to be stored in Lockr.

Namespace

Drupal\lockr\Plugin\KeyProvider

Code

public function setKeyValue(KeyInterface $key, $key_value) {
  $name = $key
    ->id();
  $label = $key
    ->label();
  $encoded = $this
    ->getConfiguration()['encoded'] ?: NULL;
  $key_client = $this->clientFactory
    ->getKeyClient();
  $encoded = $key_client
    ->encrypted()
    ->set($name, $key_value, $label, $encoded);
  if ($encoded) {
    $this
      ->setConfiguration([
      'encoded' => $encoded,
    ]);
    return TRUE;
  }
  return FALSE;
}