You are here

function yoast_seo_configuration_load_multiple in Real-time SEO for Drupal 7

Load SEO info for multiple entities.

Parameters

string $entity_type: The entity type to load.

array $entity_ids: The list of entity IDs.

Return value

array An array of SEO info data, keyed by entity ID, revision ID and language.

2 calls to yoast_seo_configuration_load_multiple()
yoast_seo_configuration_load in ./yoast_seo.module
Load an entity's SEO info.
yoast_seo_entity_load in ./yoast_seo.module
Implements hook_entity_load().

File

./yoast_seo.module, line 566
Primary hook implementations for Yoast SEO for Drupal module.

Code

function yoast_seo_configuration_load_multiple($entity_type, array $entity_ids, array $revision_ids = array()) {

  // Double check entity IDs are numeric thanks to Entity API module.
  $entity_ids = array_filter($entity_ids, 'is_numeric');
  if (empty($entity_ids)) {
    return array();
  }

  // Also need to check if the Yoast SEO table exists since this condition could
  // fire before the table has been installed yet.
  if (!db_table_exists('yoast_seo')) {
    watchdog('yoast_seo', 'The system tried to load Real-time SEO for Drupal data before the schema was fully loaded.', array(), WATCHDOG_WARNING);
    return array();
  }

  // Get all translations of data for this entity.
  $query = db_select('yoast_seo', 'y')
    ->fields('y', array(
    'entity_id',
    'revision_id',
    'language',
    'focus_keyword',
    'seo_status',
  ))
    ->condition('y.entity_type', $entity_type)
    ->orderBy('entity_id')
    ->orderBy('revision_id');

  // Filter by revision_ids if they are available. If not, filter by entity_ids.
  if (!empty($revision_ids)) {
    $query
      ->condition('y.revision_id', $revision_ids, 'IN');
  }
  else {
    $query
      ->condition('y.entity_id', $entity_ids, 'IN');
  }
  $result = $query
    ->execute();

  // Marshal it into an array keyed by entity ID. Each value is an array of
  // translations keyed by language code.
  $seo_info = array();
  while ($record = $result
    ->fetchObject()) {
    $data = array(
      'focus_keyword' => $record->focus_keyword,
      'seo_status' => $record->seo_status,
    );
    $seo_info[$record->entity_id][$record->revision_id][$record->language] = $data;
  }
  return $seo_info;
}