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.
The call to entity_language($entity_type, $entity) on a hook_field_access() throws fatal errors for some fields. This occurs because the call $langcode = $handler->getFormLanguage(); is not securely wrapped for avoid non object method calls.
// This function leaves on entity_translation.module
function entity_translation_language($entity_type, $entity) {
$handler = entity_translation_get_handler($entity_type, $entity);
$langcode = $handler->getFormLanguage();
return !empty($langcode) ? $langcode : $handler->getLanguage();
}
The following changes avoid this problem.
// This function leaves on entity_translation.module
function entity_translation_language($entity_type, $entity) {
$handler = entity_translation_get_handler($entity_type, $entity);
if (empty($handler)) {
return LANGUAGE_NONE;
}
$langcode = $handler->getFormLanguage();
return !empty($langcode) ? $langcode : $handler->getLanguage();
}
Comment | File | Size | Author |
---|---|---|---|
#2 | entity_translation-getFormLanguage_on_a_non_object-2648062-2.patch | 554 bytes | brunoric |
|
Comments
Comment #2
brunoric CreditAttribution: brunoric at CI&T commentedThe changes on issue description follows as a patch.
Comment #3
brunoric CreditAttribution: brunoric at CI&T commentedComment #4
brunoric CreditAttribution: brunoric at CI&T commentedComment #5
Anonymous (not verified) CreditAttribution: Anonymous at CI&T commentedIt's working for me.
Comment #6
cebasqueira CreditAttribution: cebasqueira at CI&T commentedWorks!!!!
Comment #7
brunoric CreditAttribution: brunoric at CI&T commentedComment #8
mmchristoph CreditAttribution: mmchristoph commentedPerfect!
Comment #10
plachCommitted and pushed, thanks!