You are here

function xmlsitemap_add_form_entity_summary in XML sitemap 2.x

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

Add a table summary for an entity and its bundles.

Parameters

array $form: Form array.

string $entity: Entity type id.

array $entity_info: Info about the entity type.

1 call to xmlsitemap_add_form_entity_summary()
XmlSitemapSettingsForm::buildForm in src/Form/XmlSitemapSettingsForm.php
Form constructor.

File

./xmlsitemap.module, line 2013
xmlsitemap XML sitemap

Code

function xmlsitemap_add_form_entity_summary(array &$form, $entity, array $entity_info) {
  $priorities = xmlsitemap_get_priority_options(NULL, FALSE);
  $statuses = xmlsitemap_get_status_options(NULL);
  $rows = [];
  $totals = [
    'total' => 0,
    'indexed' => 0,
    'visible' => 0,
  ];
  foreach ($entity_info['bundles'] as $bundle => $bundle_info) {

    // Fetch current per-bundle link total and indexed counts.
    if (!xmlsitemap_link_bundle_check_enabled($entity, $bundle)) {
      continue;
    }
    $status = xmlsitemap_get_link_type_indexed_status($entity, $bundle);
    $totals['total'] += $status['total'];
    $totals['indexed'] += $status['indexed'];
    $totals['visible'] += $status['visible'];
    $rows[] = [
      Link::createFromRoute($bundle_info['label'], 'xmlsitemap.admin_settings_bundle', [
        'entity' => $entity,
        'bundle' => $bundle,
      ]),
      $statuses[$bundle_info['xmlsitemap']['status'] ? 1 : 0],
      $priorities[number_format($bundle_info['xmlsitemap']['priority'], 1)],
      $status['total'],
      $status['indexed'],
      $status['visible'],
    ];
  }
  if ($rows) {
    $header = [
      isset($entity_info['bundle label']) ? $entity_info['bundle label'] : '',
      t('Inclusion'),
      t('Priority'),
      t('Available'),
      t('Indexed'),
      t('Visible'),
    ];
    $rows[] = [
      [
        'data' => t('Totals'),
        'colspan' => 3,
        'header' => TRUE,
      ],
      [
        'data' => $totals['total'],
        'header' => TRUE,
      ],
      [
        'data' => $totals['indexed'],
        'header' => TRUE,
      ],
      [
        'data' => $totals['visible'],
        'header' => TRUE,
      ],
    ];
    $form['summary'] = [
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $rows,
    ];
  }
}