public static function MappedObject::baseFieldDefinitions in Salesforce Suite 8.3
Same name and namespace in other branches
- 8.4 modules/salesforce_mapping/src/Entity/MappedObject.php \Drupal\salesforce_mapping\Entity\MappedObject::baseFieldDefinitions()
- 5.0.x modules/salesforce_mapping/src/Entity/MappedObject.php \Drupal\salesforce_mapping\Entity\MappedObject::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
- modules/
salesforce_mapping/ src/ Entity/ MappedObject.php, line 178
Class
- MappedObject
- Defines a Salesforce Mapped Object entity class.
Namespace
Drupal\salesforce_mapping\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$i = 0;
if (\Drupal::moduleHandler()
->moduleExists('dynamic_entity_reference')) {
$fields['drupal_entity'] = BaseFieldDefinition::create('dynamic_entity_reference')
->setLabel(t('Mapped Entity'))
->setDescription(t('Reference to the Drupal entity mapped by this mapped object.'))
->setRevisionable(FALSE)
->setCardinality(1)
->setDisplayOptions('form', [
'type' => 'dynamic_entity_reference_default',
'weight' => $i,
])
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'dynamic_entity_reference_label',
'weight' => $i++,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
}
$fields['salesforce_mapping'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Salesforce mapping'))
->setDescription(t('Salesforce mapping used to push/pull this mapped object'))
->setRevisionable(TRUE)
->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH)
->setSetting('target_type', 'salesforce_mapping')
->setSetting('handler', 'default')
->setRequired(TRUE)
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => $i,
])
->setSettings([
'allowed_values' => [],
])
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => $i++,
]);
// @TODO make this work with Drupal\salesforce\SFID (?)
$fields['salesforce_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Salesforce ID'))
->setDescription(t('Reference to the mapped Salesforce object (SObject)'))
->setRevisionable(TRUE)
->setTranslatable(FALSE)
->setSetting('is_ascii', TRUE)
->setSetting('max_length', SFID::MAX_LENGTH)
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => $i++,
])
->setDisplayOptions('view', [
'type' => 'hidden',
]);
$fields['salesforce_link'] = BaseFieldDefinition::create('salesforce_link')
->setLabel('Salesforce Record')
->setDescription(t('Link to salesforce record'))
->setRevisionable(FALSE)
->setTranslatable(FALSE)
->setComputed(TRUE)
->setClass(SalesforceLinkItemList::class)
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => $i++,
]);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Authored on'))
->setDescription(t('The time that the object mapping was created.'))
->setRevisionable(TRUE)
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'timestamp',
'weight' => $i++,
]);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the object mapping was last edited.'))
->setRevisionable(TRUE)
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => $i++,
]);
$fields['entity_updated'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Drupal Entity Updated'))
->setDescription(t('The Unix timestamp when the mapped Drupal entity was last updated.'))
->setRevisionable(TRUE)
->setDefaultValue(0)
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => $i++,
]);
$fields['last_sync_status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Status of most recent sync'))
->setDescription(t('Indicates whether most recent sync was successful or not.'))
->setRevisionable(TRUE);
$fields['last_sync_action'] = BaseFieldDefinition::create('string')
->setLabel(t('Action of most recent sync'))
->setDescription(t('Indicates acion which triggered most recent sync for this mapped object'))
->setSetting('is_ascii', TRUE)
->setSetting('max_length', MappingConstants::SALESFORCE_MAPPING_TRIGGER_MAX_LENGTH)
->setRevisionable(TRUE);
$fields['force_pull'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Force Pull'))
->setDescription(t('Whether to ignore entity timestamps and force an update on the next pull for this record.'))
->setRevisionable(FALSE);
// @see ContentEntityBase::baseFieldDefinitions
// and RevisionLogEntityTrait::revisionLogBaseFieldDefinitions
$fields += parent::baseFieldDefinitions($entity_type);
return $fields;
}