You are here

public function TaxNumberItem::checkValue in Commerce Core 8.2

Checks whether the current value can be used for tax calculation.

Confirms that:

  • The type is correct.
  • The number is not empty.
  • The number has been verified, or that unverified numbers are allowed when hen the verification web service is unavailable. This check is skipped if the type does not support verification.

Parameters

string $expected_type: The expected tax number type.

Return value

bool TRUE if the current value can be used, FALSE otherwise.

Overrides TaxNumberItemInterface::checkValue

File

modules/tax/src/Plugin/Field/FieldType/TaxNumberItem.php, line 247

Class

TaxNumberItem
Plugin implementation of the 'commerce_tax_number' field type.

Namespace

Drupal\commerce_tax\Plugin\Field\FieldType

Code

public function checkValue($expected_type) {
  if ($this
    ->isEmpty() || $this->type != $expected_type) {
    return FALSE;
  }
  if ($this
    ->getTypePlugin() instanceof SupportsVerificationInterface) {
    $verification_state = $this->verification_state;
    if ($verification_state == VerificationResult::STATE_UNKNOWN) {
      return $this
        ->getSetting('allow_unverified');
    }
    else {
      return $verification_state == VerificationResult::STATE_SUCCESS;
    }
  }
  else {
    return TRUE;
  }
}