From 98d5c718234726ebc1bda10a1f15265f5db5aab7 Mon Sep 17 00:00:00 2001 From: Mohammed Nassar Date: Fri, 9 Aug 2019 09:58:15 +0000 Subject: [PATCH] Issue #65: Add predefined list for content row layout field. --- ....paragraph.field_oe_content_row_layout.yml | 2 +- oe_paragraphs.module | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/config/install/field.storage.paragraph.field_oe_content_row_layout.yml b/config/install/field.storage.paragraph.field_oe_content_row_layout.yml index 51c20ad6..0384c639 100644 --- a/config/install/field.storage.paragraph.field_oe_content_row_layout.yml +++ b/config/install/field.storage.paragraph.field_oe_content_row_layout.yml @@ -10,7 +10,7 @@ entity_type: paragraph type: list_string settings: allowed_values: { } - allowed_values_function: '' + allowed_values_function: '_oe_paragraphs_allowed_values_content_row_column_layout' module: options locked: false cardinality: 1 diff --git a/oe_paragraphs.module b/oe_paragraphs.module index 0f5a17ba..33e10d73 100644 --- a/oe_paragraphs.module +++ b/oe_paragraphs.module @@ -8,7 +8,9 @@ declare(strict_types = 1); use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\Field\FieldStorageDefinitionInterface; /** * Implements hook_entity_base_field_info(). @@ -31,3 +33,27 @@ function oe_paragraphs_entity_base_field_info(EntityTypeInterface $entity_type): return $fields; } + +/** + * Set dynamic allowed values for the "Content row: Column layout". + * + * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $definition + * The field definition. + * @param \Drupal\Core\Entity\FieldableEntityInterface|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 _oe_paragraphs_allowed_values_content_row_column_layout(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, $cacheable): array { + return [ + '2' => t('2 columns (equal width | 6-6)'), + '8-4' => t('2 columns (non-equal width | 8-4)'), + '3' => t('3 columns (equal width | 4-4-4)'), + '3-6-3' => t('3 columns (non-equal width | 3-6-3)'), + ]; +}