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
Move hook_field_extra_fields() to the entity API.
Proposed resolution
Move hook_field_extra_fields()
to entity.api.php, renamed tohook_entity_extra_field_info()
.Move hook_field_extra_fields_alter()
to entity.api.php, renamed tohook_entity_extra_field_info_alter()
.- Move
FieldInfo::getBundleExtraFields()
toEntityManagerInterface::getBundleExtraFields()
- Deprecate
field_info_extra_fields()
Remaining tasks
None.
User interface changes
None.
API changes
The minor changes as mentioned above.
Comment | File | Size | Author |
---|---|---|---|
#31 | interdiff.txt | 1011 bytes | Xano |
#31 | drupal_2225629_30.patch | 28.53 KB | Xano |
Comments
Comment #1
XanoComment #2
ianthomas_ukWhen do we plan to remove this? We should say either
@deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
or
@deprecated in Drupal 8.0, will be removed in Drupal 9.0.
Also, that method name doesn't look right.
Comment #4
XanoSharp!
It will be removed in #2167167: Remove field_info_*().
Comment #5
BerdirLet's just use the existing cache backend.
No need for Bundle here imho, we also have getFieldDefinitions() and not getBundleFieldDefinitions().
This should be something like entity_bundle_extra_fields:...
I'm not sure that note is necessary, no idea what other way there should be.
Wondering if the hook name should be entity_extra_field_info(), for consistenty with base_field_info() and bundle_field_info() ?
Same here, let's make this part of the entity_field_info cache tag.
Comment #6
XanoAll done.
Comment #8
BerdirI guess this was only used for the removed test and as that now uses unit tests, we no longer need it?
Comment #9
XanoYup. It's not available to live sites and the removal did not break any other tests.
Comment #10
ianthomas_ukIn that case, the comment should read
@deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
Comment #11
XanoComment #14
XanoToo hurried for an interdiff.
Comment #16
XanoComment #17
XanoComment #18
fagoThanks, patch looks good. Here some remarks:
field definitions are cached with a cid using entityType:bundle:langcode - so shouldn't we follow that?
Should be $entity_type_id - and the description as well accordingly.
on content entities.
Content entities
by the entity display form now, but I guess it's enough to say "by the entity form controller".
@param array $info
Comment #19
XanoComment #20
fagoThanks, changes look good except for the following.
Misses one space indentation.
Also, I'm wondering where one can clear the extra field cache? Is this missing now? -> Needs work.
Comment #21
BerdirThought I commented already. You can clear the cache through clearCachedFieldDefinitions(), through the cache tag.
Comment #22
XanoComment #23
xjmBeta-blocking as a blocker for #2116363: Unified repository of field definitions (cache + API).
Comment #24
BerdirThis is still in it?
Also, @fago correctly pointed out that while we clear the persistent cache, we need to unset the "static" static aka property in the mentioned clearCachedDefinitions() method.
Comment #25
ianthomas_ukI've updated the issue summary with the current function names. This will need a change record (or an update to an existing one).
If we're dropping 'bundle' from the method name, we should also drop it from the variable name.
Do we still want to change this if we're not using a separate field cache?
Why not $language = new Language(array('id' => $language_code));?
Not that it makes much difference if $langauge_code = 'en' anyway. I'm not very experienced with automated tests, but the new test doesn't seem to check the same things as testFieldInfoExtraFieldsTranslation(). Do we need more tests if we're going to remove that?
Comment #26
ianthomas_ukComment #27
XanoYes, as that is used by different tests. You are referring to
field_test_field_extra_fields()
, which has indeed been removed.Done.
Done.
Done.
Because it's a trivial code style issue and I like my way ;-) This is also much more similar to what #1512424: Add a LanguageInterface, and property setters/getters to Language class introduces.
We don't, because the new test does cover translatability.
Comment #28
xjmComment #29
fagoThis looks ready to me, I just found the following minor remarks:
title is a bad example, it's not an extra field any more. So maybe we could copy over a different code example as well.
content entities
Comment #30
ianthomas_ukPassing it in the constructor means $name and $direction will be set to the correct values. Not that it really matters for this test, because they are being set to the same values anyway and are not being read.
Comment #31
XanoComment #32
fagoThanks! This was green already, so RTBC given it will be again.
Comment #33
alexpottWhere do we test translatability here? We have no assertions or expectation set that a translated label is returned in the new test.
Comment #34
XanoOkay, we don't actually test translatability, because there is no translatability. The hook implementations may return different values per language, which is why we cache them per language and *that* is tested.
Comment #35
XanoComment #36
XanoAdded a change notice.
Comment #37
Berdir+1 to getting this in as it is.
I did a quick change and the old test coverage is actually bogus and does *not* verify what it should. You can remove the $langcode from the cache cid and it still passes, because it only calls the method for one language.
That's the only thing this has been written to test, all the other like adding a language and a translation was only necessary because it's the only way to detect if there is a different string in there. Not because we want to test that the string is translatable.
The new test coverage verifies that the correct cache key with the language code is used. We could even go a step further and call it again and then return a different langcode and verify that the hook is called again.
Comment #38
andypost+! to RTBC, also this needs follow-up to clean-up old tests
Comment #39
alexpottCommitted fee6ae0 and pushed to 8.x. Thanks!