You are here

public function YamlForm::getHandlers in YAML Form 8

Returns the form handlers for this form.

Parameters

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

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

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

Return value

\Drupal\yamlform\YamlFormHandlerPluginCollection|\Drupal\yamlform\YamlFormHandlerInterface[] The form handler plugin collection.

Overrides YamlFormInterface::getHandlers

3 calls to YamlForm::getHandlers()
YamlForm::getPluginCollections in src/Entity/YamlForm.php
Gets the plugin collections used by this object.
YamlForm::invokeHandlers in src/Entity/YamlForm.php
Invoke a handlers method.
YamlForm::onDependencyRemoval in src/Entity/YamlForm.php
Informs the entity that entities it depends on will be deleted.

File

src/Entity/YamlForm.php, line 1298

Class

YamlForm
Defines the form entity.

Namespace

Drupal\yamlform\Entity

Code

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

    /** @var \Drupal\yamlform\YamlFormHandlerBase $handler */
    foreach ($this->handlersCollection as $handler) {

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

  /** @var \Drupal\yamlform\YamlFormHandlerPluginCollection $handlers */
  $handlers = $this->handlersCollection;

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

    /** @var \Drupal\yamlform\YamlFormHandlerPluginCollection $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);
      }
    }
  }
  return $handlers;
}