diff --git a/metatag.module b/metatag.module index f53ed0d..2a345d2 100644 --- a/metatag.module +++ b/metatag.module @@ -547,31 +547,34 @@ function metatag_metatags_cache_clear($entity_type, $entity_id = NULL) { * Implements hook_entity_load(). */ function metatag_entity_load($entities, $entity_type) { - // get the revision_ids + // Get the revision_ids. $revision_ids = array(); - //since some entities do not have revisions, set the vid to the id + // Since some entities do not have revisions, set the vid to the id. foreach ($entities as $key => $entity) { - list($entity_id, $revision_id) = entity_extract_ids($entity_type, $entity); - if (!$revision_id) { - $revision_id = $entity_id; + list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity); + // Verify that each entity bundle supports Metatag. + if (metatag_entity_supports_metatags($entity_type, $bundle)) { + if (empty($revision_id)) { + $revision_id = $entity_id; + } + $revision_ids[] = $revision_id; } - $revision_ids[] = $revision_id; } - // Wrap this in a try-catch block to work around occasions when the schema - // hasn't been updated yet. - try { - if (metatag_entity_supports_metatags($entity_type)) { + if (!empty($revision_ids)) { + // Wrap this in a try-catch block to work around occasions when the schema + // hasn't been updated yet. + try { $metatags = metatag_metatags_load_multiple($entity_type, array_keys($entities), $revision_ids); foreach ($entities as $entity_id => $entity) { $entities[$entity_id]->metatags = isset($metatags[$entity_id]) ? $metatags[$entity_id] : array(); } } - } - catch (Exception $e) { - watchdog('metatag', 'Error loading meta tag data, do the database updates need to be run? The error occurred when loading record(s) %ids for the %type entity type. The error message was: %error', array('@update' => base_path() . 'update.php', '%ids' => implode(', ', array_keys($entities)), '%type' => $entity_type, '%error' => $e->getMessage()), WATCHDOG_CRITICAL); - // Don't display the same message twice for Drush. - if (php_sapi_name() != 'cli') { - drupal_set_message(t('Error loading meta tag data, do the database updates need to be run?', array('@update' => base_path() . 'update.php')), 'error'); + catch (Exception $e) { + watchdog('metatag', 'Error loading meta tag data, do the database updates need to be run? The error occurred when loading record(s) %ids for the %type entity type. The error message was: %error', array('@update' => base_path() . 'update.php', '%ids' => implode(', ', array_keys($entities)), '%type' => $entity_type, '%error' => $e->getMessage()), WATCHDOG_CRITICAL); + // Don't display the same message twice for Drush. + if (php_sapi_name() != 'cli') { + drupal_set_message(t('Error loading meta tag data, do the database updates need to be run?', array('@update' => base_path() . 'update.php')), 'error'); + } } } }