You are here

public function SiteAuditCheckContentContentEntityTypes::calculateScore in Site Audit 8.2

Implements \SiteAudit\Check\Abstract\calculateScore().

Overrides SiteAuditCheckAbstract::calculateScore

File

Check/Content/ContentEntityTypes.php, line 98
Contains \SiteAudit\Check\Content\ContentTypes.

Class

SiteAuditCheckContentContentEntityTypes
Class SiteAuditCheckContentContentEntityTypes.

Code

public function calculateScore() {
  $entity_manager = \Drupal::entityManager();
  $all_bundles = $entity_manager
    ->getAllBundleInfo();
  foreach ($all_bundles as $entity_type => $bundles) {
    $bundle_column_name = $entity_manager
      ->getDefinition($entity_type)
      ->getKey('bundle');
    $interfaces = class_implements($entity_manager
      ->getDefinition($entity_type)
      ->getClass());
    if ($bundle_column_name != FALSE && in_array("Drupal\\Core\\Entity\\ContentEntityInterface", $interfaces)) {
      $this->registry['entity_count'][$entity_type] = 0;
      foreach ($bundles as $bundle => $info) {
        if (get_class($entity_manager
          ->getStorage($entity_type)) != 'Drupal\\Core\\Entity\\ContentEntityNullStorage') {
          $query = \Drupal::entityQuery($entity_type)
            ->condition($bundle_column_name, $bundle)
            ->count();
          $field_count = $query
            ->execute();
          $label = $info['label'];
          if (is_object($label)) {
            $label = (string) $label;
          }
          $this->registry['content_entity_type_counts'][$entity_type][$label] = $field_count;
          $this->registry['entity_count'][$entity_type] += $field_count;
          if ($field_count == 0) {
            $this->registry['content_types_unused'][$entity_type][] = $info['label'];
          }
        }
      }
    }
  }
  return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO;
}