public function EntityTypeInfo::entityBaseFieldInfo in Workbench Moderation 8.2
Same name and namespace in other branches
- 8 src/EntityTypeInfo.php \Drupal\workbench_moderation\EntityTypeInfo::entityBaseFieldInfo()
Adds base field info to an entity type.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: Entity type for adding base fields to.
Return value
\Drupal\Core\Field\BaseFieldDefinition[] New fields added by moderation state.
File
- src/
EntityTypeInfo.php, line 257
Class
- EntityTypeInfo
- Service class for manipulating entity type information.
Namespace
Drupal\workbench_moderationCode
public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
if (!$this->moderationInfo
->isModeratableEntityType($entity_type)) {
return [];
}
$fields = [];
// @todo write a test for this.
$fields['moderation_state'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Moderation state'))
->setDescription(t('The moderation state of this piece of content.'))
->setSetting('target_type', 'moderation_state')
->setTargetEntityTypeId($entity_type
->id())
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'hidden',
'weight' => -5,
])
->setDisplayOptions('form', [
'type' => 'moderation_state_default',
'weight' => 5,
'settings' => [],
])
->addConstraint('ModerationState', [])
->setDisplayConfigurable('form', FALSE)
->setDisplayConfigurable('view', FALSE);
return $fields;
}