protected function WebformDevelEntityFormApiExportForm::getPhpTemplate in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_devel/src/Form/WebformDevelEntityFormApiExportForm.php \Drupal\webform_devel\Form\WebformDevelEntityFormApiExportForm::getPhpTemplate()
Get the form's PHP template.
Return value
string The form's PHP template.
1 call to WebformDevelEntityFormApiExportForm::getPhpTemplate()
- WebformDevelEntityFormApiExportForm::buildForm in modules/
webform_devel/ src/ Form/ WebformDevelEntityFormApiExportForm.php - Form constructor.
File
- modules/
webform_devel/ src/ Form/ WebformDevelEntityFormApiExportForm.php, line 215
Class
- WebformDevelEntityFormApiExportForm
- Export a webform's element to Form API (FAPI).
Namespace
Drupal\webform_devel\FormCode
protected function getPhpTemplate() {
return <<<'EOT'
<?php
namespace Drupal\{{ name }}\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* {{ label }} configuration settings form.
*/
class {{ class_name }}SettingsForm extends ConfigFormBase {
/**
* The webform token manager.
*
* @var \Drupal\webform\WebformTokenManagerInterface
*/
protected $tokenManager;
/**
* The webform element plugin manager.
*
* @var \Drupal\webform\Plugin\WebformElementManagerInterface
*/
protected $elementManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance->tokenManager = $container->get('webform.token_manager');
$instance->elementManager = $container->get('plugin.manager.webform.element');
return $instance;
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return '{{ name }}_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['{{ name }}.settings'];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('{{ name }}.settings');
{{ form }}
// Process elements.
$this->elementManager->processElements($form);
// Replace tokens.
$form = $this->tokenManager->replace($form);
// 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 $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Get all values.
$values = $form_state->getValues();
// Remove Form API values.
unset(
$values['form_build_id'],
$values['form_token'],
$values['form_id'],
$values['op'],
$values['actions']
);
// Save config.
$this->config('{{ name }}.settings')
->setData($values)
->save();
// Display message.
parent::submitForm($form, $form_state);
}
}
EOT;
}