public function SiteAuditCheckContentFieldInstances::calculateScore in Site Audit 8.2
Same name and namespace in other branches
- 7 Check/Content/FieldInstances.php \SiteAuditCheckContentFieldInstances::calculateScore()
Implements \SiteAudit\Check\Abstract\calculateScore().
Overrides SiteAuditCheckAbstract::calculateScore
File
- Check/
Content/ FieldInstances.php, line 95 - Contains \SiteAudit\Check\Content\FieldInstances.
Class
- SiteAuditCheckContentFieldInstances
- Class SiteAuditCheckContentFieldInstances.
Code
public function calculateScore() {
$entity_manager = \Drupal::entityManager();
$map = $entity_manager
->getFieldMap();
$this->registry['field_instance_counts'] = array();
foreach ($map as $entity => $fields) {
$bundle_column_name = $entity_manager
->getDefinition($entity)
->getKey('bundle');
foreach ($fields as $field => $description) {
if (!in_array($field, array_keys($this->registry['fields']))) {
continue;
}
foreach ($description['bundles'] as $bundle) {
$query = \Drupal::entityQuery($entity);
if (!empty($bundle_column_name)) {
$query
->condition($bundle_column_name, $bundle);
}
$query
->exists($field)
->count();
$field_count = $query
->execute();
$this->registry['field_instance_counts'][$bundle][$entity][$field] = $field_count;
}
}
}
return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO;
}