You are here

class WebformUiEntityElementsForm in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_ui/src/WebformUiEntityElementsForm.php \Drupal\webform_ui\WebformUiEntityElementsForm

Webform manage elements UI form.

Hierarchy

Expanded class hierarchy of WebformUiEntityElementsForm

File

modules/webform_ui/src/WebformUiEntityElementsForm.php, line 28

Namespace

Drupal\webform_ui
View source
class WebformUiEntityElementsForm extends BundleEntityFormBase {
  use WebformEntityAjaxFormTrait;

  /**
   * Array of required states.
   *
   * @var array
   */
  protected $requiredStates = [
    'required' => 'required',
    '!required' => '!required',
    'optional' => 'optional',
    '!optional' => '!optional',
  ];

  /**
   * The renderer.
   *
   * @var \Drupal\Core\Render\RendererInterface
   */
  protected $renderer;

  /**
   * The element info manager.
   *
   * @var \Drupal\Core\Render\ElementInfoManagerInterface
   */
  protected $elementInfo;

  /**
   * The webform element manager.
   *
   * @var \Drupal\webform\Plugin\WebformElementManagerInterface
   */
  protected $elementManager;

  /**
   * The webform element validator.
   *
   * @var \Drupal\webform\WebformEntityElementsValidatorInterface
   */
  protected $elementsValidator;

  /**
   * The webform token manager.
   *
   * @var \Drupal\webform\WebformTokenManagerInterface
   */
  protected $tokenManager;

  /**
   * Constructs a WebformUiEntityElementsForm.
   *
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer.
   * @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info
   *   The element manager.
   * @param \Drupal\webform\Plugin\WebformElementManagerInterface $element_manager
   *   The webform element manager.
   * @param \Drupal\webform\WebformEntityElementsValidatorInterface $elements_validator
   *   Webform element validator.
   */
  public function __construct(RendererInterface $renderer, ElementInfoManagerInterface $element_info, WebformElementManagerInterface $element_manager, WebformEntityElementsValidatorInterface $elements_validator) {
    $this->renderer = $renderer;
    $this->elementInfo = $element_info;
    $this->elementManager = $element_manager;
    $this->elementsValidator = $elements_validator;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('renderer'), $container
      ->get('plugin.manager.element_info'), $container
      ->get('plugin.manager.webform.element'), $container
      ->get('webform.elements_validator'));
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    /** @var \Drupal\webform\WebformInterface $webform */
    $webform = $this
      ->getEntity();
    $header = $this
      ->getTableHeader();
    $elements = $this
      ->getOrderableElements();

    // Get (weight) delta parent options.
    $delta = count($elements);
    $parent_options = $this
      ->getParentOptions($elements);

    // Build table rows for elements.
    $rows = [];
    foreach ($elements as $element) {
      $rows[$element['#webform_key']] = $this
        ->getElementRow($element, $delta, $parent_options);
    }
    $form['webform_ui_elements'] = [
      '#type' => 'table',
      '#header' => $header,
      '#empty' => $this
        ->t('Please add elements to this webform.'),
      '#attributes' => [
        'class' => [
          'webform-ui-elements-table',
        ],
      ],
      '#tabledrag' => [
        [
          'action' => 'match',
          'relationship' => 'parent',
          'group' => 'row-parent-key',
          'source' => 'row-key',
          'hidden' => TRUE,
          /* hides the WEIGHT & PARENT tree columns below */
          'limit' => FALSE,
        ],
        [
          'action' => 'order',
          'relationship' => 'sibling',
          'group' => 'row-weight',
        ],
      ],
    ] + $rows;
    if ($rows && !$webform
      ->hasActions()) {
      $form['webform_ui_elements'] += [
        'webform_actions_default' => $this
          ->getCustomizeActionsRow(),
      ];
    }

    // Must preload libraries required by (modal) dialogs.
    WebformDialogHelper::attachLibraries($form);
    $form['#attached']['library'][] = 'webform/webform.admin.tabledrag';
    $form['#attached']['library'][] = 'webform_ui/webform_ui';
    $form = parent::buildForm($form, $form_state);
    return $this
      ->buildAjaxForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state);

    /** @var \Drupal\webform\WebformInterface $webform */
    $webform = $this
      ->getEntity();

    // Get raw flattened elements that will be used to rebuild element's YAML
    // hierarchy.
    $elements_flattened = $webform
      ->getElementsDecodedAndFlattened();

    // Get the reordered elements and sort them by weight.
    $webform_ui_elements = $form_state
      ->getValue('webform_ui_elements') ?: [];
    uasort($webform_ui_elements, [
      'Drupal\\Component\\Utility\\SortArray',
      'sortByWeightElement',
    ]);

    // Make sure the reordered element keys and match the existing element keys.
    if (array_diff_key($webform_ui_elements, $elements_flattened)) {
      $form_state
        ->setError($form['webform_ui_elements'], $this
        ->t('The elements have been unexpectedly altered. Please try again'));
    }

    // Validate parent key and add children to ordered elements.
    foreach ($webform_ui_elements as $key => $table_element) {

      // Validate parent key.
      if ($parent_key = $table_element['parent_key']) {

        // Validate missing parent key.
        if (!isset($elements_flattened[$parent_key])) {
          $form_state
            ->setError($form['webform_ui_elements'][$key]['parent']['parent_key'], $this
            ->t('Parent %parent_key does not exist.', [
            '%parent_key' => $parent_key,
          ]));
          continue;
        }

        // Validate the parent keys and make sure there
        // are no recursive parents.
        $parent_keys = [
          $key,
        ];
        $current_parent_key = $parent_key;
        while ($current_parent_key) {
          if (in_array($current_parent_key, $parent_keys)) {
            $form_state
              ->setError($form['webform_ui_elements'][$key]['parent']['parent_key'], $this
              ->t('Parent %parent_key key is not valid.', [
              '%parent_key' => $parent_key,
            ]));
            break;
          }
          $parent_keys[] = $current_parent_key;
          $current_parent_key = isset($webform_ui_elements[$current_parent_key]['parent_key']) ? $webform_ui_elements[$current_parent_key]['parent_key'] : NULL;
        }
      }

      // Set #required or remove the property.
      $is_conditionally_required = isset($elements_flattened[$key]['#states']) && array_intersect_key($this->requiredStates, $elements_flattened[$key]['#states']);
      if ($is_conditionally_required) {

        // Always unset conditionally required elements.
        unset($elements_flattened[$key]['#required']);
      }
      elseif (isset($webform_ui_elements[$key]['required'])) {
        if (empty($webform_ui_elements[$key]['required'])) {
          unset($elements_flattened[$key]['#required']);
        }
        else {
          $elements_flattened[$key]['#required'] = TRUE;
        }
      }

      // Add this key to the parent's children.
      $webform_ui_elements[$parent_key]['children'][$key] = $key;
    }
    if ($form_state
      ->hasAnyErrors()) {
      return;
    }

    // Rebuild elements to reflect new hierarchy.
    $elements_updated = [];

    // Preserve the original elements root properties.
    $elements_original = Yaml::decode($webform
      ->get('elements')) ?: [];
    foreach ($elements_original as $key => $value) {
      if (WebformElementHelper::property($key)) {
        $elements_updated[$key] = $value;
      }
    }
    $this
      ->buildUpdatedElementsRecursive($elements_updated, '', $webform_ui_elements, $elements_flattened);

    // Update the webform's elements.
    $webform
      ->setUpdating()
      ->setElements($elements_updated);

    // Validate only elements required, hierarchy, and rendering.
    $validate_options = [
      'required' => TRUE,
      'yaml' => FALSE,
      'array' => FALSE,
      'names' => FALSE,
      'properties' => FALSE,
      'submissions' => FALSE,
      'hierarchy' => TRUE,
      'rendering' => TRUE,
    ];
    if ($this->elementsValidator
      ->validate($webform, $validate_options)) {
      $form_state
        ->setErrorByName(NULL, $this
        ->t('There has been error validating the elements.'));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function save(array $form, FormStateInterface $form_state) {

    /** @var \Drupal\webform\WebformInterface $webform */
    $webform = $this
      ->getEntity();
    $webform
      ->save();
    $context = [
      '@label' => $webform
        ->label(),
      'link' => $webform
        ->toLink($this
        ->t('Edit'), 'edit-form')
        ->toString(),
    ];
    $t_args = [
      '%label' => $webform
        ->label(),
    ];
    $this
      ->logger('webform')
      ->notice('Webform @label elements saved.', $context);
    $this
      ->messenger()
      ->addStatus($this
      ->t('Webform %label elements saved.', $t_args));
  }

  /**
   * {@inheritdoc}
   */
  protected function actionsElement(array $form, FormStateInterface $form_state) {
    $form = parent::actionsElement($form, $form_state);
    $form['submit']['#value'] = $this
      ->t('Save elements');
    unset($form['delete']);
    return $form;
  }

  /**
   * Build updated elements using the new parent child relationship.
   *
   * @param array $elements
   *   An associative array that will be populated with updated elements
   *   hierarchy.
   * @param string $key
   *   The current element key. The blank empty key represents the elements
   *   root.
   * @param array $webform_ui_elements
   *   An associative array contain the reordered elements parent child
   *   relationship.
   * @param array $elements_flattened
   *   An associative array containing the raw flattened elements that will
   *   copied into the updated elements hierarchy.
   */
  protected function buildUpdatedElementsRecursive(array &$elements, $key, array $webform_ui_elements, array $elements_flattened) {
    if (!isset($webform_ui_elements[$key]['children'])) {
      return;
    }
    foreach ($webform_ui_elements[$key]['children'] as $key) {
      $elements[$key] = $elements_flattened[$key];
      $this
        ->buildUpdatedElementsRecursive($elements[$key], $key, $webform_ui_elements, $elements_flattened);
    }
  }

  /**
   * Get webform's elements as an associative array of orderable elements.
   *
   * @return array
   *   An associative array of orderable elements.
   */
  protected function getOrderableElements() {

    /** @var \Drupal\webform\WebformInterface $webform */
    $webform = $this
      ->getEntity();
    $elements = $webform
      ->getElementsInitializedAndFlattened();
    $weights = [];
    foreach ($elements as $element_key => &$element) {
      $parent_key = $element['#webform_parent_key'];
      if (!isset($weights[$parent_key])) {
        $element['#weight'] = $weights[$parent_key] = 0;
      }
      else {
        $element['#weight'] = ++$weights[$parent_key];
      }
      if (empty($element['#type'])) {
        if (isset($element['#theme'])) {
          $element['#type'] = $element['#theme'];
        }
        else {
          $element['#type'] = '';
        }
      }
      if (empty($element['#title'])) {
        if (!empty($element['#markup'])) {
          $element['#title'] = Markup::create(Unicode::truncate(strip_tags($element['#markup']), 100, TRUE, TRUE));
        }
        else {
          $element['#title'] = '[' . $element_key . ']';
        }
      }
    }
    return $elements;
  }

  /**
   * Gets the elements table header.
   *
   * @return array
   *   The header elements.
   */
  protected function getTableHeader() {

    /** @var \Drupal\webform\WebformInterface $webform */
    $webform = $this
      ->getEntity();
    $header = [];
    $header['title'] = $this
      ->t('Title');
    if ($webform
      ->hasContainer()) {
      $header['add'] = [
        'data' => '',
        'class' => [
          'webform-ui-element-operations',
        ],
      ];
    }
    $header['key'] = [
      'data' => $this
        ->t('Key'),
      'class' => [
        RESPONSIVE_PRIORITY_LOW,
      ],
    ];
    $header['type'] = [
      'data' => $this
        ->t('Type'),
      'class' => [
        RESPONSIVE_PRIORITY_LOW,
      ],
    ];
    if ($webform
      ->hasFlexboxLayout()) {
      $header['flex'] = [
        'data' => $this
          ->t('Flex'),
        'class' => [
          RESPONSIVE_PRIORITY_LOW,
        ],
      ];
    }
    if ($webform
      ->hasConditions()) {
      $header['conditions'] = [
        'data' => $this
          ->t('Conditional'),
        'class' => [
          RESPONSIVE_PRIORITY_LOW,
        ],
      ];
    }
    $header['required'] = [
      'data' => $this
        ->t('Required'),
      'class' => [
        'webform-ui-element-required',
        RESPONSIVE_PRIORITY_LOW,
      ],
    ];
    $header['weight'] = [
      'data' => $this
        ->t('Weight'),
      'class' => [
        'webform-tabledrag-hide',
      ],
    ];
    $header['parent'] = [
      'data' => $this
        ->t('Parent'),
      'class' => [
        'webform-tabledrag-hide',
      ],
    ];
    $header['operations'] = [
      'data' => $this
        ->t('Operations'),
      'class' => [
        'webform-ui-element-operations',
      ],
    ];
    return $header;
  }

  /**
   * Get parent (container) elements as options.
   *
   * @param array $elements
   *   A flattened array of elements.
   *
   * @return array
   *   Parent (container) elements as options.
   */
  protected function getParentOptions(array $elements) {
    $options = [];
    foreach ($elements as $key => $element) {
      $plugin_id = $this->elementManager
        ->getElementPluginId($element);
      $webform_element = $this->elementManager
        ->createInstance($plugin_id);
      if ($webform_element
        ->isContainer($element)) {
        $options[$key] = $element['#admin_title'] ?: $element['#title'];
      }
    }
    return $options;
  }

  /**
   * Gets an row for a single element.
   *
   * @param array $element
   *   Webform element.
   * @param int $delta
   *   The number of elements.
   * @param array $parent_options
   *   An associative array of parent (container) options.
   *
   * @return array
   *   The row for the element.
   */
  protected function getElementRow(array $element, $delta, array $parent_options) {

    /** @var \Drupal\webform\WebformInterface $webform */
    $webform = $this
      ->getEntity();
    $row = [];
    $element_state_options = OptGroup::flattenOptions(WebformElementStates::getStateOptions());
    $key = $element['#webform_key'];
    $title = $element['#admin_title'] ?: $element['#title'];
    $title = is_array($title) ? $this->renderer
      ->render($title) : $title;
    $plugin_id = $this->elementManager
      ->getElementPluginId($element);

    /** @var \Drupal\webform\Plugin\WebformElementInterface $webform_element */
    $webform_element = $this->elementManager
      ->createInstance($plugin_id);
    $offcanvas_dialog_attributes = WebformDialogHelper::getOffCanvasDialogAttributes($webform_element
      ->getOffCanvasWidth());
    $is_container = $webform_element
      ->isContainer($element);
    $is_root = $webform_element
      ->isRoot();
    $is_element_disabled = $webform_element
      ->isDisabled();
    $is_access_disabled = !Element::isVisibleElement($element);

    // If disabled, display warning.
    if ($is_element_disabled) {
      $webform_element
        ->displayDisabledWarning($element);
    }

    // Get row class names.
    $row_class = [
      'draggable',
    ];
    if ($is_root) {
      $row_class[] = 'tabledrag-root';
      $row_class[] = 'webform-ui-element-root';
    }
    if (!$is_container) {
      $row_class[] = 'tabledrag-leaf';
    }
    if ($is_container) {
      $row_class[] = 'webform-ui-element-container';
    }
    if (!empty($element['#type'])) {
      $row_class[] = 'webform-ui-element-type-' . $element['#type'];
    }
    else {
      $row_class[] = 'webform-ui-element-container';
    }
    if ($is_element_disabled || $is_access_disabled) {
      $row_class[] = 'webform-ui-element-disabled';
    }

    // Add element key and type.
    $row['#attributes']['data-webform-key'] = $element['#webform_key'];
    $row['#attributes']['data-webform-type'] = isset($element['#type']) ? $element['#type'] : '';
    $row['#attributes']['class'] = $row_class;
    $indentation = NULL;
    if ($element['#webform_depth']) {
      $indentation = [
        '#theme' => 'indentation',
        '#size' => $element['#webform_depth'],
      ];
    }
    $row['title'] = [
      'link' => [
        '#type' => 'link',
        '#title' => $element['#admin_title'] ?: $element['#title'],
        '#url' => new Url('entity.webform_ui.element.edit_form', [
          'webform' => $webform
            ->id(),
          'key' => $key,
        ]),
        '#attributes' => $offcanvas_dialog_attributes,
        '#prefix' => !empty($indentation) ? $this->renderer
          ->renderPlain($indentation) : '',
      ],
    ];
    if (!empty($element['#admin_notes'])) {
      $row['title']['notes'] = [
        '#type' => 'webform_help',
        '#help_title' => $element['#admin_title'] ?: $element['#title'],
        '#help' => $element['#admin_notes'],
        '#weight' => 100,
      ];
    }
    if ($webform
      ->hasContainer()) {
      if ($is_container) {
        $route_parameters = [
          'webform' => $webform
            ->id(),
        ];
        $route_options = [
          'query' => [
            'parent' => $key,
          ],
        ];
        if ($webform_element instanceof WebformTable) {
          $route_parameters['type'] = 'webform_table_row';
          $row['add'] = [
            '#type' => 'link',
            '#title' => $this
              ->t('Add <span>row</span>'),
            '#url' => new Url('entity.webform_ui.element.add_form', $route_parameters, $route_options),
            '#attributes' => WebformDialogHelper::getOffCanvasDialogAttributes(WebformDialogHelper::DIALOG_NORMAL, [
              'button',
              'button-action',
              'button--primary',
              'button--small',
            ]),
          ];
        }
        else {
          $row['add'] = [
            '#type' => 'link',
            '#title' => $this
              ->t('Add <span>element</span>'),
            '#url' => new Url('entity.webform_ui.element', $route_parameters, $route_options),
            '#attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NORMAL, [
              'button',
              'button-action',
              'button--primary',
              'button--small',
            ]),
          ];
        }
      }
      else {
        $row['add'] = [
          '#markup' => '',
        ];
      }
    }
    $row['name'] = [
      '#markup' => $element['#webform_key'],
    ];
    $type = $webform_element
      ->getPluginLabel();
    if ($webform_element instanceof WebformElement) {
      if (!empty($element['#type'])) {
        $type = '[' . $element['#type'] . ']';
      }
      elseif (isset($element['#theme'])) {
        $type = '[' . $element['#theme'] . ']';
      }
    }
    $row['type'] = [
      '#markup' => $type,
    ];
    if ($webform
      ->hasFlexboxLayout()) {
      $row['flex'] = [
        '#markup' => empty($element['#flex']) ? 1 : $element['#flex'],
      ];
    }
    $is_conditionally_required = FALSE;
    if ($webform
      ->hasConditions()) {
      $states = [];
      if (!empty($element['#states'])) {
        $states = array_intersect_key($element_state_options, $element['#states']);
        $is_conditionally_required = array_intersect_key($this->requiredStates, $element['#states']);
      }
      $row['conditional'] = [
        '#type' => 'link',
        '#title' => implode('; ', $states),
        '#url' => new Url('entity.webform_ui.element.edit_form', [
          'webform' => $webform
            ->id(),
          'key' => $key,
        ]),
        '#attributes' => $offcanvas_dialog_attributes + [
          // Add custom hash to current page's location.
          // @see Drupal.behaviors.webformAjaxLink
          'data-hash' => 'webform-tab--conditions',
          'title' => $this
            ->t('Edit @states conditional', [
            '@states' => implode('; ', $states),
          ]),
          'aria-label' => $this
            ->t('Edit @states conditional', [
            '@states' => implode('; ', $states),
          ]),
        ],
      ];
    }
    if ($webform_element
      ->hasProperty('required')) {
      $row['required'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Required for @title', [
          '@title' => $title,
        ]),
        '#title_display' => 'invisible',
        '#default_value' => empty($element['#required']) ? FALSE : TRUE,
      ];
      if ($is_conditionally_required) {
        $row['required']['#default_value'] = TRUE;
        $row['required']['#disabled'] = TRUE;
      }
    }
    else {
      $row['required'] = [
        '#markup' => '',
      ];
    }
    $row['weight'] = [
      '#type' => 'weight',
      '#title' => $this
        ->t('Weight for @title', [
        '@title' => $title,
      ]),
      '#title_display' => 'invisible',
      '#default_value' => $element['#weight'],
      '#wrapper_attributes' => [
        'class' => [
          'webform-tabledrag-hide',
        ],
      ],
      '#attributes' => [
        'class' => [
          'row-weight',
        ],
      ],
      '#delta' => $delta,
    ];
    $row['parent'] = [
      '#wrapper_attributes' => [
        'class' => [
          'webform-tabledrag-hide',
        ],
      ],
    ];
    $row['parent']['key'] = [
      '#parents' => [
        'webform_ui_elements',
        $key,
        'key',
      ],
      '#type' => 'hidden',
      '#value' => $key,
      '#attributes' => [
        'class' => [
          'row-key',
        ],
      ],
    ];
    if ($parent_options) {
      $row['parent']['parent_key'] = [
        '#parents' => [
          'webform_ui_elements',
          $key,
          'parent_key',
        ],
        '#type' => 'select',
        '#options' => $parent_options,
        '#empty_option' => '',
        '#title' => $this
          ->t('Parent element @title', [
          '@title' => $title,
        ]),
        '#title_display' => 'invisible',
        '#default_value' => $element['#webform_parent_key'],
        '#attributes' => [
          'class' => [
            'row-parent-key',
          ],
        ],
      ];
    }
    else {
      $row['parent']['parent_key'] = [
        '#parents' => [
          'webform_ui_elements',
          $key,
          'parent_key',
        ],
        '#type' => 'hidden',
        '#default_value' => '',
        '#attributes' => [
          'class' => [
            'row-parent-key',
          ],
        ],
      ];
    }
    $row['operations'] = [
      '#type' => 'operations',
      '#prefix' => '<div class="webform-dropbutton">',
      '#suffix' => '</div>',
    ];
    $row['operations']['#links']['edit'] = [
      'title' => $this
        ->t('Edit'),
      'url' => new Url('entity.webform_ui.element.edit_form', [
        'webform' => $webform
          ->id(),
        'key' => $key,
      ]),
      'attributes' => $offcanvas_dialog_attributes,
    ];

    // Issue #2741877 Nested modals don't work: when using CKEditor in a
    // modal, then clicking the image button opens another modal,
    // which closes the original modal.
    // @todo Remove the below workaround once this issue is resolved.
    if ($webform_element
      ->getPluginId() === 'processed_text' && !WebformDialogHelper::useOffCanvas()) {
      unset($row['operations']['#links']['edit']['attributes']);
    }
    if (!$is_container) {
      $row['operations']['#links']['duplicate'] = [
        'title' => $this
          ->t('Duplicate'),
        'url' => new Url('entity.webform_ui.element.duplicate_form', [
          'webform' => $webform
            ->id(),
          'key' => $key,
        ]),
        'attributes' => $offcanvas_dialog_attributes,
      ];
    }
    $row['operations']['#links']['delete'] = [
      'title' => $this
        ->t('Delete'),
      'url' => new Url('entity.webform_ui.element.delete_form', [
        'webform' => $webform
          ->id(),
        'key' => $key,
      ]),
      'attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NARROW),
    ];
    return $row;
  }

  /**
   * Get customize actions row.
   *
   * @return array
   *   The customize actions row.
   */
  protected function getCustomizeActionsRow() {

    /** @var \Drupal\webform\WebformInterface $webform */
    $webform = $this
      ->getEntity();
    $row = [];
    $row['#attributes']['class'] = [
      'webform-ui-element-type-webform_actions',
    ];
    $row['title'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Submit button(s)'),
      '#url' => new Url('entity.webform_ui.element.add_form', [
        'webform' => $webform
          ->id(),
        'type' => 'webform_actions',
      ], [
        'query' => [
          'key' => 'actions',
        ],
      ]),
      '#attributes' => WebformDialogHelper::getOffCanvasDialogAttributes(),
    ];
    if ($webform
      ->hasContainer()) {
      $row['add'] = [
        '#markup' => '',
      ];
    }
    $row['name'] = [
      '#markup' => 'actions',
    ];
    $row['type'] = [
      '#markup' => $this
        ->t('Submit button(s)'),
    ];
    if ($webform
      ->hasFlexboxLayout()) {
      $row['flex'] = [
        '#markup' => 1,
      ];
    }
    if ($webform
      ->hasConditions()) {
      $row['conditions'] = [
        '#markup' => '',
      ];
    }
    $row['required'] = [
      '#markup' => '',
    ];
    $row['weight'] = [
      '#markup' => '',
      '#wrapper_attributes' => [
        'class' => [
          'webform-tabledrag-hide',
        ],
      ],
    ];
    $row['parent'] = [
      '#markup' => '',
      '#wrapper_attributes' => [
        'class' => [
          'webform-tabledrag-hide',
        ],
      ],
    ];
    if ($this->elementManager
      ->isExcluded('webform_actions')) {
      $row['operations'] = [
        '#markup' => '',
      ];
    }
    else {
      $row['operations'] = [
        '#type' => 'operations',
        '#prefix' => '<div class="webform-dropbutton">',
        '#suffix' => '</div>',
      ];
      $row['operations']['#links']['customize'] = [
        'title' => $this
          ->t('Customize'),
        'url' => new Url('entity.webform_ui.element.add_form', [
          'webform' => $webform
            ->id(),
          'type' => 'webform_actions',
        ]),
        'attributes' => WebformDialogHelper::getOffCanvasDialogAttributes(),
      ];
    }
    return $row;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BundleEntityFormBase::protectBundleIdElement protected function Protects the bundle entity's ID property's form element against changes.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EntityForm::$entity protected property The entity being used by this form. 7
EntityForm::$entityTypeManager protected property The entity type manager. 3
EntityForm::$moduleHandler protected property The module handler service.
EntityForm::$operation protected property The name of the current operation.
EntityForm::$privateEntityManager private property The entity manager.
EntityForm::afterBuild public function Form element #after_build callback: Updates the entity with submitted data.
EntityForm::buildEntity public function Builds an updated entity object based upon the submitted form values. Overrides EntityFormInterface::buildEntity 2
EntityForm::copyFormValuesToEntity protected function Copies top-level form values to entity properties 7
EntityForm::form public function Gets the actual form array to be built. 30
EntityForm::getBaseFormId public function Returns a string identifying the base form. Overrides BaseFormIdInterface::getBaseFormId 5
EntityForm::getEntity public function Gets the form entity. Overrides EntityFormInterface::getEntity
EntityForm::getEntityFromRouteMatch public function Determines which entity will be used by this form from a RouteMatch object. Overrides EntityFormInterface::getEntityFromRouteMatch 1
EntityForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId 10
EntityForm::getOperation public function Gets the operation identifying the form. Overrides EntityFormInterface::getOperation
EntityForm::init protected function Initialize the form state and the entity before the first form build. 3
EntityForm::prepareEntity protected function Prepares the entity object before the form is built first. 3
EntityForm::prepareInvokeAll protected function Invokes the specified prepare hook variant.
EntityForm::processForm public function Process callback: assigns weights and hides extra fields.
EntityForm::setEntity public function Sets the form entity. Overrides EntityFormInterface::setEntity
EntityForm::setEntityManager public function Sets the entity manager for this form. Overrides EntityFormInterface::setEntityManager
EntityForm::setEntityTypeManager public function Sets the entity type manager for this form. Overrides EntityFormInterface::setEntityTypeManager
EntityForm::setModuleHandler public function Sets the module handler for this form. Overrides EntityFormInterface::setModuleHandler
EntityForm::setOperation public function Sets the operation for this form. Overrides EntityFormInterface::setOperation
EntityForm::submitForm public function This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state… Overrides FormInterface::submitForm 17
EntityForm::__get public function
EntityForm::__set public function
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.
WebformAjaxFormTrait::announce protected function Queue announcement with Ajax response.
WebformAjaxFormTrait::buildAjaxForm protected function Add Ajax support to a form.
WebformAjaxFormTrait::createAjaxResponse protected function Create an AjaxResponse or WebformAjaxResponse object.
WebformAjaxFormTrait::getAnnouncements protected function Get announcements.
WebformAjaxFormTrait::getFormStateRedirectUrl protected function Get redirect URL from the form's state.
WebformAjaxFormTrait::getWrapperId protected function Get the form's Ajax wrapper id. 1
WebformAjaxFormTrait::isCallableAjaxCallback protected function Determine if Ajax callback is callable.
WebformAjaxFormTrait::isDialog protected function Is the current request for an Ajax modal/dialog.
WebformAjaxFormTrait::isOffCanvasDialog protected function Is the current request for an off canvas dialog.
WebformAjaxFormTrait::missingAjaxCallback protected function Handle missing Ajax callback.
WebformAjaxFormTrait::noSubmit public function Empty submit callback used to only have the submit button to use an #ajax submit callback. 1
WebformAjaxFormTrait::resetAnnouncements protected function Reset announcements.
WebformAjaxFormTrait::setAnnouncements protected function Set announcements.
WebformAjaxFormTrait::submitAjaxForm public function Submit form #ajax callback. 1
WebformAjaxFormTrait::validateAjaxForm public function Validate form #ajax callback. 1
WebformEntityAjaxFormTrait::actions protected function
WebformEntityAjaxFormTrait::cancelAjaxForm public function Cancel form #ajax callback. Overrides WebformAjaxFormTrait::cancelAjaxForm
WebformEntityAjaxFormTrait::getDefaultAjaxSettings protected function Get default ajax callback settings. Overrides WebformAjaxFormTrait::getDefaultAjaxSettings
WebformEntityAjaxFormTrait::isAjax protected function Returns if webform is using Ajax. Overrides WebformAjaxFormTrait::isAjax
WebformEntityAjaxFormTrait::isDialogDisabled protected function Determine if dialogs are disabled.
WebformEntityAjaxFormTrait::replaceForm protected function Replace form via an Ajax response. Overrides WebformAjaxFormTrait::replaceForm
WebformUiEntityElementsForm::$elementInfo protected property The element info manager.
WebformUiEntityElementsForm::$elementManager protected property The webform element manager.
WebformUiEntityElementsForm::$elementsValidator protected property The webform element validator.
WebformUiEntityElementsForm::$renderer protected property The renderer.
WebformUiEntityElementsForm::$requiredStates protected property Array of required states.
WebformUiEntityElementsForm::$tokenManager protected property The webform token manager.
WebformUiEntityElementsForm::actionsElement protected function Returns the action form element for the current entity form. Overrides EntityForm::actionsElement
WebformUiEntityElementsForm::buildForm public function Form constructor. Overrides WebformEntityAjaxFormTrait::buildForm
WebformUiEntityElementsForm::buildUpdatedElementsRecursive protected function Build updated elements using the new parent child relationship.
WebformUiEntityElementsForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
WebformUiEntityElementsForm::getCustomizeActionsRow protected function Get customize actions row.
WebformUiEntityElementsForm::getElementRow protected function Gets an row for a single element.
WebformUiEntityElementsForm::getOrderableElements protected function Get webform's elements as an associative array of orderable elements.
WebformUiEntityElementsForm::getParentOptions protected function Get parent (container) elements as options.
WebformUiEntityElementsForm::getTableHeader protected function Gets the elements table header.
WebformUiEntityElementsForm::save public function Form submission handler for the 'save' action. Overrides EntityForm::save
WebformUiEntityElementsForm::validateForm public function Form validation handler. Overrides FormBase::validateForm
WebformUiEntityElementsForm::__construct public function Constructs a WebformUiEntityElementsForm.