You are here

public static function Pet::baseFieldDefinitions in Previewable email templates 8.3

Same name and namespace in other branches
  1. 8.4 src/Entity/Pet.php \Drupal\pet\Entity\Pet::baseFieldDefinitions()
  2. 8 src/Entity/Pet.php \Drupal\pet\Entity\Pet::baseFieldDefinitions()

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 RevisionableContentEntityBase::baseFieldDefinitions

See also

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

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

File

src/Entity/Pet.php, line 145

Class

Pet
Defines the pet entity.

Namespace

Drupal\pet\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = parent::baseFieldDefinitions($entity_type);
  $fields['user_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Authored by'))
    ->setDescription(t('The user ID of author of the pet entity.'))
    ->setRevisionable(TRUE)
    ->setSetting('target_type', 'user')
    ->setSetting('handler', 'default')
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'hidden',
  ])
    ->setDisplayOptions('form', [
    'type' => 'entity_reference_autocomplete',
    'weight' => 5,
    'settings' => [
      'match_operator' => 'CONTAINS',
      'size' => '60',
      'autocomplete_type' => 'tags',
      'placeholder' => '',
    ],
  ])
    ->setDisplayConfigurable('view', TRUE);
  $fields['title'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Title'))
    ->setDescription(t('A short, descriptive title for this email template. It will be used in administrative interfaces, and in page titles and menu items.'))
    ->setRequired(TRUE)
    ->setRevisionable(TRUE)
    ->setSettings([
    'max_length' => 50,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -8,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -8,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['subject'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Subject'))
    ->setDescription(t('The subject line of the email template. May include tokens of any token type specified below.'))
    ->setRequired(TRUE)
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -7,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string',
    'weight' => -7,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['mail_body'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Body'))
    ->setDescription(t('The plain text body of the email template. May include tokens of any token type specified below.'))
    ->setDefaultValue(NULL)
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -6,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textarea',
    'weight' => -6,
    'settings' => [
      'rows' => 4,
    ],
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['mail_body_html'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('HTML body'))
    ->setDescription(t('The HTML body of the email template. May include tokens of any token type specified below.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -5,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textarea',
    'weight' => -5,
    'settings' => [
      'rows' => 4,
    ],
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['format'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Format'))
    ->setDescription(t('HTML format.'))
    ->setDefaultValue(NULL)
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -4,
  ]);
  $fields['send_plain'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Send only plain text'))
    ->setDescription(t('If checked, only the plain text will be sent. If unchecked both will be sent as multipart mime.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -4,
  ])
    ->setDisplayOptions('form', [
    'type' => 'boolean_checkbox',
    'weight' => -4,
    'settings' => [
      'display_label' => TRUE,
    ],
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['recipient_callback'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Recipient Callback'))
    ->setDescription(t('The name of a function which will be called to retrieve a list of recipients. This function will be called if the query parameter uid=0 is in the URL. It will be called with one argument, the loaded node (if the PET takes one) or NULL if not. This function should return an array of recipients in the form uid|email, as in 136|bob@example.com. If the recipient has no uid, leave it blank but leave the pipe in. Providing the uid allows token substitution for the user.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
  ])
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -0,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string',
    'weight' => -0,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['reply_to'] = BaseFieldDefinition::create('email')
    ->setLabel(t('Reply-To'))
    ->setDescription(t('Reply-To email address.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'email',
    'weight' => -3,
  ])
    ->setDisplayOptions('form', [
    'type' => 'email',
    'weight' => -3,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['cc'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Cc'))
    ->setDescription(t('Cc recipients, comma separated.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -2,
  ])
    ->setDisplayOptions('form', [
    'type' => 'email',
    'weight' => -2,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['bcc'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Bcc'))
    ->setDescription(t('Bcc recipients, comma separated.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -1,
  ])
    ->setDisplayOptions('form', [
    'type' => 'email',
    'weight' => -1,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['status'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Publishing status'))
    ->setDescription(t('A boolean indicating whether the entity is published.'))
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE)
    ->setDefaultValue(TRUE);
  $fields['created'] = BaseFieldDefinition::create('created')
    ->setLabel(t('Created'))
    ->setDescription(t('The time that the entity was created.'))
    ->setTranslatable(TRUE);
  $fields['changed'] = BaseFieldDefinition::create('changed')
    ->setLabel(t('Changed'))
    ->setDescription(t('The time that the entity was last edited.'))
    ->setTranslatable(TRUE);
  $fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Revision translation affected'))
    ->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
    ->setReadOnly(TRUE)
    ->setRevisionable(TRUE)
    ->setTranslatable(TRUE);
  return $fields;
}