diff --git a/config/install/field.storage.node.field_uw_type_of_media.yml b/config/install/field.storage.node.field_uw_type_of_media.yml index 3671c93b57d9cf62e460a8afdd274ce3a490cc75..196be0afd982f30458ae984285a2a4afa50a0fd9 100644 --- a/config/install/field.storage.node.field_uw_type_of_media.yml +++ b/config/install/field.storage.node.field_uw_type_of_media.yml @@ -9,11 +9,8 @@ field_name: field_uw_type_of_media entity_type: node type: list_string settings: - allowed_values: - - - value: image - label: Image - allowed_values_function: '' + allowed_values: { } + allowed_values_function: '_uw_cfg_common_allowed_media_types' module: options locked: false cardinality: 1 diff --git a/uw_cfg_common.module b/uw_cfg_common.module index 0cd525a8c1e31bb44d8195f1c26d3fcabb2059ee..0772ca8d1d82e8a931adbf711d1516c879d57de0 100644 --- a/uw_cfg_common.module +++ b/uw_cfg_common.module @@ -7,6 +7,7 @@ use Drupal\Component\Utility\Html; use Drupal\Core\Access\AccessResult; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; @@ -14,6 +15,7 @@ use Drupal\Core\Link; use Drupal\Core\Render\Element; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\fillpdf\Controller\HandlePdfController; use Drupal\fillpdf\Form\FillPdfFormForm; use Drupal\media_library\MediaLibraryState; @@ -1432,3 +1434,29 @@ function uw_cfg_common_preprocess_html(&$variables): void { $variables['page']['#attached']['html_head'][] = [$noindex, 'noindex']; } } + +/** + * Set dynamic allowed values for the type of media field. + * + * @param \Drupal\field\Entity\FieldStorageConfig $definition + * The field definition. + * @param \Drupal\Core\Entity\ContentEntityInterface|null $entity + * The entity being created if applicable. + * @param bool $cacheable + * Boolean indicating if the results are cacheable. + * + * @return array + * An array of possible key and value options. + * + * @see options_allowed_values() + */ +function _uw_cfg_common_allowed_media_types( + FieldStorageConfig $definition, + ContentEntityInterface $entity = NULL, $cacheable +) { + + return [ + 'banner' => 'Banner images', + 'image' => 'Image', + ]; +}