Skip to content

Commit

Permalink
Issue #65: Add predefined list for content row layout field.
Browse files Browse the repository at this point in the history
  • Loading branch information
msnassar committed Sep 5, 2019
1 parent 7b5524a commit 98d5c71
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions oe_paragraphs.module
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -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)'),
];
}

0 comments on commit 98d5c71

Please sign in to comment.