You are here

public static function ContactEmail::baseFieldDefinitions in Contact Emails 8

Provides base field definitions for an entity type.

Implementations typically use the class \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions; for example a 'name' field could be defined as the following:

$fields['name'] = BaseFieldDefinition::create('string')
  ->setLabel(t('Name'));

By definition, base fields are fields that exist for every bundle. To provide definitions for fields that should only exist on some bundles, use \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions().

The definitions returned by this function can be overridden for all bundles by hook_entity_base_field_info_alter() or overridden on a per-bundle basis via 'base_field_override' configuration entities.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.

Return value

\Drupal\Core\Field\FieldDefinitionInterface[] An array of base field definitions for the entity type, keyed by field name.

Overrides ContentEntityBase::baseFieldDefinitions

See also

\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()

\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()

File

src/Entity/ContactEmail.php, line 77

Class

ContactEmail
Defines the Contact Email entity.

Namespace

Drupal\contact_emails\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = parent::baseFieldDefinitions($entity_type);

  // Contact form.
  $fields['contact_form'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Contact form'))
    ->setDescription(t('The associated contact form entity.'))
    ->setRequired(TRUE)
    ->setTranslatable(TRUE)
    ->setSettings([
    'target_type' => 'contact_form',
    'handler' => 'default',
    'default_value' => NULL,
  ])
    ->setDisplayOptions('form', [
    'weight' => -15,
  ]);
  $fields['subject'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Subject'))
    ->setDescription(t('Subject of the email.'))
    ->setRequired(TRUE)
    ->setTranslatable(TRUE)
    ->setDefaultValue('')
    ->setSettings([
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -10,
    'settings' => [
      'size' => 64,
    ],
  ]);
  $fields['message'] = BaseFieldDefinition::create('text_long')
    ->setLabel(t('Message'))
    ->setDescription(t('The email message body.'))
    ->setDefaultValue('')
    ->setTranslatable(TRUE)
    ->setSettings([
    'max_length' => 9999,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'text_textarea',
    'weight' => -5,
    'settings' => [
      'rows' => 4,
    ],
  ]);
  $fields['append_message'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Append message'))
    ->setDescription(t('Append the entire message below the body of the email.'))
    ->setTranslatable(TRUE)
    ->setDefaultValue(TRUE)
    ->setDisplayOptions('form', [
    'type' => 'boolean_checkbox',
    'weight' => 0,
    'settings' => [
      'display_label' => TRUE,
    ],
  ]);
  $fields['recipient_type'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Recipient type'))
    ->setDescription(t('How to determine the submitter of the form.'))
    ->setDefaultValue('manual')
    ->setTranslatable(TRUE)
    ->setSettings([
    'max_length' => 20,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 0,
  ]);
  $fields['recipients'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Recipients'))
    ->setDescription(t('Recipients of the email.'))
    ->setDefaultValue('')
    ->setTranslatable(TRUE)
    ->setSettings([
    'max_length' => 9999,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'textarea',
    'weight' => 0,
    'settings' => [
      'display_label' => TRUE,
    ],
  ]);
  $fields['recipient_field'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Recipient field'))
    ->setDescription(t('The field to send to if recipient type is field.'))
    ->setDefaultValue('')
    ->setTranslatable(TRUE)
    ->setSettings([
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 0,
  ]);
  $fields['recipient_reference'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Recipient reference'))
    ->setDescription(t('The field to send to if recipient type is reference.'))
    ->setDefaultValue('')
    ->setTranslatable(TRUE)
    ->setSettings([
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 0,
  ]);
  $fields['reply_to_type'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Reply-to type'))
    ->setDescription(t('The type of reply-to.'))
    ->setDefaultValue('default')
    ->setTranslatable(TRUE)
    ->setSettings([
    'max_length' => 10,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 0,
  ]);
  $fields['reply_to_email'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Reply-to email'))
    ->setDescription(t('The field to set the reply-to as if reply-to type is email.'))
    ->setDefaultValue('')
    ->setTranslatable(TRUE)
    ->setSettings([
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_email',
    'weight' => 0,
  ]);
  $fields['reply_to_field'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Reply-to field'))
    ->setDescription(t('The field to set the reply-to as if reply-to type is field.'))
    ->setDefaultValue('')
    ->setTranslatable(TRUE)
    ->setSettings([
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 0,
  ]);
  $fields['reply_to_reference'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Reply-to reference'))
    ->setDescription(t('The field to use if recipient type is reference.'))
    ->setDefaultValue('')
    ->setTranslatable(TRUE)
    ->setSettings([
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => 0,
  ]);
  $fields['status'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Enabled'))
    ->setDescription(t('Whether or not this email is enabled.'))
    ->setTranslatable(TRUE)
    ->setDefaultValue(TRUE)
    ->setDisplayOptions('form', [
    'type' => 'boolean_checkbox',
    'weight' => 10,
    'settings' => [
      'display_label' => TRUE,
    ],
  ]);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Created'))
    ->setTranslatable(TRUE)
    ->setDescription(t('The time that the entity was created.'));
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setTranslatable(TRUE)
    ->setDescription(t('The time that the entity was last edited.'));
  return $fields;
}