dbb474b493731df84400088d1e5f495e91c9e967
[yaffs-website] / options_test.module
1 <?php
2
3 /**
4  * @file
5  * Helper module for the List module tests.
6  */
7
8 use Drupal\Core\Entity\FieldableEntityInterface;
9 use Drupal\Core\Field\FieldStorageDefinitionInterface;
10
11 /**
12  * Implements callback_allowed_values_function().
13  *
14  * @see options_allowed_values()
15  */
16 function options_test_allowed_values_callback(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL) {
17   $values = [
18     'Group 1' => [
19       0 => 'Zero',
20     ],
21     1 => 'One',
22     'Group 2' => [
23       2 => 'Some <script>dangerous</script> & unescaped <strong>markup</strong>',
24     ],
25     'More <script>dangerous</script> markup' => [
26       3 => 'Three',
27     ],
28   ];
29
30   return $values;
31 }
32
33 /**
34  * Implements callback_allowed_values_function().
35  *
36  * @todo This function violates the recommendation in options_allowed_values()
37  *   to return a list of all possible values in any context when $items is
38  *   NULL. Since this is not yet used for testing Views integration, that is
39  *   alright for now. Fix this in https://www.drupal.org/node/2012130.
40  *
41  * @see options_allowed_values()
42  */
43 function options_test_dynamic_values_callback(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &$cacheable = NULL) {
44   $values = [];
45   if (isset($entity)) {
46     $cacheable = FALSE;
47     $values = [
48       $entity->label(),
49       $entity->url(),
50       $entity->uuid(),
51       $entity->bundle(),
52     ];
53   }
54   // We need the values of the entity as keys.
55   return array_combine($values, $values);
56 }