You are here

class WebformProtectedDownloadsManager in Webform Protected Downloads 8

Class WebformProtectedDownloadsManager.

@package Drupal\webform_protected_downloads

Hierarchy

Expanded class hierarchy of WebformProtectedDownloadsManager

1 file declares its use of WebformProtectedDownloadsManager
WebformProtectedDownloadsController.php in src/Controller/WebformProtectedDownloadsController.php
1 string reference to 'WebformProtectedDownloadsManager'
webform_protected_downloads.services.yml in ./webform_protected_downloads.services.yml
webform_protected_downloads.services.yml
1 service uses WebformProtectedDownloadsManager
webform_protected_downloads.manager in ./webform_protected_downloads.services.yml
Drupal\webform_protected_downloads\WebformProtectedDownloadsManager

File

src/WebformProtectedDownloadsManager.php, line 15

Namespace

Drupal\webform_protected_downloads
View source
class WebformProtectedDownloadsManager implements WebformProtectedDownloadsManagerInterface, ContainerInjectionInterface {

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

  /**
   * Constructs a GroupContentCardinalityValidator object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getSubmissionByUuid($uuid) {

    // Get all WebformProtectedDownloads.
    $webformProtectedDownloadEntities = WebformProtectedDownloads::loadMultiple();
    foreach ($webformProtectedDownloadEntities as $entity) {

      // Get WebformSubmission.
      $webformSubmission = $entity
        ->getWebformSubmission();

      // Compare uuid's.
      if ($webformSubmission
        ->uuid() == $uuid) {

        // Return WebformProtectedDownload.
        return $entity;
      }
      continue;
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getSubmissionByHash($hash) {
    $result = $this->entityTypeManager
      ->getStorage('webform_protected_downloads')
      ->getQuery()
      ->condition('hash', $hash)
      ->execute();

    // Return entity if exists or FALSE.
    if ($result) {
      return WebformProtectedDownloads::load(reset($result));
    }
    else {
      return FALSE;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WebformProtectedDownloadsManager::$entityTypeManager protected property The entity type manager.
WebformProtectedDownloadsManager::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
WebformProtectedDownloadsManager::getSubmissionByHash public function Get WebformProtectedDownloads entity by hash. Overrides WebformProtectedDownloadsManagerInterface::getSubmissionByHash
WebformProtectedDownloadsManager::getSubmissionByUuid public function Function will search submission by uuid. Overrides WebformProtectedDownloadsManagerInterface::getSubmissionByUuid
WebformProtectedDownloadsManager::__construct public function Constructs a GroupContentCardinalityValidator object.