You are here

public function WebformAjaxElementTrait::buildAjaxElementUpdate in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformAjaxElementTrait.php \Drupal\webform\Element\WebformAjaxElementTrait::buildAjaxElementUpdate()

Build an Ajax element's update (submit) button.

Parameters

string $id: The id used to create the Ajax wrapper and trigger.

array &$element: The element to append the hidden Ajax submit button.

4 calls to WebformAjaxElementTrait::buildAjaxElementUpdate()
EmailWebformHandler::buildElement in src/Plugin/WebformHandler/EmailWebformHandler.php
Build A select other element for email address and names.
WebformAjaxElementTrait::buildAjaxElement in src/Element/WebformAjaxElementTrait.php
Build an Ajax element.
WebformEntityReferenceTrait::form in src/Plugin/WebformElement/WebformEntityReferenceTrait.php
WebformEntityReferenceWidgetTrait::formElement in src/Plugin/Field/FieldWidget/WebformEntityReferenceWidgetTrait.php

File

src/Element/WebformAjaxElementTrait.php, line 116

Class

WebformAjaxElementTrait
Trait class for element Ajax support.

Namespace

Drupal\webform\Element

Code

public function buildAjaxElementUpdate($id, array &$element) {
  $element['update'] = [
    '#type' => 'submit',
    '#value' => t('Update'),
    // Submit buttons with the same label must have a unique name.
    // @see https://www.drupal.org/project/drupal/issues/1342066
    '#name' => $this
      ->getAjaxElementUpdateName($id),
    // Validate the element.
    '#validate' => [
      [
        get_called_class(),
        'validateAjaxElementCallback',
      ],
    ],
    // Submit the element.
    '#submit' => [
      [
        get_called_class(),
        'submitAjaxElementCallback',
      ],
    ],
    // Refresh the element.
    '#ajax' => [
      'callback' => [
        get_called_class(),
        'updateAjaxElementCallback',
      ],
      'wrapper' => $this
        ->getAjaxElementWrapperId($id),
      'progress' => [
        'type' => 'fullscreen',
      ],
    ],
    // Disable validation, hide the button, and add trigger update class.
    '#attributes' => [
      'formnovalidate' => 'formnovalidate',
      'class' => [
        'js-hide',
        $this
          ->getAjaxElementUpdateClass($id),
      ],
    ],
    // Always render the update button.
    '#access' => TRUE,
    // Store a reference to the Ajax id.
    '#webform_ajax_element_type' => 'update',
    '#webform_ajax_element_id' => $id,
  ];
}