You are here

Count.php in Site Audit 8.2

Same filename in this branch
  1. 8.2 Check/Extensions/Count.php
  2. 8.2 Check/Watchdog/Count.php
  3. 8.2 Check/Views/Count.php
Same filename and directory in other branches
  1. 7 Check/Views/Count.php

Contains \SiteAudit\Check\Views\Count.

File

Check/Views/Count.php
View source
<?php

/**
 * @file
 * Contains \SiteAudit\Check\Views\Count.
 */
use Drupal\views\Views;

/**
 * Class SiteAuditCheckViewsCount.
 */
class SiteAuditCheckViewsCount extends SiteAuditCheckAbstract {

  /**
   * Implements \SiteAudit\Check\Abstract\getLabel().
   */
  public function getLabel() {
    return dt('Count');
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getDescription().
   */
  public function getDescription() {
    return dt('Number of enabled Views.');
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultFail().
   */
  public function getResultFail() {
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultInfo().
   */
  public function getResultInfo() {
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultPass().
   */
  public function getResultPass() {
    $views_count = count($this->registry['views']);
    if (!$views_count) {
      return dt('There are no enabled views.');
    }
    return dt('There are @count_views enabled views.', array(
      '@count_views' => count($this->registry['views']),
    ));
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultWarn().
   */
  public function getResultWarn() {
    return $this
      ->getResultPass();
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getAction().
   */
  public function getAction() {
    if ($this->score == SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN) {
      return dt('Consider disabling the views module if you don\'t need it.');
    }
  }

  /**
   * Implements \SiteAudit\Check\Abstract\calculateScore().
   */
  public function calculateScore() {
    $this->registry['views'] = Views::getEnabledViews();
    if (empty($this->registry['views'])) {
      $this->abort = TRUE;
      return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN;
    }
    return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS;
  }

}

Classes

Namesort descending Description
SiteAuditCheckViewsCount Class SiteAuditCheckViewsCount.