You are here

public static function QuailApiSettings::get_validation_methods in Quail API 8

Returns an array of validation methods that are supported.

A validation method is how the validation process is to be performed. Examples are:

  • performing the validation everytime a page is viewed
  • performing the validation only when a validate button is checked

This is mostly information. Extending modules are expected to provide the functionality that utilizes this data.

Parameters

string|null $validation_method: (optional) A machine name representing of the validation method. When defined, the return value to only contain the validation method that matches the given id. When undefined, all validation methods will be loaded into the validation_method array.

Return value

array An array of validation methods that are supported by this module or extending modules. The array keys are the machine names for each display level.

1 call to QuailApiSettings::get_validation_methods()
QuailApiSettings::get_validation_methods_list in src/QuailApiSettings.php
Returns a list of validation methods.

File

src/QuailApiSettings.php, line 387

Class

QuailApiSettings
Class QuailApiSettings.

Namespace

Drupal\quail_api

Code

public static function get_validation_methods($validation_method = NULL) {
  $validation_methods =& drupal_static('quail_api_' . __FUNCTION__, NULL);
  if (!isset($validation_methods)) {
    if ($cache = \Drupal::cache()
      ->get('quail_api_validation_methods')) {
      $validation_methods = $cache->data;
    }
    else {
      \Drupal::moduleHandler()
        ->alter('quail_api_validation_methods', $validation_methods, $validation_method);
    }
  }
  if (isset($validation_methods)) {
    if (!is_null($validation_method)) {
      if (isset($validation_methods[$validation_method])) {
        return $validation_methods[$validation_method];
      }
      return [];
    }
    return $validation_methods;
  }
  $validation_methods = [];
  $validation_methods['quail_api_method_immediate'] = [
    'human_name' => t("Immediately Validate"),
    'module' => 'quail_api',
    'description' => t("Always perform the validation. Validation results are never saved."),
    'database' => FALSE,
    'automatic' => TRUE,
  ];
  $validation_methods['quail_api_method_manual'] = [
    'human_name' => t("Manually Validate"),
    'module' => 'quail_api',
    'description' => t("Perform the validation only when requested. Validation results are never saved."),
    'database' => FALSE,
    'automatic' => FALSE,
  ];
  $validation_methods['quail_api_method_immediate_database'] = [
    'human_name' => t("Immediately Validate & Save"),
    'module' => 'quail_api',
    'description' => t("Always perform the validation. Validation results are stored in the database."),
    'database' => TRUE,
    'automatic' => TRUE,
  ];
  $validation_methods['quail_api_method_manual_database'] = [
    'human_name' => t("Manually Validate & Save"),
    'module' => 'quail_api',
    'description' => t("Perform the validation only when requested. Validation results are stored in the database."),
    'database' => TRUE,
    'automatic' => FALSE,
  ];
  \Drupal::cache()
    ->set('quail_api_validation_methods', $validation_methods);
  if (!is_null($validation_method)) {
    if (isset($validation_methods[$validation_method])) {
      return $validation_methods[$validation_method];
    }
    return [];
  }
  return $validation_methods;
}