Added Provider field to cases, auto-completed from actor linked to logged-in user. DB update required

This commit is contained in:
naomi 2022-01-21 15:00:26 +00:00
parent 40435a16be
commit cc551b0851
2 changed files with 28 additions and 1 deletions

View File

@ -149,3 +149,17 @@ function opencase_entities_update_8003() {
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('activity_date_time', 'oc_activity', 'oc_activity', $storage_definition);
}
function opencase_entities_update_90001() {
$storage_definition = \Drupal\Core\Field\BaseFieldDefinition::create('entity_reference')
->setLabel(t('Provider'))
->setRevisionable(TRUE)
->setSetting('target_type', 'oc_actor')
->setSetting('handler', 'default')
->setDefaultValueCallback('\Drupal\opencase_entities\Entity\OCActivity::loggedInActorId')
->setDisplayConfigurable('form', true)
->setDisplayConfigurable('view', true);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('oc_provider', 'oc_activity', 'oc_activity', $storage_definition);
}

View File

@ -93,6 +93,11 @@ class OCActivity extends RevisionableContentEntityBase implements OCActivityInte
$formatted = $current_time->format('Y-m-d');
return $formatted;
}
public static function loggedInActorId() {
$linked_actor = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id())->field_linked_opencase_actor;
if (empty($linked_actor)) return [];
else return $linked_actor->target_id ;
}
/**
* {@inheritdoc}
*/
@ -231,7 +236,15 @@ class OCActivity extends RevisionableContentEntityBase implements OCActivityInte
->setSettings([
'datetime_type' => 'date'
]);
$fields['oc_provider'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Provider'))
->setRevisionable(TRUE)
->setSetting('target_type', 'oc_actor')
->setSetting('handler', 'default')
->setDefaultValueCallback('\Drupal\opencase_entities\Entity\OCActivity::loggedInActorId')
->setDisplayConfigurable('form', true)
->setDisplayConfigurable('view', true);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Visible'))
->setDescription('If this box is not ticked this record will be hidden from view for most users. Users with access to unpublished entities will be able to restore it if needed.')