You are here

function xmlsitemap_get_link_type_indexed_status in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 xmlsitemap.module \xmlsitemap_get_link_type_indexed_status()
  2. 6.2 xmlsitemap.module \xmlsitemap_get_link_type_indexed_status()
  3. 7.2 xmlsitemap.module \xmlsitemap_get_link_type_indexed_status()

Returns statistics about specific entity links.

Parameters

string $entity_type_id: Entity type id.

string $bundle: Bundle id.

Return value

array Array with statistics.

1 call to xmlsitemap_get_link_type_indexed_status()
xmlsitemap_add_form_entity_summary in ./xmlsitemap.module
Add a table summary for an entity and its bundles.

File

./xmlsitemap.module, line 830
xmlsitemap XML sitemap

Code

function xmlsitemap_get_link_type_indexed_status($entity_type_id, $bundle = '') {
  $info = xmlsitemap_get_link_info($entity_type_id);
  $database = \Drupal::database();
  $entity_type = \Drupal::entityTypeManager()
    ->getDefinition($entity_type_id);
  $status['indexed'] = $database
    ->query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle", [
    ':entity' => $entity_type_id,
    ':bundle' => $bundle,
  ])
    ->fetchField();
  $status['visible'] = $database
    ->query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle AND status = 1 AND access = 1", [
    ':entity' => $entity_type_id,
    ':bundle' => $bundle,
  ])
    ->fetchField();
  try {
    $query = \Drupal::entityQuery($entity_type_id);
    if ($bundle && $entity_type
      ->hasKey('bundle')) {
      $query
        ->condition($entity_type
        ->getKey('bundle'), $bundle);
    }

    // We are only using this for totals, so we can skip the access check.
    $query
      ->accessCheck(FALSE);
    $query
      ->addTag('xmlsitemap_link_indexed_status');
    $status['total'] = $query
      ->count()
      ->execute();
    return $status;
  } catch (\Exception $e) {
    $status['total'] = 0;
  }
  return $status;
}