You are here

public function Webform::invokeHandlers in Webform 6.x

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

Invoke a handlers method.

Parameters

string $method: The handler method to be invoked.

mixed $data: The argument to passed by reference to the handler method.

mixed $context1: (optional) An additional variable that is passed by reference.

mixed $context2: (optional) An additional variable that is passed by reference.

mixed $context3: (optional) An additional variable that is passed by reference.

Return value

\Drupal\Core\Access\AccessResult|null If 'access' method is invoked an AccessResult is returned.

Overrides WebformInterface::invokeHandlers

2 calls to Webform::invokeHandlers()
Webform::initElements in src/Entity/Webform.php
Initialize and parse webform elements.
Webform::postSave in src/Entity/Webform.php
Acts on a saved entity before the insert or update hook is invoked.

File

src/Entity/Webform.php, line 2685

Class

Webform
Defines the webform entity.

Namespace

Drupal\webform\Entity

Code

public function invokeHandlers($method, &$data, &$context1 = NULL, &$context2 = NULL, &$context3 = NULL) {

  // Get webform submission from arguments for conditions validations.
  $webform_submission = NULL;
  $args = func_get_args();
  foreach ($args as $arg) {
    if ($arg instanceof WebformSubmissionInterface) {
      $webform_submission = $arg;
      break;
    }
  }

  // Get handlers.
  $handlers = $this
    ->getHandlers();
  switch ($method) {
    case 'overrideSettings':

      // If webform submission and alter settings, make sure to completely
      // reset all settings to their original values.
      $this
        ->resetSettings();
      $settings = $this
        ->getSettings();
      foreach ($handlers as $handler) {
        $handler
          ->setWebformSubmission($webform_submission);
        $this
          ->invokeHandlerAlter($handler, $method, $args);
        if ($this
          ->isHandlerEnabled($handler, $webform_submission)) {
          $handler
            ->overrideSettings($settings, $webform_submission);
        }
      }

      // If a handler has change some settings set override.
      // Only look for altered original settings, which prevents issues where
      // a webform saved settings and default settings are out-of-sync.
      if (array_intersect_key($settings, $this->settingsOriginal) !== $this->settingsOriginal) {
        $this
          ->setSettingsOverride($settings);
      }
      return NULL;
    case 'access':
    case 'accessElement':

      // WebformHandler::access() and WebformHandler::accessElement()
      // returns a AccessResult.

      /** @var \Drupal\Core\Access\AccessResultInterface $result */
      $result = AccessResult::neutral();
      foreach ($handlers as $handler) {
        $handler
          ->setWebformSubmission($webform_submission);
        $this
          ->invokeHandlerAlter($handler, $method, $args);
        if ($this
          ->isHandlerEnabled($handler, $webform_submission)) {
          $result = $result
            ->orIf($handler
            ->{$method}($data, $context1, $context2));
        }
      }
      return $result;
    default:
      foreach ($handlers as $handler) {
        $handler
          ->setWebformSubmission($webform_submission);
        $this
          ->invokeHandlerAlter($handler, $method, $args);
        if ($this
          ->isHandlerEnabled($handler, $webform_submission)) {
          $handler
            ->{$method}($data, $context1, $context2);
        }
      }
      return NULL;
  }
}