Add owner to the BlockContent entity type

Created on 7 March 2019, almost 6 years ago
Updated 15 August 2024, 4 months ago

Problem/Motivation

Block content entities do not have an owner (uid) field, they do have a revision_user field. All other core entity types have owner fields, block content should have one too!

Proposed resolution

  1. Add owner entity key to BlockContent entity type
  2. Add EntityOwnerInterface to BlockContentInterface and add EntityOwnerTrait to BlockContent
  3. Add ownerBaseFieldDefinitions to baseFieldDefinitions
  4. Add an upgrade path that sets the author of existing Block Content entities to the value of the first revision's revision_user
  5. Add an upgrade path to install the new owner field
  6. - Split to ✨ [PP1] Implement authoring information form element and summary for Block Content Active
  7. Write tests

Canonical MR is https://git.drupalcode.org/project/drupal/-/merge_requests/5500

Disregard all patch files.

Remaining tasks





Review
Commit

Release notes snippet

Block Content entities now have an author field. When updating to 10.4.0, existing Block content entities will have the author will be set to the revision author of the first revision. For sites using the MongoDB database driver, this will happen when each entity is updated via a preSave hook.

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
Block contentΒ  β†’

Last updated 20 days ago

Created by

πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

Live updates comments and jobs are added and updated live.
  • Needs release manager review

    It is used to alert the release manager core committer(s) that an issue significantly affects the overall technical debt or release timeline of Drupal, and their signoff is needed. See the governance policy draft for more information.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡­Switzerland jeremie_alvin

    Here's a patch based on #15 working on Drupal 10.1.6

  • last update about 1 year ago
    Patch Failed to Apply
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Patch #15 is incorrect, the entity key is incorrect and it's not using the EntityOwnerTrait

    I've updated the IS with all steps to get this across the line. The first being a rebase onto 11.x.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Split authoring information + summary JS out into ✨ [PP1] Implement authoring information form element and summary for Block Content Active we can deliver the bulk of functionality easier that way.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Hiding all patches, MR up with a reroll onto 11.x + using EntityOwnerTrait + an install hook for the field def.

    https://git.drupalcode.org/project/drupal/-/merge_requests/5500

  • Pipeline finished with Failed
    about 1 year ago
    Total: 624s
    #53605
  • Pipeline finished with Failed
    about 1 year ago
    Total: 631s
    #53609
  • Status changed to Needs review about 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Should be good to review.

  • Pipeline finished with Canceled
    about 1 year ago
    Total: 234s
    #53616
  • Pipeline finished with Failed
    about 1 year ago
    Total: 661s
    #53618
  • Pipeline finished with Failed
    about 1 year ago
    Total: 917s
    #53621
  • Pipeline finished with Failed
    about 1 year ago
    Total: 800s
    #53625
  • Pipeline finished with Success
    about 1 year ago
    Total: 1349s
    #53634
  • Status changed to RTBC about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Seems like a good first step to getting authored on field add. Though was initially testing on umami where they had those fields on the block_content.

    Applied locally and ran the updb which both ran fine. I see in the DB there is a UID column now for block_content_field_data

    LGTM

  • last update about 1 year ago
    Custom Commands Failed
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Though was initially testing on umami where they had those fields on the block_content.

    It looks like that's the translation author, although I'm not sure how that interacts with the owner field!

  • Pipeline finished with Success
    about 1 year ago
    Total: 718s
    #54081
  • last update about 1 year ago
    Custom Commands Failed
  • last update about 1 year ago
    Custom Commands Failed
  • Status changed to Needs work about 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    Left a couple of comments on the MR.

  • Pipeline finished with Success
    about 1 year ago
    Total: 1171s
    #55941
  • Status changed to Needs review about 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Feedback addressed and back to green (after a random fail).

  • Pipeline finished with Failed
    about 1 year ago
    Total: 166s
    #56419
  • Pipeline finished with Success
    about 1 year ago
    Total: 633s
    #56429
  • Status changed to RTBC about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Believe feedback has been addressed and look forward to this + the UI for it being add :)

  • last update about 1 year ago
    Custom Commands Failed
  • last update about 1 year ago
    Custom Commands Failed
  • last update about 1 year ago
    Custom Commands Failed
  • Pipeline finished with Success
    about 1 year ago
    Total: 544s
    #58673
  • last update about 1 year ago
    Custom Commands Failed
  • last update about 1 year ago
    Custom Commands Failed
  • last update about 1 year ago
    Custom Commands Failed
  • last update about 1 year ago
    Custom Commands Failed
  • last update about 1 year ago
    Custom Commands Failed
  • last update about 1 year ago
    Custom Commands Failed
  • last update about 1 year ago
    Custom Commands Failed
  • last update about 1 year ago
    Custom Commands Failed
  • last update about 1 year ago
    Custom Commands Failed
  • last update 12 months ago
    Custom Commands Failed
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    I'm triaging RTBC issues β†’ . I read the IS and the comments. I didn't find any unanswered questions. But is does look like a follow up is needed for this comment. I am tagging for that.

    I updated credit.

    Leaving at RTBC.

  • last update 12 months ago
    Custom Commands Failed
  • last update 12 months ago
    Custom Commands Failed
  • last update 12 months ago
    Custom Commands Failed
  • last update 12 months ago
    Custom Commands Failed
  • last update 12 months ago
    Custom Commands Failed
  • last update 12 months ago
    Custom Commands Failed
  • last update 12 months ago
    Custom Commands Failed
  • last update 12 months ago
    Custom Commands Failed
  • Pipeline finished with Success
    11 months ago
    Total: 2386s
    #78398
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    acbramley β†’ changed the visibility of the branch 3038365-add-the-entityownerinterface to hidden.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    acbramley β†’ changed the visibility of the branch 11.x to hidden.

  • Status changed to Needs work 10 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    Needs a reroll

  • Status changed to Needs review 10 months ago
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    I think that bug will be fixed by πŸ“Œ Automatically set revision user/log information/created time on entity revisions Needs review but I'll need to double check.

  • Pipeline finished with Success
    10 months ago
    Total: 605s
    #101012
  • Status changed to RTBC 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Does seem issue in #36 should address that comment. Restoring RTBC after reoll

  • Pipeline finished with Success
    10 months ago
    Total: 566s
    #110494
    • catch β†’ committed 34416a08 on 10.3.x
      Issue #3038365 by acbramley, Grimreaper, smustgrave, catch: Add owner to...
    • catch β†’ committed b8d5c0e4 on 11.x
      Issue #3038365 by acbramley, Grimreaper, smustgrave, catch: Add owner to...
  • Status changed to Fixed 10 months ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    Renamed the hook_update_N() to reflect it landing in 10.3.0, otherwise looks good so committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

    • catch β†’ committed 3f5fc53c on 10.3.x
      Revert "Issue #3038365 by acbramley, Grimreaper, smustgrave, catch: Add...
    • catch β†’ committed a1a138cf on 11.x
      Revert "Issue #3038365 by acbramley, Grimreaper, smustgrave, catch: Add...
  • Status changed to Needs work 10 months ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    There's good research and discussion going on in πŸ“Œ Investigate performance of block_content_post_update_set_owner Needs review but it's not a quick fix, so I've gone ahead and reverted the commits here - we can recommit with the optimized update path once that's decided.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    I had a thought about this when I saw this issue in the RTBC queue. What does this mean for user cancelling. For nodes we offer to delete the user's content or move it to the anonymous user.

    With some content blocks deleting them would break your site. This feels a tricky issue.

  • πŸ‡¬πŸ‡§United Kingdom catch

    I had a thought about this when I saw this issue in the RTBC queue. What does this mean for user cancelling. For nodes we offer to delete the user's content or move it to the anonymous user.

    Anonymous user seems reasonable. Deleting does not.

    User cancelling is pretty broken overall, we still have πŸ› comment_user_cancel() doesn't implement a batch Needs review open.

  • Status changed to Needs review 10 months ago
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    It's not clear to me if there's anything to do here wrt. user cancelling? In any case I've merged the changes from πŸ“Œ Investigate performance of block_content_post_update_set_owner Needs review into this MR.

  • Pipeline finished with Failed
    10 months ago
    Total: 492s
    #114204
  • Pipeline finished with Success
    10 months ago
    Total: 490s
    #114211
  • πŸ‡¬πŸ‡§United Kingdom catch

    Adding a new field definition can have an initial value. We can initialize them to 0 so that they are not empty. or we could leave them as null and set an author the next time they are being saved.

    I wondered about this, and I can't really see a downside. Is there any issue with users being able to edit blocks by different owners? I guess our permissions aren't that granular for blocks so maybe not?

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    > I guess our permissions aren't that granular for blocks so maybe not?

    I was going to ask about this too... is there a follow-up to add the own permissions?

  • πŸ‡·πŸ‡΄Romania amateescu

    Adding a new field definition can have an initial value.

    There's also BaseFieldDefinition::setInitialValueFromField(), which in this case would set the owner of each revision to the value of the `revision_user` field.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    > There's also BaseFieldDefinition::setInitialValueFromField(), which in this case would set the owner of each revision to the value of the `revision_user` field.

    True, but I would be surprised if that works as it's not stored in the same table. I think I tried something like that before in a different use case.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Yeah I tried #51 last night and it does not work. Maybe it could be fixed to work... but that is likely to be super complex.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    is there a follow-up to add the own permissions?

    I would argue against adding own permissions - this could be done in contrib. It adds serious cacheability issues as seen in πŸ› MediaAccessControlHandler update/delete access caching is not correct Needs work

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Would be good to get a response re #48 and now the new ideas about whether or not we need the post update.

    I was just about to apply this to our client site and rip out our custom implementation but I want to hold off until this is committed again so I'm not reworking again.

  • Status changed to Needs work 8 months ago
  • The Needs Review Queue Bot β†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Pipeline finished with Failed
    8 months ago
    Total: 178s
    #159229
  • Pipeline finished with Failed
    8 months ago
    Total: 565s
    #159268
  • Pipeline finished with Success
    8 months ago
    Total: 567s
    #159274
  • Status changed to Needs review 8 months ago
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Rerolled and squashed the MR against 11.x - now green again.

    We still need to decide whether we keep the upgrade path or not. IMO the code is there and working so it seems like it'd be good to keep but if people feel otherwise then I'm not too fussed tbh...

  • Status changed to RTBC 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Posted about this in slack #block-content and only hold up seems to be around the post_update hook. Since it's already been added and is functional I don't think we need to remove.

  • Status changed to Needs work 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States xjm

    This is not committable without the comment on the post-update hook being addressed one way or another. It's actually a pretty important question in terms of data integrity and user expectations.

    I also think this is the type of change that merits signoff from the maintainers of the subsystem (also possibly framework managers, but let's start with the subsystem).

    Meanwhile, posted a couple small points of my own feedback on the MR, so NW instead of NR for those to be addressed.

    Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    And probably RM signoff eventually to validate the community consensus about the post-update hook, I guess, but I'd like to hear from subsystem contributors first. :)

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    That would be @acbramely and myself so maybe needs to be framework manager as @larowlan is both.

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Sorry, one more thing... before commit, I'd like clear confirmation that the performance regression has absolutely definitely been addressed. Thanks!

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    The new patch uses a limit and sort per #3425888-6: Investigate performance of block_content_post_update_set_owner β†’ which in theory should resolve the performance issue.

    I like the 'let's just make them all anonymous (uid 0)' idea because none of block content's permissions (see \Drupal\block_content\BlockContentAccessControlHandler::checkAccess) take the owner into account. But given the update hook is written, I think we should test the performance. I will ask @luke.leber if he can retry this patch with the same site he saw the issue on previously. If it performs OK, I think we may as well leave things in the best state rather than offloading the question to a contrib solution.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    which is acbramley and smustgrave saying "meh" apparently

    @xjm I feel like this must have been a driveby comment? Did you read through everything in this issue and the others? This is quite rude to say. I've worked a lot on this issue, including the original post update hook that got reverted and working to make it more performant. I've manually tested this countless times on large sites.

    In #57 I said I'm not fussed if we have it or not, I just want to get this issue in as it's a good improvement and had already been committed before.

  • Pipeline finished with Success
    6 months ago
    Total: 990s
    #201315
  • Status changed to Needs review 6 months ago
  • πŸ‡¦πŸ‡ΊAustralia acbramley
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    I like the 'let's just make them all anonymous (uid 0)' idea

    I think that's a decent approach if we deem this update hook too heavy, although for me it seems like something core absolutely needs to be able to support. Direct db queries are the most performant way to do this (that I can think of), if even that is too heavy what happens when an issue comes along that must have an update hook like this? We need a scalable way to set entity values in upgrade paths.

    Also, I feel like setting everything to uid 0 may be confusing to users. Block content entities already have a revision user, if the author gets added and its anonymous that could be confusing in the UI?

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    @acbramley, my apologies, I did not mean to sound critical at all. I was documenting that both you and @smustgrave don't have strong feelings either way about the post-update hook (you feel "meh" about it), and so therefore we needed to escalate it to a tie-breaking role (Lee in this case). Sorry again for how it came across!

  • πŸ‡ΊπŸ‡ΈUnited States luke.leber Pennsylvania

    Timing on !5500 on 19621 blocks, 24290 revisions, and a batch size of 50 (default).

    real    0m19.932s
    user    0m11.936s
    sys     0m0.955s
    

    ~20 seconds is a lot more acceptable than 30 minutes! What a difference the Database API makes versus the Entity API!

  • Status changed to Needs work 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Thanks for your patience on this issue.

    I discussed this issue at Dev Davs with @catch and @daffie following discussion with @acbramley in Slack.

    The new performance is great; however, the downside of the approach currently being used is that it won't work on no-SQL databases. We discussed this with @daffie and he will propose a related issue that will allow core updates to better support an SQL case and a no-SQL case.

    We also discussed the proposal to set it to 0 as @Berdir suggested. We're concerned that this could have unintended side effects in edgecases or specific site configurations.

    If the data validation allows it to be set to NULL, that would be ideal. Then we can add code that happens on entity save to set a given block's author based on the first revision, so that it happens as-needed rather than in a big batch. So that's the approach we recommend (so long as it is feasible).

    Meanwhile, this issue has a data model improvement that should have a change record and maybe a release note. (We'll decide after the final approach whether to use the release note, but having a good release note will help us think about the impacts on site owners, code, etc. as well as edgecases.)

    Leaving "Needs release manager review" pending the new approach. Thanks!

  • πŸ‡³πŸ‡±Netherlands daffie
  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Saving some credits.

  • πŸ‡¬πŸ‡§United Kingdom catch

    I agree 0 feels risky, not for core but in case contrib is doing something weird.

    NULL seems OK if we could do it, but not sure what the implications of that are.

    So checking whether we're running on a relational database or not then doing the direct update if we are seems OK compared to all the other options. I'd be OK with hard-coding mongodb in the update here if we have the follow-up to add a connection class method or similar. Or if that issue is easy to get done, we could do that first then check here (with otherwise exactly the current logic in the patch).

    20 seconds for thousands of blocks is more than good enough for performance of the update so that bit is great now.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    NULL seems OK if we could do it, but not sure what the implications of that are.

    Doing some testing locally - I don't see any issues with leaving it NULL, the owner field is already nullable and the default value is null. That means when we install the new field (in block_content_update_10301) all existing rows get NULL as the uid column value. So step 1 is taken care of automatically :)

    Next step was to test what currently happens with existing blocks if you edit them without an author, I expected the defaultValueCallback from EntityOwnerTrait to kick in and set the owner to the current user, but that does not happen on update, only on insert. IMO that's good - one less thing for us to worry about overriding.

    (FYI That does not happen for revision_user - I reported this somewhere else but forgot about it, Block Content's revision_user is not set on the initial revision only on subsequent revisions. Node acts correctly so there must be some custom code doing that rather than using the default value callback. Tested MenuLinkContent as well and that has the same issue. I think πŸ“Œ Automatically set revision user/log information/created time on entity revisions Needs review will cover this)

    Next is to implement a preSave which sets the owner based on the initial revision's revision_user (which may be empty for some blocks because of the above, not much we can do about that though). As I'm writing this though I realise this can't use the same database queries though...

  • Status changed to Needs review 6 months ago
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    This will most likely be my last push on this issue. Someone else will have to pick up the torch from here on out as I've lost interest in getting it across the line due to all the rework. Unfortunately that probably means this issue is dead in the water.

    I think we're going to have quite a few issues with this new approach:

    1. The update path test will probably fail because the author will be set by the preSave
    2. It's impossible to test that preSave because the author will be set for new blocks by the default callback
    3. It's really ugly IMO.

  • Pipeline finished with Failed
    6 months ago
    Total: 556s
    #210267
  • Status changed to Needs work 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Appears to have a functional test failure

    1)
        Drupal\Tests\block_content\Functional\Update\BlockContentUpdateTest::testAddAndSetOwnerField
        Failed asserting that null matches expected '4'.
        
        /builds/issue/drupal-3038365/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php:74
    
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    This would be very awkward for people already using the patch, but #1233394: Agree on a property naming pattern β†’ reminded me that we shouldn't be adding new fields with the old combined property/field names like uid anymore. Back then that issue proposed user_id, but I think just naming it owner would make more sense.

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    This issue is stalled on worse things than what the field is named πŸ˜… I have no preference but it does seem redundant to change it at this point, just making it harder for people using it already

  • πŸ‡ΊπŸ‡ΈUnited States luke.leber Pennsylvania

    Agree that the ship has likely sailed with such naming convention standardizations as the landscape exists.

    The time to decide such things was before there were literally billions of records and tens of thousands of custom sites depending on certain field names.

    Any changes at this point would likely require a brand new way to performantly migrate huge volumes of records to new columns and would likely require maintaining redundancies between multiple major Drupal versions to prevent disastrous upgrades.

Production build 0.71.5 2024