ContentFieldsUnused.php in Site Audit 8.3
File
src/Plugin/SiteAuditCheck/ContentFieldsUnused.php
View source
<?php
namespace Drupal\site_audit\Plugin\SiteAuditCheck;
use Drupal\site_audit\Plugin\SiteAuditCheckBase;
class ContentFieldsUnused extends SiteAuditCheckBase {
public function getResultFail() {
}
public function getResultInfo() {
return $this
->t('There are no unused fields.');
}
public function getResultPass() {
}
public function getResultWarn() {
$report = [];
foreach ($this->registry->fields_unused as $bundle_name => $fields) {
$report[] = $bundle_name .= ': ' . implode(', ', $fields);
}
return $this
->t('The following fields are unused: @report', [
'@report' => implode('; ', $report),
]);
}
public function getAction() {
if ($this
->getScore() == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) {
return $this
->t('Consider removing unused fields.');
}
}
public function calculateScore() {
$this->registry->fields_unused = [];
foreach ($this->registry->field_instance_counts as $bundle_name => $entity_types) {
foreach ($entity_types as $entity_type => $fields) {
foreach ($fields as $field_name => $count) {
if (!$count) {
$this->registry->fields_unused[$entity_type . '-' . $bundle_name][] = $field_name;
}
}
}
}
if (!empty($this->registry->fields_unused)) {
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN;
}
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO;
}
}