public static function SmsDeliveryReport::baseFieldDefinitions in SMS Framework 8
Same name and namespace in other branches
- 2.x src/Entity/SmsDeliveryReport.php \Drupal\sms\Entity\SmsDeliveryReport::baseFieldDefinitions()
- 2.1.x src/Entity/SmsDeliveryReport.php \Drupal\sms\Entity\SmsDeliveryReport::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/ SmsDeliveryReport.php, line 172
Class
- SmsDeliveryReport
- Defines the SMS message delivery report entity.
Namespace
Drupal\sms\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['message_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Message ID'))
->setDescription(t('The message ID assigned to the message.'))
->setReadOnly(TRUE)
->setDefaultValue('');
$fields['recipient'] = BaseFieldDefinition::create('string')
->setLabel(t('Recipient number'))
->setDescription(t('The phone number of the recipient of the message.'))
->setReadOnly(TRUE)
->setDefaultValue('')
->setRequired(TRUE);
$fields['status'] = BaseFieldDefinition::create('string')
->setLabel(t('Delivery status'))
->setDescription(t('A status code from \\Drupal\\sms\\Message\\SmsMessageReportStatus.'))
->setReadOnly(TRUE)
->setRequired(TRUE)
->setRevisionable(TRUE);
$fields['status_message'] = BaseFieldDefinition::create('string')
->setLabel(t('Status message'))
->setDescription(t('The status message as provided by the gateway API.'))
->setReadOnly(TRUE)
->setDefaultValue('')
->setRequired(FALSE)
->setRevisionable(TRUE);
$fields['status_time'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Status time'))
->setDescription(t('The time for the current delivery report status.'))
->setReadOnly(TRUE)
->setRequired(TRUE)
->setRevisionable(TRUE);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time the entity was last updated.'))
->setTranslatable(TRUE)
->setRevisionable(TRUE);
$fields['sms_message'] = BaseFieldDefinition::create('entity_reference')
->setSetting('target_type', 'sms')
->setLabel(t('SMS Message'))
->setDescription(t('The parent SMS message.'))
->setReadOnly(TRUE)
->setRequired(TRUE);
return $fields;
}