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.
As we've classed entity types now there is no need to pass $type separately, so let's remove it.
Talking of
core/modules/entity/entity.api.php:function hook_entity_presave($entity, $type) {
core/modules/entity/entity.api.php:function hook_entity_insert($entity, $type) {
core/modules/entity/entity.api.php:function hook_entity_update($entity, $type) {
core/modules/entity/entity.api.php:function hook_entity_predelete($entity, $type) {
core/modules/entity/entity.api.php:function hook_entity_delete($entity, $type) {
core/modules/entity/entity.api.php:function hook_entity_view($entity, $type, $view_mode, $langcode) {
Comments
Comment #1
fagoadded tags
Comment #2
aspilicious CreditAttribution: aspilicious commentedCan we merge this with #1618154: add type-hinting for $entity parameter ?
Comment #3
larowlanPatch for this and #1618154: add type-hinting for $entity parameter
Comment #4
aspilicious CreditAttribution: aspilicious commentedThnx for starting this but this needs extra work
In .api.php files we need to declare te full path. EntiInterface should be Drupal\entity\EntityInterface. And we need to define the type after @param. SO that should be: @param Drupal\entity\EntityInterface $entity
Second of all you should grep for "Implement_hook_entity_*" in drupal 8. Replace * with one of the hooks.
You'll find one instance for all in a test file. There you need to add the typehint.
In those classes you can add "use Drupal\entity\EntityInterface" on top of the file and than you can use EntityInterface to typehint.
I hope this makes a bit sense... ;)
14 days to next Drupal core point release.
Comment #5
fgmRerolled accordingly.
Comment #6
aspilicious CreditAttribution: aspilicious commentedWe need to delete the $type if I'm correct :)
Same for the other functions
14 days to next Drupal core point release.
Comment #7
fgmPrevious patch was still missing a few changes.
Comment #8
fgm@aspilicious: indeed, just rerolled for that reason :-)
Comment #9
aspilicious CreditAttribution: aspilicious commentedentity_extract id's is wrong is having incorrect paramaters. But we don't need that here anymore we just can call $entity->id() (or something like that, just check the entity.php class)
same
Same
Same
14 days to next Drupal core point release.
Comment #10
aspilicious CreditAttribution: aspilicious commentedAnd the info stuff looks useless too...
Comment #11
fgmNot exactly the same issue, but close enough to include it.
Comment #12
aspilicious CreditAttribution: aspilicious commentedmmm we have an entity array and we are fetching the type from it... We have to check if it's not empty and use the first entity than... (or just use the first entity as it just an api doc)
14 days to next Drupal core point release.
Comment #13
fgmGood catch. This should be better.
I also added the full signature for Drupal\entity\EntityFieldQuery on hook_entity_query_alter() while changing that file.
Comment #14
aspilicious CreditAttribution: aspilicious commentedentityType
14 days to next Drupal core point release.
Comment #15
fgmCan't even guess why I didn't change that one.
Comment #16
fagoI don't think we want to remove it from the multiple hooks, as it's still useful there in that you don't have to look it up from your passed $entities.
Is that information available in $build? Maybe, let's just pass $entity instead.
Imo, that's a change for the worse. Again, the multiple-issue.
Comment #17
aspilicious CreditAttribution: aspilicious commentedYeah I agree with the above actually...
Comment #18
BerdirThe view alter stuff looks like a duplicate of #1618140: hook_entity_view_alter() misses an $entity parameter, maybe just leave this out in this issue?
Comment #19
fgmRerolled included #1618140: hook_entity_view_alter() misses an $entity parameter and the changes from #16. Tests for comment, entity, node, taxonomy, and user pass locally.
Comment #21
fgm#19: 0001-Issue-1618136-remove-type-and-entity_extract_ids-fro.patch queued for re-testing.
(these 2 errors just do not make sense: they happen outside the test)
Comment #22
fagoOuch.
Also, aspilicious needs to get commit credits for this one as well as he wrote the code taken over from #1618140: hook_entity_view_alter() misses an $entity parameter.
Comment #23
fgmOuch as you say. Rerolled and credit added.
Comment #24
aspilicious CreditAttribution: aspilicious commentedIs rtbc IMO.
Comment #25
fgmRerolled after yesternight's commits, just in case they broke something. Setting to CNR just for bot to check.
Comment #26
Damien Tournoud CreditAttribution: Damien Tournoud commentedI think this is conceptually blocked by #1551140: Remove stub entities, replace entity_create_stub_entity(). During the delete operation, we currently pass a stub of the entity to field hooks. That's not going to work anymore if the stub entities are not classed themselves.
Comment #27
fgm@DamZ: just discussed this with Berdir, and he's saying that since #1551140: Remove stub entities, replace entity_create_stub_entity() only affects the field hook, and this only affects the entity CRUD hooks, it shouldn't be a blocker.
Comment #28
Damien Tournoud CreditAttribution: Damien Tournoud commentedTalking with @berdir, we are not actually blocked here, because we load the entity everywhere, including in delete.
Looking at the patch, it seems to be missing updates to the documentation:
We modify the entity-type specific hook signature without updating its API documentation (true for all entity types in core).
Comment #29
fgmRerolled accordingly.
Comment #30
fgmresetting to rtbc as per #24.
Comment #31
fagooh, still the additions need review before it can go to RTBC again. So here it is:
We do type-hinting on the Comment class in that case, see the other comment specific hooks. The same issue applies to the other entity types as well.
Comment #32
fgmAnd here they are.
Comment #33
fagoSomehow a whitespace made it in here?
Comment #34
fgmCannot guess how this even happens.
Comment #35
fagoThat happens .. ;)
When looking at it for once another I've found another remark, this should be $account as it is for all the user hooks for consistency.
Comment #36
fgmSomeday we'll get rid of global $user
Comment #37
fagoThanks, looks good now! :-)
As mentioned in #22 aspilicious needs to get commit credits for this one as well as he wrote the code taken over from #1618140: hook_entity_view_alter() misses an $entity parameter.
Also, this will need a change notice.
Comment #38
fgmProspective change notice created at http://drupal.org/node/1637540
Comment #39
webchickSo we had a discussion about this:
That looks bloody awful from a "newish to Drupal 8" perspective, but OTOH this is the current standard, so it's correct. The reason we do that is so you can copy/paste these implementations into your module without having to also figure out where the class comes from and toss the namespace at the top of your file. However, not the fault of this patch, and I'm actually reasonably sure I was one of the people advocating for this originally so.. ;P
Committed and pushed to 8.x. Thanks! :)
Comment #40
webchickAlso reviewed the change notice and it looks great. :)
Comment #41
webchickComment #42
sunStray $type variable, which should be removed.
Comment #43
aspilicious CreditAttribution: aspilicious commentedOw we forgot to remove
$type = 'node';
Comment #44
fgmYup.
Comment #45
BerdirSimple enough, RTBC unless the testbot disagrees, and I don't think he will ;)
Comment #46
webchickCommitted and pushed to 8.x. Thanks for the catch. :)
Comment #48
fagoRemoving sprint tag.