The Drupal keyValue module is a package library in Drupal that enables developers to store and retrieve arbitrary key-value data in a Drupal website.
Example 1: To store and retrieve a simple key-value pair in Drupal using the keyValue module, developers can use the following code:
// To save a value $key = 'my_key'; $value = 'my_value'; \Drupal::keyValue('my_store')->set($key, $value);
// To retrieve the value $value = \Drupal::keyValue('my_store')->get($key);
Example 2: To store and retrieve an array of key-value pairs in Drupal using the keyValue module, developers can use the following code:
// To save the array $values = [ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' ]; \Drupal::keyValue('my_store')->setMultiple($values);
// To retrieve the values $values = \Drupal::keyValue('my_store')->getMultiple(['key1', 'key2', 'key3']);
The Drupal keyValue module is a part of the Drupal core package and is therefore included in every Drupal installation by default.
PHP Drupal::keyValue - 30 examples found. These are the top rated real world PHP examples of Drupal::keyValue extracted from open source projects. You can rate examples to help us improve the quality of examples.