Skip to content
Snippets Groups Projects
Commit efbf061c authored by Angie Byron's avatar Angie Byron
Browse files

#852522 by catch: Optimize file_field_load() to load filefields on all entities at once.

parent 4f28649f
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -208,16 +208,19 @@ function _file_generic_settings_file_directory_validate($element, &$form_state)
* Implements hook_field_load().
*/
function file_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
$fids = array();
foreach ($entities as $id => $entity) {
// Load the files from the files table.
$fids = array();
foreach ($items[$id] as $delta => $item) {
if (!empty($item['fid'])) {
$fids[] = $item['fid'];
}
}
$files = file_load_multiple($fids);
}
$files = file_load_multiple($fids);
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => $item) {
// If the file does not exist, mark the entire item as empty.
if (empty($item['fid']) || !isset($files[$item['fid']])) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment