You are here

public function TaxNumberController::result in Commerce Core 8.2

Displays the verification result for the given tax number.

Parameters

string $tax_number: The tax number.

string $context: The encoded context.

Return value

array A renderable array.

Throws

\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException If the context is invalid or the user doesn't have access to update the parent entity.

1 string reference to 'TaxNumberController::result'
commerce_tax.routing.yml in modules/tax/commerce_tax.routing.yml
modules/tax/commerce_tax.routing.yml

File

modules/tax/src/Controller/TaxNumberController.php, line 117

Class

TaxNumberController

Namespace

Drupal\commerce_tax\Controller

Code

public function result($tax_number, $context) {
  $context = $this
    ->prepareContext($context);
  if (!$context) {
    throw new AccessDeniedHttpException();
  }

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $context['entity'];
  if (!$entity
    ->access('update')) {
    throw new AccessDeniedHttpException();
  }

  /** @var \Drupal\commerce_tax\Plugin\Field\FieldType\TaxNumberItemInterface $field */
  $field = $entity
    ->get('tax_number')
    ->first();
  if ($field->value != $tax_number) {
    throw new AccessDeniedHttpException();
  }
  $result = [];
  $type_plugin = $field
    ->getTypePlugin();
  if ($type_plugin instanceof SupportsVerificationInterface) {
    $verification_result = new VerificationResult($field->verification_state, $field->verification_timestamp, $field->verification_result);
    $result = $type_plugin
      ->renderVerificationResult($verification_result);

    // @todo Move this to a Twig template, to allow it to be customized.
    if ($field->verification_timestamp) {
      $result['timestamp'] = [
        '#type' => 'item',
        '#title' => $this
          ->t('Timestamp'),
        '#plain_text' => $this->dateFormatter
          ->format($field->verification_timestamp, 'long'),
        '#weight' => -10,
      ];
    }
  }
  return $result;
}