Commit b53bd1a6 authored by mglaman's avatar mglaman Committed by mglaman

Issue #2946712 by mglaman, alphawebgroup, daggerhart: "uid" entity key is...

Issue #2946712 by mglaman, alphawebgroup, daggerhart: "uid" entity key is missing in Profile annotation
parent 42e0b561
......@@ -87,3 +87,28 @@ function profile_update_8003() {
return t('Language code key removed from profile entity definition.');
}
/**
* Add the uid entity key to profiles.
*/
function profile_update_8004() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type = $definition_update_manager->getEntityType('menu_link_content');
$entity_keys = $entity_type->getKeys();
$entity_keys['uid'] = 'uid';
$entity_type->set('entity_keys', $entity_keys);
$definition_update_manager->updateEntityType($entity_type);
// @todo The above should be enough, since that is the only definition that
// changed. But \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema varies
// field schema by whether a field is an entity key, so invoke
// EntityDefinitionUpdateManagerInterface::updateFieldStorageDefinition()
// with an unmodified field storage definition to trigger the necessary
// changes. SqlContentEntityStorageSchema::onEntityTypeUpdate() should be
// fixed to automatically handle this.
// @see https://www.drupal.org/node/2554245
$definition_update_manager->updateFieldStorageDefinition($definition_update_manager->getFieldStorageDefinition('uid', 'profile'));
return t('The uid entity key has been added to profiles.');
}
......@@ -48,6 +48,8 @@ use Drupal\user\UserInterface;
* "id" = "profile_id",
* "revision" = "revision_id",
* "bundle" = "type",
* "owner" = "uid",
* "uid" = "uid",
* "uuid" = "uuid"
* },
* links = {
......@@ -264,7 +266,8 @@ class Profile extends ContentEntityBase implements ProfileInterface {
->setDescription(t('The user that owns this profile.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default');
->setSetting('handler', 'default')
->setDefaultValueCallback('Drupal\profile\Entity\Profile::getCurrentUserId');
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Active'))
......@@ -290,4 +293,16 @@ class Profile extends ContentEntityBase implements ProfileInterface {
return $fields;
}
/**
* Default value callback for 'uid' base field definition.
*
* @see ::baseFieldDefinitions()
*
* @return array
* An array of default values.
*/
public static function getCurrentUserId() {
return [\Drupal::currentUser()->id()];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment