You are here

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

Same name and namespace in other branches
  1. 8 src/Entity/Pet.php \Drupal\pet\Entity\Pet::baseFieldDefinitions()
  2. 8.3 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 ContentEntityBase::baseFieldDefinitions

See also

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

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

File

src/Entity/Pet.php, line 71

Class

Pet
Defines pet entity class.

Namespace

Drupal\pet\Entity

Code

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {

  // Standard field, used as unique if primary index.
  $fields['id'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('ID'))
    ->setDescription(t('The internal identifier for any templates.'))
    ->setReadOnly(TRUE)
    ->setSetting('unsigned', TRUE)
    ->setDisplayOptions('view', [
    'weight' => -10,
  ]);

  // Standard field, unique outside of the scope of the current project.
  $fields['uuid'] = BaseFieldDefinition::create('uuid')
    ->setLabel(t('UUID'))
    ->setDescription(t('The UUID of the Pets entity.'))
    ->setReadOnly(TRUE);
  $fields['module'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Module'))
    ->setDescription(t('The name of the providing module if the entity has been defined in code.'));
  $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)
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
  ])
    ->setDisplayOptions('form', [
    'type' => 'string_textfield',
    'weight' => -14,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['status'] = BaseFieldDefinition::create('integer')
    ->setLabel(t('Status'))
    ->setDescription(t('The exportable status of the entity.'))
    ->setRequired(TRUE)
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'integer',
    'unsigned' => TRUE,
    'weight' => -12,
  ]);
  $fields['langcode'] = BaseFieldDefinition::create('language')
    ->setLabel(t('Language code'))
    ->setDescription(t('The Pet entity language code.'))
    ->setRevisionable(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)
    ->setTranslatable(TRUE)
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -9,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string',
    'weight' => -9,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['mail_body'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Mail Body'))
    ->setDescription(t('The body of the email template. May include tokens of any token type specified below.'))
    ->setDefaultValue(NULL)
    ->setTranslatable(TRUE)
    ->setDisplayOptions('form', [
    'type' => 'string_textarea',
    'weight' => -8,
    'settings' => [
      'rows' => 4,
    ],
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['mail_body_plain'] = BaseFieldDefinition::create('string_long')
    ->setLabel(t('Mail Body Plain'))
    ->setDescription(t('The plain text body of the email template. May include tokens of any token type specified below. If left empty Mime Mail will use drupal_html_to_text() to create a plain text version of the email.'))
    ->setTranslatable(TRUE)
    ->setDisplayOptions('form', [
    'type' => 'string_textarea',
    'weight' => -7,
    'settings' => [
      'rows' => 4,
    ],
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['send_plain'] = BaseFieldDefinition::create('boolean')
    ->setLabel(t('Send only plain text'))
    ->setDescription(t('Send email as plain text only. If checked, only the plain text here will be sent. If unchecked both will be sent as multipart mime.Send email as plain text only. If checked, only the plain text here will be sent. If unchecked both will be sent as multipart mime..'))
    ->setDisplayOptions('form', [
    'weight' => -6,
    'type' => 'boolean_checkbox',
    '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.'))
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
  ])
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -5,
  ])
    ->setDisplayOptions('form', [
    'type' => 'string',
    'weight' => -5,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['from_override'] = BaseFieldDefinition::create('email')
    ->setLabel(t('From Override'))
    ->setDescription(t('Email to override system from address.'))
    ->setSettings([
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,
  ])
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'email',
    'weight' => -4,
  ])
    ->setDisplayOptions('form', [
    'type' => 'email',
    'weight' => -4,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['cc_default'] = BaseFieldDefinition::create('email')
    ->setLabel(t('CC Default'))
    ->setDescription(t('Emails to be copied by default for each mail sent to recipient. Enter emails separated by lines or commas.'))
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -3,
  ])
    ->setDisplayOptions('form', [
    'type' => 'email',
    'weight' => -3,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);
  $fields['bcc_default'] = BaseFieldDefinition::create('email')
    ->setLabel(t('BCC Default'))
    ->setDescription(t('Emails to be blind copied by default for each mail sent to recipient. Enter emails separated by lines or commas.'))
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'string',
    'weight' => -2,
  ])
    ->setDisplayOptions('form', [
    'type' => 'email',
    'weight' => -2,
  ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);

  // Owner field of the pets.
  // Entity reference field, holds the reference to the user object.
  // The view shows the user name field of the user.
  // The form presents a auto complete field for the user name.
  $fields['user_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('User Name'))
    ->setDescription(t('The Name of the associated user.'))
    ->setSetting('target_type', 'user')
    ->setSetting('handler', 'default')
    ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'entity_reference',
    'weight' => -1,
  ])
    ->setDisplayConfigurable('form', FALSE)
    ->setDisplayConfigurable('view', TRUE);
  return $fields;
}