123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- use Drupal\Core\Entity\FieldableEntityInterface;
- use Drupal\Core\Field\FieldStorageDefinitionInterface;
- function hook_options_list_alter(array &$options, array $context) {
-
- if ($context['fieldDefinition']->id() == 'field_option') {
-
- $options['_none'] = t('== Empty ==');
- }
- }
- function callback_allowed_values_function(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &$cacheable = TRUE) {
- if (isset($entity) && ($entity->bundle() == 'not_a_programmer')) {
- $values = [
- 1 => 'One',
- 2 => 'Two',
- ];
- }
- else {
- $values = [
- 'Group 1' => [
- 0 => 'Zero',
- 1 => 'One',
- ],
- 'Group 2' => [
- 2 => 'Two',
- ],
- ];
- }
- return $values;
- }
|