diff --git a/metatag.module b/metatag.module index 4c04992..e60d976 100644 --- a/metatag.module +++ b/metatag.module @@ -601,20 +601,25 @@ function metatag_metatags_cache_clear($entity_type, $entity_ids = NULL) { function metatag_entity_load($entities, $entity_type) { // Get the revision_ids. $revision_ids = array(); + + // 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); - $revision_id = intval($revision_id); - if (!empty($revision_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; } } - // 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)) { + // Don't proceed if there are no revision_ids. + 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); - // Assign the metatag records for the correct revision ID. foreach ($entities as $entity_id => $records) { list($entity_id, $revision_id) = entity_extract_ids($entity_type, $entity); @@ -622,16 +627,16 @@ function metatag_entity_load($entities, $entity_type) { $entities[$entity_id]->metatags = isset($metatags[$entity_id][$revision_id]) ? $metatags[$entity_id][$revision_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 (drupal_is_cli()) { - drupal_set_message(t('Run your updates, like drush updb.')); - } - // Only message people who can see it in watchdog and can likely fix it. - elseif (user_access('access site reports')) { - 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 (drupal_is_cli()) { + drupal_set_message(t('The database updates need to be run: drush upatedb')); + } + // Only message people who can see it in watchdog and can likely fix it. + elseif (user_access('access site reports')) { + drupal_set_message(t('Error loading meta tag data, do the database updates need to be run?', array('@update' => base_path() . 'update.php')), 'error'); + } } } }