You are here

class UuidConverter in Email confirmer 8

Email confirmation UUID param converter.

Hierarchy

Expanded class hierarchy of UuidConverter

1 string reference to 'UuidConverter'
email_confirmer.services.yml in ./email_confirmer.services.yml
email_confirmer.services.yml
1 service uses UuidConverter
email_confirmer.confirmation_uuid_param_converter in ./email_confirmer.services.yml
Drupal\email_confirmer\ParamConverter\UuidConverter

File

src/ParamConverter/UuidConverter.php, line 13

Namespace

Drupal\email_confirmer\ParamConverter
View source
class UuidConverter implements ParamConverterInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Construct an email confirmation UUID param converter.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    $confirmation = NULL;
    if (Uuid::isValid($value) && ($storage = $this->entityTypeManager
      ->getStorage('email_confirmer_confirmation'))) {
      $entities = $storage
        ->loadByProperties([
        'uuid' => $value,
      ]);
      $confirmation = $entities ? reset($entities) : NULL;
    }
    return $confirmation;
  }

  /**
   * {@inheritdoc}
   */
  public function applies($definition, $name, Route $route) {
    return !empty($definition['type']) && $definition['type'] == 'email-confirmer-confirmation-uuid';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UuidConverter::$entityTypeManager protected property The entity type manager.
UuidConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
UuidConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
UuidConverter::__construct public function Construct an email confirmation UUID param converter.