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.
I get the following PHP notices when deleting files using file_delete():
Warning: array_fill() [function.array-fill]: Number of elements must be positive in EntityTranslationDefaultHandler->removeTranslation() (line 460 of sites/all/modules/entity_translation/includes/translation.handler.inc).
Warning: array_combine() expects parameter 2 to be array, boolean given in EntityTranslationDefaultHandler->removeTranslation() (line 462 of sites/all/modules/entity_translation/includes/translation.handler.inc).
Comment | File | Size | Author |
---|---|---|---|
#8 | et-undefined_translations-1728648-8.patch | 1.96 KB | plach |
#6 | et-undefined_translations-1728648-6.patch | 1.46 KB | plach |
#2 | 1728648-php-notice-empty-translations.patch | 708 bytes | Dave Reid |
Comments
Comment #1
Dave ReidFiles in question had no entity_translation data, which is a common occurrence.
Comment #2
Dave ReidPatch provided which at least to me fixes the issue without any harm.
Comment #3
Dave ReidThe alternative would be to do this:
But it seems pointless to execute the else statement if the translation 'data' array is empty.
Comment #4
plachThanks, the patch in itself looks good but it's a bit weird that the data field is not defined, see EntityTranslationDefaultHandler::loadMultiple(). Does that happen with a new entity?
Comment #5
plachActually I'm wondering whether it would make more sense to ensure that translations are defined when setting the wrapped entity in the translation handler.
Comment #6
plachDoes this fix the issue?
Comment #7
Dave ReidNo. $file->translations does exist, it's just $file->translations['data'] is an empty array because it has no data (entity created prior to entity_translation). The problem is array_fill cannot be called to generate an empty array.
Comment #8
plachAh ok, let's combine the two patches then.
Comment #9
plachCommitted and pushed, thanks.
Comment #10
Dave ReidHrm, I'm just not seeing that the code from #6 is even necessary, but I guess it can't hurt. For reference, this is the debug() output of a file from file_load() that has no entity translation records:
Comment #11
plachOK, that looks fine. The code in #6 is to account for situations where one creates an entity and wraps it in a translation handler before saving it for the first time.