From e8c595c47de3e0b5f2405efdd2ffc8c8dae12514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Dehorter?= Date: Thu, 24 Aug 2017 18:53:32 +0200 Subject: [PATCH] field-item-collection-hostentity-2774369-9.patch --- file_entity.pages.inc | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/file_entity.pages.inc b/file_entity.pages.inc index c4f9005..5ca89ed 100644 --- a/file_entity.pages.inc +++ b/file_entity.pages.inc @@ -258,7 +258,8 @@ function file_entity_add_upload_step_fields($form, &$form_state, array $options function file_entity_usage_page($file) { $rows = array(); $occured_entities = array(); - + $parent = new stdClass(); + // Determine all of the locations where a file is used, then loop through the // occurrences and filter out any duplicates. foreach (file_usage_list($file) as $module => $type) { @@ -268,6 +269,24 @@ function file_entity_usage_page($file) { $entity_info = entity_get_info($entity_type); $entities = empty($entity_info) ? NULL : entity_load($entity_type, array_keys($entity_ids)); + /** + * If $entities are field collection, check parent informations instead field collection informations + * Only last revision + * To do : All revisions + */ + $parent_informations = array(); + + if($entity_type == 'field_collection_item') { + foreach ($entities as $entity) { + $parent_informations[$entity->item_id] = db_select('field_revision_' . $entity->field_name, 'pi') + ->fields('pi') + ->condition($entity->field_name . '_value', $entity->item_id, '=') + ->condition($entity->field_name . '_revision_id', $entity->revision_id, '=') + ->execute() + ->fetchAssoc(); + } + } + foreach ($entity_ids as $entity_id => $count) { // If this entity has already been listed in the table, just add any // additional usage to the total count column in the table row and @@ -280,16 +299,35 @@ function file_entity_usage_page($file) { // Retrieve the label and the URI of the entity. $label = empty($entities[$entity_id]) ? $module : entity_label($entity_type, $entities[$entity_id]); $entity_uri = empty($entities[$entity_id]) ? NULL : entity_uri($entity_type, $entities[$entity_id]); + + // Get parent label. + if (!empty($parent_informations)) { + $parent = empty($parent_informations[$entity_id]['revision_id']) ? + entity_load($parent_informations[$entity_id]['entity_type'], array($parent_informations[$entity_id]['entity_id'])) : + entity_revision_load($parent_informations[$entity_id]['entity_type'], array($parent_informations[$entity_id]['revision_id'])); + + $parent_label = entity_label($parent_informations[$entity_id]['entity_type'], $parent); + } - // Link the label to the URI when possible. + /** + * Link the label to the URI when possible. + * Link parents label to the parents URI for field_collection_item entity + * Add entity status to label + * Modify entity type to add parent type + */ if (!empty($entity_uri['path'])) { - $entity_label = l($label, $entity_uri['path']); + $entity_status = $entities[$entity_id]->status == 0 ? t('Unpublished') : t('Published'); + $parent_status = $parent->status == 0 ? t('Unpublished') : t('Published'); + + $entity_label = empty($parent_informations[$entity_id]['revision_id']) ? + l($label, $entity_uri['path']) . ' (' . $entity_status . ')' : + l($parent_label, $parent->path['source']) . ' (' . $parent_status . ')'; } else { $entity_label = check_plain($label); } - - $rows[] = array($entity_label, $entity_type, $count); + + $rows[] = array($entity_label, empty($parent_informations[$entity_id]['entity_type']) ? $entity_type : $parent_informations[$entity_id]['entity_type'] . ' (' . $entity_type . ')', $count); // Record the occurrence of the entity to ensure that it isn't listed in // the table again. -- 1.9.1