You are here

function easy_email_field_add_from_address_field in Easy Email 8

Same name and namespace in other branches
  1. 2.0.x easy_email.module \easy_email_field_add_from_address_field()
1 call to easy_email_field_add_from_address_field()
easy_email_entity_insert in ./easy_email.module

File

./easy_email.module, line 785
Contains easy_email.module.

Code

function easy_email_field_add_from_address_field(EasyEmailTypeInterface $easy_email_type) {
  $field_definition = BaseFieldDefinition::create('string')
    ->setTargetEntityTypeId('easy_email')
    ->setTargetBundle($easy_email_type
    ->id())
    ->setName('from_address')
    ->setLabel(t('From Address'))
    ->setDescription(t('The From address of the Email entity.'))
    ->setRevisionable(TRUE)
    ->setSettings([
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDefaultValue('')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -4,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -4,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  try {
    easy_email_create_field($field_definition, FALSE);
  } catch (\RuntimeException $e) {

    // In this case, field already exists from installation
  } catch (EntityStorageException $e) {

    // In this case, field already exists from installation
  }
}