Add a required single-value plan entity reference base field.

This commit is contained in:
Michael Stenta 2024-01-08 17:49:13 -05:00
parent 79704c3c7c
commit 4f4f666c28
2 changed files with 25 additions and 0 deletions

View File

@ -5,3 +5,4 @@ package: farmOS
core_version_requirement: ^10
dependencies:
- entity:entity
- farm:plan

View File

@ -3,6 +3,8 @@
namespace Drupal\plan_record\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
/**
* Defines the Plan record relationship entity.
@ -43,4 +45,26 @@ class PlanRecord extends ContentEntityBase implements PlanRecordInterface {
return $type->label();
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['plan'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Plan'))
->setDescription(t('Associate this plan record relationship with a plan entity.'))
->setTranslatable(FALSE)
->setCardinality(1)
->setSetting('target_type', 'plan')
->setDisplayOptions('form', [
'type' => 'entity_reference',
'weight' => 12,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
}