class WebformDevelEntityFormApiTestForm in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_devel/src/Form/WebformDevelEntityFormApiTestForm.php \Drupal\webform_devel\Form\WebformDevelEntityFormApiTestForm
Export a webform's element to Form API (FAPI).
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
- class \Drupal\webform_devel\Form\WebformDevelEntityFormApiBaseForm
- class \Drupal\webform_devel\Form\WebformDevelEntityFormApiTestForm uses WebformDialogFormTrait
- class \Drupal\webform_devel\Form\WebformDevelEntityFormApiBaseForm
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
Expanded class hierarchy of WebformDevelEntityFormApiTestForm
File
- modules/
webform_devel/ src/ Form/ WebformDevelEntityFormApiTestForm.php, line 13
Namespace
Drupal\webform_devel\FormView source
class WebformDevelEntityFormApiTestForm extends WebformDevelEntityFormApiBaseForm {
use WebformDialogFormTrait;
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $this
->getEntity();
$elements = $webform
->getElementsDecoded();
// Cleanup element and set default data for testing.
$this
->cleanupElements($elements);
$this
->setDefaultValues($elements);
// Process elements and replace tokens.
$this->elementManager
->processElements($elements);
$elements = $this->tokenManager
->replace($elements);
// Set elements.
$form += $elements;
// Append submit actions.
$form['actions'] = [
'#type' => 'actions',
'#tree' => TRUE,
'submit' => [
'#type' => 'submit',
'#value' => $this
->t('Test'),
'#button_type' => 'primary',
],
];
// Attach the webform library.
$form['#attached']['library'][] = 'webform/webform.form';
// Autofocus: Save details open/close state.
$form['#attributes']['class'][] = 'js-webform-autofocus';
$form['#attached']['library'][] = 'webform/webform.form.auto_focus';
// Unsaved: Warn users about unsaved changes.
$form['#attributes']['class'][] = 'js-webform-unsaved';
$form['#attached']['library'][] = 'webform/webform.form.unsaved';
// Details save: Attach details element save open/close library.
$form['#attached']['library'][] = 'webform/webform.element.details.save';
// Details toggle: Display collapse/expand all details link.
$form['#attributes']['class'][] = 'js-webform-details-toggle';
$form['#attributes']['class'][] = 'webform-details-toggle';
$form['#attached']['library'][] = 'webform/webform.element.details.toggle';
return $this
->buildDialogConfirmForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($this
->isDialog()) {
$form_state
->setRebuild();
}
// Display submission values.
$values = $form_state
->getValues();
unset($values['form_build_id'], $values['form_token'], $values['form_id'], $values['op'], $values['actions']);
$build = [
'#markup' => 'Submitted values are:<pre>' . WebformYaml::encode($values) . '</pre>',
];
$this
->messenger()
->addWarning($this->renderer
->renderPlain($build));
}
/****************************************************************************/
// Helper functions.
/****************************************************************************/
/**
* Set webform elements default values using test data.
*
* @param array $elements
* An render array representing elements.
*/
protected function setDefaultValues(array &$elements) {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $this
->getEntity();
$data = $this->generate
->getData($webform);
$flattened_elements =& WebformFormHelper::flattenElements($elements);
foreach ($flattened_elements as $element_key => &$element) {
if (isset($data[$element_key])) {
$element['#default_value'] = $data[$element_key];
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityForm:: |
protected | property | The entity being used by this form. | 11 |
EntityForm:: |
protected | property | The entity type manager. | 3 |
EntityForm:: |
protected | property | The module handler service. | |
EntityForm:: |
protected | property | The name of the current operation. | |
EntityForm:: |
protected | function | Returns an array of supported actions for the current entity form. | 35 |
EntityForm:: |
protected | function | Returns the action form element for the current entity form. | |
EntityForm:: |
public | function | Form element #after_build callback: Updates the entity with submitted data. | |
EntityForm:: |
public | function |
Builds an updated entity object based upon the submitted form values. Overrides EntityFormInterface:: |
3 |
EntityForm:: |
protected | function | Copies top-level form values to entity properties. | 9 |
EntityForm:: |
public | function | Gets the actual form array to be built. | 36 |
EntityForm:: |
public | function |
Returns a string identifying the base form. Overrides BaseFormIdInterface:: |
6 |
EntityForm:: |
public | function |
Gets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Determines which entity will be used by this form from a RouteMatch object. Overrides EntityFormInterface:: |
3 |
EntityForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
12 |
EntityForm:: |
public | function |
Gets the operation identifying the form. Overrides EntityFormInterface:: |
|
EntityForm:: |
protected | function | Initialize the form state and the entity before the first form build. | 3 |
EntityForm:: |
protected | function | Prepares the entity object before the form is built first. | 3 |
EntityForm:: |
protected | function | Invokes the specified prepare hook variant. | |
EntityForm:: |
public | function | Process callback: assigns weights and hides extra fields. | |
EntityForm:: |
public | function |
Form submission handler for the 'save' action. Overrides EntityFormInterface:: |
47 |
EntityForm:: |
public | function |
Sets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity type manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the module handler for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the operation for this form. Overrides EntityFormInterface:: |
|
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
72 |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
WebformAjaxFormTrait:: |
protected | function | Queue announcement with Ajax response. | |
WebformAjaxFormTrait:: |
protected | function | Add Ajax support to a form. | |
WebformAjaxFormTrait:: |
protected | function | Create an AjaxResponse or WebformAjaxResponse object. | |
WebformAjaxFormTrait:: |
protected | function | Get announcements. | |
WebformAjaxFormTrait:: |
protected | function | Get default ajax callback settings. | 1 |
WebformAjaxFormTrait:: |
protected | function | Get redirect URL from the form's state. | |
WebformAjaxFormTrait:: |
protected | function | Get the form's Ajax wrapper id. | 1 |
WebformAjaxFormTrait:: |
protected | function | Determine if Ajax callback is callable. | |
WebformAjaxFormTrait:: |
protected | function | Is the current request for an Ajax modal/dialog. | |
WebformAjaxFormTrait:: |
protected | function | Is the current request for an off canvas dialog. | |
WebformAjaxFormTrait:: |
protected | function | Handle missing Ajax callback. | |
WebformAjaxFormTrait:: |
protected | function | Replace form via an Ajax response. | 1 |
WebformAjaxFormTrait:: |
protected | function | Reset announcements. | |
WebformAjaxFormTrait:: |
protected | function | Set announcements. | |
WebformAjaxFormTrait:: |
public | function | Submit form #ajax callback. | 1 |
WebformAjaxFormTrait:: |
public | function | Validate form #ajax callback. | 1 |
WebformDevelEntityFormApiBaseForm:: |
protected | property | The archiver manager. | |
WebformDevelEntityFormApiBaseForm:: |
protected | property | The webform element plugin manager. | |
WebformDevelEntityFormApiBaseForm:: |
protected | property | The webform submission generator service. | |
WebformDevelEntityFormApiBaseForm:: |
protected | property | The renderer. | |
WebformDevelEntityFormApiBaseForm:: |
protected | property | The webform token manager. | |
WebformDevelEntityFormApiBaseForm:: |
protected | property | An array of translatable properties. | |
WebformDevelEntityFormApiBaseForm:: |
protected | function | Cleanup webform elements. | |
WebformDevelEntityFormApiBaseForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
WebformDevelEntityFormApiBaseForm:: |
protected | function | Initialize WebformDevelEntityFormApiBaseForm object. | |
WebformDevelEntityFormApiBaseForm:: |
protected | function | Determine if an element property is translatable. | |
WebformDevelEntityFormApiBaseForm:: |
protected | function | Export a PHP render array. | |
WebformDevelEntityFormApiBaseForm:: |
protected | function | Outputs string representation of a variable using array short syntax. | |
WebformDevelEntityFormApiBaseForm:: |
protected | function | Wrap translatable value in <T> tags. | |
WebformDevelEntityFormApiTestForm:: |
public | function |
Form constructor. Overrides EntityForm:: |
|
WebformDevelEntityFormApiTestForm:: |
protected | function | Set webform elements default values using test data. | |
WebformDevelEntityFormApiTestForm:: |
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 EntityForm:: |
|
WebformDialogFormTrait:: |
protected | function | Add modal dialog support to a confirm form. | |
WebformDialogFormTrait:: |
protected | function | Build webform dialog delete link. | |
WebformDialogFormTrait:: |
protected | function | Add modal dialog support to a form. | |
WebformDialogFormTrait:: |
public | function |
Cancel form #ajax callback. Overrides WebformAjaxFormTrait:: |
1 |
WebformDialogFormTrait:: |
public | function | Close dialog. | |
WebformDialogFormTrait:: |
protected | function |
Returns if webform is using Ajax. Overrides WebformAjaxFormTrait:: |
1 |
WebformDialogFormTrait:: |
public | function |
Empty submit callback used to only have the submit button to use an #ajax submit callback. Overrides WebformAjaxFormTrait:: |
|
WebformDialogFormTrait:: |
public | function | Validate callback to clear validation errors. | 2 |