You are here

class SiteVerifyService in Site verification 8

Class SiteVerifyService.

@package Drupal\site_verify\Service.

Hierarchy

Expanded class hierarchy of SiteVerifyService

1 string reference to 'SiteVerifyService'
site_verify.services.yml in ./site_verify.services.yml
site_verify.services.yml
1 service uses SiteVerifyService
site_verify_service in ./site_verify.services.yml
Drupal\site_verify\Service\SiteVerifyService

File

src/Service/SiteVerifyService.php, line 12

Namespace

Drupal\site_verify\Service
View source
class SiteVerifyService {

  /**
   * Menu load callback; loads a site verification record.
   *
   * This also loads the engine details if the record was found.
   *
   * @param int $svid
   *   A site verification ID.
   *
   * @return array
   *   An array of the site verification record, or FALSE if not found.
   */
  public function siteVerifyLoad($svid) {
    $record = \Drupal::database()
      ->select('site_verify', 'site_verify')
      ->fields('site_verify')
      ->condition('svid', $svid)
      ->execute()
      ->fetchAssoc();
    if ($record) {
      $record['engine'] = $this
        ->siteVerifyEngineLoad($record['engine']);
    }
    return $record;
  }

  /**
   * Menu load callback; loads engine details.
   *
   * @param string $engine
   *   A string with the engine shortname.
   *
   * @return array
   *   An arary of the engine details, or FALSE if not found.
   */
  public function siteVerifyEngineLoad($engine) {
    $engines = $this
      ->siteVerifyGetEngines();
    return isset($engines[$engine]) ? $engines[$engine] : FALSE;
  }

  /**
   * Fetch an array of supported search engines.
   */
  public function siteVerifyGetEngines() {
    static $engines;
    if (!isset($engines)) {

      // Fetch the list of engines and allow other modules to alter it.
      $engines = \Drupal::moduleHandler()
        ->invokeAll('site_verify_engine_info');
      \Drupal::moduleHandler()
        ->alter('site_verify_engine', $engines);

      // Merge the default values for each engine entry.
      foreach ($engines as $key => $engine) {
        $engines[$key] += [
          'key' => $key,
          'name' => Unicode::ucfirst($engine['name']),
          'file' => FALSE,
          'file_example' => FALSE,
          'file_validate' => [],
          'file_contents' => FALSE,
          'file_contents_example' => FALSE,
          'file_contents_validate' => [],
          'meta' => FALSE,
          'meta_example' => FALSE,
          'meta_validate' => [],
        ];
      }
    }
    return $engines;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SiteVerifyService::siteVerifyEngineLoad public function Menu load callback; loads engine details.
SiteVerifyService::siteVerifyGetEngines public function Fetch an array of supported search engines.
SiteVerifyService::siteVerifyLoad public function Menu load callback; loads a site verification record.