diff --git a/core/lib/Drupal/Core/KeyValueStore/State.php b/core/lib/Drupal/Core/KeyValueStore/State.php index f255e51..36a7973 100644 --- a/core/lib/Drupal/Core/KeyValueStore/State.php +++ b/core/lib/Drupal/Core/KeyValueStore/State.php @@ -56,6 +56,8 @@ public function getMultiple(array $keys) { if ($load) { $loaded_values = $this->keyValueStore->getMultiple($load); foreach ($load as $key) { + // If we find a value, even one that is NULL, add it to the cache and + // return it. if (isset($loaded_values[$key]) || array_key_exists($key, $loaded_values)) { $values[$key] = $loaded_values[$key]; $this->cache[$key] = $loaded_values[$key]; @@ -91,9 +93,9 @@ public function deleteMultiple(array $keys) { /** * {@inheritdoc} */ - public function get($key) { + public function get($key, $default = NULL) { $values = $this->getMultiple(array($key)); - return isset($values[$key]) ? $values[$key] : NULL; + return isset($values[$key]) ? $values[$key] : $default; } /** @@ -103,7 +105,7 @@ public function setMultiple(array $data) { foreach ($data as $key => $value) { $this->cache[$key] = $value; } - $this->setMultiple($data); + $this->keyValueStore->setMultiple($data); } /** diff --git a/core/lib/Drupal/Core/KeyValueStore/StateInterface.php b/core/lib/Drupal/Core/KeyValueStore/StateInterface.php index 9e248d8..7584abc 100644 --- a/core/lib/Drupal/Core/KeyValueStore/StateInterface.php +++ b/core/lib/Drupal/Core/KeyValueStore/StateInterface.php @@ -17,11 +17,13 @@ * * @param string $key * The key of the data to retrieve. + * @param mixed $default + * The default value to use if the key is not found. * * @return mixed * The stored value, or NULL if no value exists. */ - public function get($key); + public function get($key, $default = NULL); /** * Returns the stored key/value pairs for a given set of keys.