You are here

function message_ui_entity_base_field_info_alter in Message UI 8

Implements hook_entity_base_field_info_alter().

Extend the message entity type's field by providing display handlers.

File

./message_ui.module, line 53
Contains Drupal\message_ui\message_ui.module.

Code

function message_ui_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {

  // Alter the uid and created field to include display settings.
  if ($entity_type
    ->id() != 'message') {
    return;
  }
  if (!empty($fields['uid'])) {

    /* @var Drupal\Core\Field\BaseFieldDefinition $fields['uid'] */
    $fields['uid']
      ->setDisplayOptions('view', [
      'label' => 'hidden',
      'type' => 'author',
      'weight' => 0,
    ])
      ->setDisplayOptions('form', [
      'type' => 'entity_reference_autocomplete',
      'weight' => 5,
      '#group' => 'advanced',
      'settings' => [
        'match_operator' => 'CONTAINS',
        'size' => '60',
        'placeholder' => '',
      ],
    ])
      ->setDisplayConfigurable('form', TRUE)
      ->setRequired(TRUE);
  }
  if (!empty($fields['created'])) {
    $fields['created']
      ->setDisplayOptions('view', [
      'label' => 'hidden',
      'type' => 'timestamp',
      'weight' => 0,
    ])
      ->setDisplayOptions('form', [
      'type' => 'datetime_timestamp',
      'weight' => 10,
    ])
      ->setDisplayConfigurable('form', TRUE);
  }
}