Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Custom blocks don't have changed time tracking. See various reasons why this is a problem at #2074191: [META] Add changed timestamp tracking to content entities.
Proposed resolution
Add change time tracking to custom blocks.
Remaining tasks
User interface changes
None.
API changes
Schema changed. New getChangedTime method added. This naming is already used on other entity types. See #2044583: Add EntityChangedInterface to allow entities with "changed" field to be properly cached for unification of this.
Related Issues
#2044583: Add EntityChangedInterface to allow entities with "changed" field to be properly cached
#2074191: [META] Add changed timestamp tracking to content entities
Comment | File | Size | Author |
---|---|---|---|
#16 | changed-custom-block-16.patch | 7.95 KB | Wim Leers |
#16 | interdiff.txt | 4.01 KB | Wim Leers |
#15 | changed-custom-block-15.patch | 7.48 KB | Gábor Hojtsy |
#13 | changed-custom-block-13.patch | 7.47 KB | Gábor Hojtsy |
#13 | interdiff.txt | 1.04 KB | Gábor Hojtsy |
Comments
Comment #2
Gábor HojtsyAs per @berdir as of yesterday, we should now have a baseFieldDefinitions() entry as well for this. Let's see how this works :)
Comment #3
Gábor HojtsyComment #5
BerdirAh, sorry, should have thought of this before. This is the init() insanity. It is a crazy trick to make auto-complete of them work without having them actually exist on an instantiated object. We're removing them as we're adding methods/interfaces, they're useless with interface type hints anyway.
Just don't define protected $changed and should work.
Comment #6
Gábor HojtsyYeah I previously tried to have the unset() in init() which I thought would solve the problem (I guess based on your explanation) but that did not work either. Let's see not defining the property then :) Its a magic property either way.
Comment #7
Wim LeersI'm not sure how to review the
hook_schema_0()
changes because there are no docs for it, so somebody else should review that.All other changes are identical to how it's handled for nodes. So that looks good.
I think this needs tests, but I'm not entirely certain … because not a single test verifies thatNode::getChangedTime()
is correct either. There is some test coverage forFile::getChangedTime()
, but it is very light.This needs tests, see
NodeSaveTest::testTimestamps()
.I think this is RTBC-worthy, but somebody who's familiar with the entity/node system should probably RTBC it, in case there are special things that must be done.
Comment #8
Wim LeersI was wrong, updated #7, this needs tests for sure.
Thanks to @berdir for pointing out my mistake!
Comment #9
Gábor Hojtsyhook_schema_0() is executed from core/lib/Drupal/Core/Extension/UpdateModuleHandler.php with this code:
Views is the only other module that has such a schema. This is applicable to new modules that need to create schemas as part of being installed in an update. See #1929816: Remove all references to/implementations of hook_schema_0() especially comment #2 there.
Comment #10
Gábor HojtsyComment #11
Gábor HojtsyIn, #2074229: Add changed time tracking to taxonomy terms, we figured out this needs to be added to the views integration of the module. Custom blocks don't have views integration for some reason. Instead of adding it all with the changed field, I think this is out of scope for this patch so opened #2077833: Add views integration to custom_block module.
Comment #12
Gábor HojtsyAll right, provided test for creating new blocks as well as same after upgrade path. Also added code to upgrade changed time for existing blocks properly in the upgrade path. Anything else missing?
Comment #13
Gábor HojtsyAfter #2044583: Add EntityChangedInterface to allow entities with "changed" field to be properly cached landed, we should use the EntityChangedInterface here. I think this is complete. Any concerns?
Comment #14
Wim LeersThis is updating an existing hook_update_N() function. Shouldn't we add a new hook_update_N() function for this, just like in #2074229: Add changed time tracking to taxonomy terms?
This should be nonzero, not equal to boolean true. The used assert function sets the wrong expectations.
Why not use
assertNotEqual($block->getChangedTime(), 0)
, just like in #2074229: Add changed time tracking to taxonomy terms?Comment #15
Gábor Hojtsy@WimLeers: we don't yet maintain a head 2 head upgrade path so updating existing update functions is fine, when the code is already there. That was not the case with the taxonomy patch.
I am fine with NotEqual checking as well. Updated patch attached with only that change.
Comment #16
Wim LeersThanks, that makes sense.
For final review, I noticed that the
BlockUpgradePathTest
hunk didn't make a whole lot sense. block.module provides config entity blocks. custom_block.module provides content entity blocks.BlockUpgradePathTest
only covers config entity blocks. And that's fine. But because there is noCustomBlockUpgradePathTest
yet, Gábor was forced to inject additional *content* entity block (i.e. custom block) test coverage toBlockUpgradePathTest
. That doesn't make a lot of sense.Custom block upgrade path test coverage should probably be added in #1871700-73: Provide an upgrade path to the new Block architecture from Drupal 7, but it definitely does not belong here; it's just very confusing.
I also noticed that the added test coverage in
CustomBlockTest
were extremely sparse, just checking for "not equal to zero" is fine for the upgrade path, but not for actual test coverage. So I looked atNodeSaveTest
for inspiration. I added test coverage analogous to whatNodeSaveTest
i.c.w.node_test.module/node_test_node_presave()
does.Comment #17
Gábor HojtsyI think its overkill to add so much test coverage for each column added, but if that makes people happy, so be it.
Comment #18
Gábor HojtsyAnyway, the test coverage looks much better than mine. I think this should be ready to go.
Comment #19
larowlan+1
Comment #20
Dries CreditAttribution: Dries commentedCommitted to 8.x.
Comment #21
Wim Leers.