You are here

protected function FieldDefinitionProvider::getTextDefinition in CiviCRM Entity 8.3

Gets a text field definition.

These are long text fields, and all default to being rich text. The CiviCRM API does not provide a way to identify plain text or rich text fields.

The CiviCRM field info is passed so that the method can be override to provide other specific logic in different implementations.

Parameters

array $civicrm_field: The CiviCRM field definition.

Return value

\Drupal\Core\Field\BaseFieldDefinition The base field definition.

1 call to FieldDefinitionProvider::getTextDefinition()
FieldDefinitionProvider::getBaseFieldDefinition in src/Entity/FieldDefinitionProvider.php
Gets an entity base field definition from a CiviCRM field definition.

File

src/Entity/FieldDefinitionProvider.php, line 258

Class

FieldDefinitionProvider

Namespace

Drupal\civicrm_entity\Entity

Code

protected function getTextDefinition(array $civicrm_field) {
  if (!empty($civicrm_field['html']['type']) && $civicrm_field['html']['type'] == 'RichTextEditor' || !empty($civicrm_field['html_type']) && $civicrm_field['html_type'] == 'RichTextEditor') {
    $field_type = 'text_long';
  }
  elseif (!empty($civicrm_field['description']) && strpos($civicrm_field['description'], 'Text and html allowed.') !== FALSE) {
    $field_type = 'text_long';
  }
  else {
    $field_type = 'string_long';
  }
  if ($civicrm_field['name'] === 'details' && $civicrm_field['entity'] === 'Case') {
    $field_type = 'text_long';
  }
  $field = BaseFieldDefinition::create($field_type)
    ->setDisplayOptions('view', [
    'type' => $field_type == 'string_long' ? 'basic_string' : 'text_default',
    'weight' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => $field_type == 'string_long' ? 'string_textarea' : 'civicrm_entity_textarea',
    'weight' => 0,
    // If the default text formatter is CKEditor, this will be ignored.
    'rows' => isset($civicrm_field['rows']) ? $civicrm_field['rows'] : 5,
  ]);
  return $field;
}