buttonWasClicked example

      // can only have been triggered by a button, and we need to determine       // which button within the constraints of how browsers provide this       // information.       if (!empty($element['#is_button'])) {
        // All buttons in the form need to be tracked for         // \Drupal\Core\Form\FormState::cleanValues() and for the         // self::doBuildForm() code that handles a form submission containing no         // button information in \Drupal::request()->request.         $buttons = $form_state->getButtons();
        $buttons[] = $element;
        $form_state->setButtons($buttons);
        if ($this->buttonWasClicked($element$form_state)) {
          $form_state->setTriggeringElement($element);
        }
      }
    }

    // Set the element's value in $form_state->getValues(), but only, if its key     // does not exist yet (a #value_callback may have already populated it).     if (!NestedArray::keyExists($form_state->getValues()$element['#parents'])) {
      $form_state->setValueForElement($element$element['#value']);
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.