protected function FieldDefinitionProvider::getStringDefinition in CiviCRM Entity 8.3
Gets a string field definition.
If the field uses pseudo constants, it is turned into a list_integer and allowed values are set based on values that can be returned from the CiviCRM API, as they are references.
Parameters
array $civicrm_field: The CiviCRM field definition.
Return value
\Drupal\Core\Field\BaseFieldDefinition The base field definition.
1 call to FieldDefinitionProvider::getStringDefinition()
- FieldDefinitionProvider::getBaseFieldDefinition in src/
Entity/ FieldDefinitionProvider.php - Gets an entity base field definition from a CiviCRM field definition.
File
- src/
Entity/ FieldDefinitionProvider.php, line 207
Class
Namespace
Drupal\civicrm_entity\EntityCode
protected function getStringDefinition(array $civicrm_field) {
if (!empty($civicrm_field['pseudoconstant'])) {
$field = BaseFieldDefinition::create('list_string')
->setSetting('allowed_values_function', 'civicrm_entity_pseudoconstant_options')
->setDisplayOptions('view', [
'type' => 'list_default',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => 0,
]);
}
else {
$field = BaseFieldDefinition::create('string')
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'text_default',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 0,
]);
}
if (isset($civicrm_field['html_type']) && $civicrm_field['html_type'] === 'CheckBox') {
$field
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$field
->setCustomStorage(TRUE);
}
return $field;
}