You are here

public function Webform::getHandlers in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Entity/Webform.php \Drupal\webform\Entity\Webform::getHandlers()

Returns the webform handlers for this webform.

Parameters

string $plugin_id: (optional) Plugin id used to return specific plugin instances (i.e. handlers).

bool $status: (optional) Status used to return enabled or disabled plugin instances (i.e. handlers).

int $results: (optional) Value indicating if webform submissions are saved to internal or external system.

int $submission: (optional) Value indicating if webform submissions must be saved to the database.

Return value

\Drupal\webform\Plugin\WebformHandlerPluginCollection|\Drupal\webform\Plugin\WebformHandlerInterface[] The webform handler plugin collection.

Overrides WebformInterface::getHandlers

5 calls to Webform::getHandlers()
Webform::getPluginCollections in src/Entity/Webform.php
Gets the plugin collections used by this object.
Webform::hasAnonymousSubmissionTrackingHandler in src/Entity/Webform.php
Determine if a webform handler requires anonymous submission tracking.
Webform::hasMessageHandler in src/Entity/Webform.php
Determine if the webform has any message handlers.
Webform::invokeHandlers in src/Entity/Webform.php
Invoke a handlers method.
Webform::onDependencyRemoval in src/Entity/Webform.php
Informs the entity that entities it depends on will be deleted.

File

src/Entity/Webform.php, line 2576

Class

Webform
Defines the webform entity.

Namespace

Drupal\webform\Entity

Code

public function getHandlers($plugin_id = NULL, $status = NULL, $results = NULL, $submission = NULL) {
  if (!$this->handlersCollection) {
    $this->handlersCollection = new WebformHandlerPluginCollection($this
      ->getWebformHandlerPluginManager(), $this->handlers);

    /** @var \Drupal\webform\Plugin\WebformHandlerBase $handler */
    foreach ($this->handlersCollection as $handler) {

      // Initialize the handler and pass in the webform.
      $handler
        ->setWebform($this);
    }
    $this->handlersCollection
      ->sort();
  }

  /** @var \Drupal\webform\Plugin\WebformHandlerPluginCollection $handlers */
  $handlers = $this->handlersCollection;

  // Clone the handlers if they are being filtered.
  if (isset($plugin_id) || isset($status) || isset($results)) {

    /** @var \Drupal\webform\Plugin\WebformHandlerPluginCollection $handlers */
    $handlers = clone $this->handlersCollection;
  }

  // Filter the handlers by plugin id.
  // This is used to limit track and enforce a handlers cardinality.
  if (isset($plugin_id)) {
    foreach ($handlers as $instance_id => $handler) {
      if ($handler
        ->getPluginId() !== $plugin_id) {
        $handlers
          ->removeInstanceId($instance_id);
      }
    }
  }

  // Filter the handlers by status.
  // This is used to limit track and enforce a handlers cardinality.
  if (isset($status)) {
    foreach ($handlers as $instance_id => $handler) {
      if ($handler
        ->getStatus() !== $status) {
        $handlers
          ->removeInstanceId($instance_id);
      }
    }
  }

  // Filter the handlers by results.
  // This is used to track is results are processed or ignored.
  if (isset($results)) {
    foreach ($handlers as $instance_id => $handler) {
      $plugin_definition = $handler
        ->getPluginDefinition();
      if ($plugin_definition['results'] !== $results) {
        $handlers
          ->removeInstanceId($instance_id);
      }
    }
  }

  // Filter the handlers by submission.
  // This is used to track is submissions must be saved to the database.
  if (isset($submission)) {
    foreach ($handlers as $instance_id => $handler) {
      $plugin_definition = $handler
        ->getPluginDefinition();
      if ($plugin_definition['submission'] !== $submission) {
        $handlers
          ->removeInstanceId($instance_id);
      }
    }
  }
  return $handlers;
}