You are here

protected function WebformTranslationConfigManager::alterConfigWebformFormHandlers in Webform 6.x

Alter the webform configuration form handlers.

Parameters

string $config_name: The webform configuration name.

array $config_element: The webform configuration element.

$form: Nested array of form elements that comprise the form.

$form_state: The current state of the form.

1 call to WebformTranslationConfigManager::alterConfigWebformFormHandlers()
WebformTranslationConfigManager::alterConfigWebformForm in src/WebformTranslationConfigManager.php
Alter the webform configuration form.

File

src/WebformTranslationConfigManager.php, line 321

Class

WebformTranslationConfigManager
Defines a class to translate webform config.

Namespace

Drupal\webform

Code

protected function alterConfigWebformFormHandlers($config_name, &$config_element, &$form, $form_state) {
  $handlers =& $config_element['handlers'];

  // Verify if the webform has any handler.
  if (!isset($handlers)) {
    return;
  }
  $webform = $this
    ->loadWebform($config_name);
  foreach (Element::children($handlers) as $handler_id) {
    $handler = $webform
      ->getHandler($handler_id);
    if (!$handler) {
      continue;
    }

    // Apply custom logic to email body which can be twig, html, or text.
    if ($handler instanceof EmailWebformHandler) {
      $body_element =& NestedArray::getValue($config_element, [
        'handlers',
        $handler_id,
        'settings',
        'body',
      ]);
      if ($body_element) {
        $configuration = $handler
          ->getConfiguration();
        if (!empty($configuration['settings']['twig'])) {
          $this
            ->alterTextareaElement($body_element, 'twig');
          $body_element['translation']['#access'] = WebformTwigExtension::hasEditTwigAccess();
        }
        elseif (!empty($configuration['settings']['html'])) {
          $this
            ->alterHtmlEditorElement($body_element);
        }
        else {
          $this
            ->alterTextareaElement($body_element, 'text');
        }
      }
    }
  }
}