Could someone explain why Profile's annotation doesn't contain "uid" entity key?
Is it just missing? or?
Profile entity implements EntityOwnerInterface as well, but "uid" entity key is missing in annotation...
it just adds some difficulties with implementing different plugins and derivatives based on entity keys.

Comments

alphawebgroup created an issue. See original summary.

alphawebgroup’s picture

Title: Profile annotation » "uid" entity key is missing in Profile annotation
alphawebgroup’s picture

Assigned: Unassigned » alphawebgroup
Category: Support request » Bug report
StatusFileSize
new361 bytes

here is the patch what fixes this.

alphawebgroup’s picture

Assigned: alphawebgroup » Unassigned
Status: Active » Needs work

Looks like it's failed.

1) Drupal\Tests\profile\Kernel\ProfileTest::testLoadDefaultProfile
Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'uid' cannot be null: INSERT INTO {profile} (revision_id, type, uuid, uid, status, is_default, created, changed) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array
(
    [:db_insert_placeholder_0] => 
    [:db_insert_placeholder_1] => test_defaults
    [:db_insert_placeholder_2] => 5903e3f4-20e0-4949-a0cd-9655a74ac8da
    [:db_insert_placeholder_3] => 
    [:db_insert_placeholder_4] => 1
    [:db_insert_placeholder_5] => 
    [:db_insert_placeholder_6] => 1519339063
    [:db_insert_placeholder_7] => 1519339063
)

but.. the question to Maintainers:
is that test correct what is checking the profile creation with uid = NULL?
is it correct by the data integrity?

alphawebgroup’s picture

Status: Needs work » Needs review
StatusFileSize
new1.18 KB
daggerhart’s picture

StatusFileSize
new1.91 KB
new743 bytes

This makes sense to me. This is exactly how the node module handles the uid base field.

I'm not 100% sure about this step, but the node module also wrote an update hook to ensure the uid field was added to the field storage definition - http://cgit.drupalcode.org/drupal/tree/core/modules/node/node.install#n195.

In the spirit of that, I've added an update hook to the patch which performs the same operations for adding the uid to the entity_keys of the profile module.

Feedback welcome

mglaman’s picture

+++ b/profile.install
@@ -54,3 +54,17 @@ function profile_update_8002() {
+
+/**
+ * Add uid to profile entity_keys.
+ */
+function profile_update_8003() {
...
+  $manager = \Drupal::entityDefinitionUpdateManager();
+  $entity_type = $manager->getEntityType('profile');
+  $entity_keys = $entity_type->getKeys();
+  $entity_keys['uid'] = 'uid';
+  $entity_type->set('entity_keys', $entity_keys);
+  $manager->updateEntityType($entity_type);
+  $manager->updateFieldStorageDefinition($manager->getFieldStorageDefinition('uid', 'profile'));
+}

I'm not sure why this is needed, we already have the field available.

Looking at that update function.. now I see:

  // @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.
mglaman’s picture

Apparently that line of code is still valid #2981915: Update MenuLinkContent to use EntityPublishedInterface

	+/**
+ * Add the publishing status entity key to custom menu links.
+ */
+function menu_link_content_update_8601() {
+  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
+  $entity_type = $definition_update_manager->getEntityType('menu_link_content');
+
+  // Add the published entity key to the menu_link_content entity type.
+  $entity_keys = $entity_type->getKeys();
+  $entity_keys['published'] = 'enabled';
+  $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('enabled', 'menu_link_content'));
+
+  return t('The publishing status entity key has been added to custom menu links.');
+}
mglaman’s picture

Status: Needs review » Needs work

No longer applies, working on a reroll

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new2.64 KB

Reroll!

Status: Needs review » Needs work

The last submitted patch, 10: 2946712-10.patch, failed testing. View results

mglaman’s picture

Status: Needs work » Needs review

Okay, only HEAD failure failed.

bojanz’s picture

Status: Needs review » Needs work

This also needs to set the "owner" key, like Commerce did, since that is the 8.7 convention.

mglaman’s picture

Thanks @bojanz

mglaman’s picture

Status: Needs work » Needs review
StatusFileSize
new2.66 KB

Adds owner key alongside legacy uid.

  • mglaman committed b53bd1a on 8.x-1.x
    Issue #2946712 by mglaman, alphawebgroup, daggerhart: "uid" entity key...
mglaman’s picture

Status: Needs review » Fixed

Anddddd committed!

eric_a’s picture

Looks like "menu_link_content" was copy-pasted and not changed. See you in #3038445: Unable to update entity from RC-2?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.