webex_client-1.0.5/src/Entity/WebexEncodeTrait.php
src/Entity/WebexEncodeTrait.php
<?php
namespace Drupal\webex_client\Entity;
use Drupal\Component\Serialization\Json;
/**
* Provides methods for encoding and decoding keys.
*/
trait WebexEncodeTrait {
/**
* Encodes a key and stores it in the state.
*
* @param string $name
* The name under which the key is stored.
* @param string $key
* The key to be encoded and stored.
*/
protected function encodeKey(string $name, string $key) {
\Drupal::state()->set("{$this->id()}.$name", Json::encode([$key]));
}
/**
* Decodes a key from the state.
*
* @param string $name
* The name under which the key is stored.
*
* @return string
* The decoded key, or an empty string if not found.
*/
protected function decodeKey(string $name) {
$key = \Drupal::state()->get("{$this->id()}.$name");
$decoded = $key ? Json::decode($key) : [];
return $decoded[0] ?? "";
}
}
