WebformExampleElement.php in Webform 8.5
Same filename in this branch
Same filename and directory in other branches
File
modules/webform_example_element/src/Plugin/WebformElement/WebformExampleElement.phpView source
<?php
namespace Drupal\webform_example_element\Plugin\WebformElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformElementBase;
use Drupal\webform\WebformSubmissionInterface;
/**
* Provides a 'webform_example_element' element.
*
* @WebformElement(
* id = "webform_example_element",
* label = @Translation("Webform example element"),
* description = @Translation("Provides a webform element example."),
* category = @Translation("Example elements"),
* )
*
* @see \Drupal\webform_example_element\Element\WebformExampleElement
* @see \Drupal\webform\Plugin\WebformElementBase
* @see \Drupal\webform\Plugin\WebformElementInterface
* @see \Drupal\webform\Annotation\WebformElement
*/
class WebformExampleElement extends WebformElementBase {
/**
* {@inheritdoc}
*/
protected function defineDefaultProperties() {
// Here you define your webform element's default properties,
// which can be inherited.
//
// @see \Drupal\webform\Plugin\WebformElementBase::defaultProperties
// @see \Drupal\webform\Plugin\WebformElementBase::defaultBaseProperties
return [
'multiple' => '',
'size' => '',
'minlength' => '',
'maxlength' => '',
'placeholder' => '',
] + parent::defineDefaultProperties();
}
/****************************************************************************/
/**
* {@inheritdoc}
*/
public function prepare(array &$element, WebformSubmissionInterface $webform_submission = NULL) {
parent::prepare($element, $webform_submission);
// Here you can customize the webform element's properties.
// You can also customize the form/render element's properties via the
// FormElement.
//
// @see \Drupal\webform_example_element\Element\WebformExampleElement::processWebformElementExample
}
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
// Here you can define and alter a webform element's properties UI.
// Form element property visibility and default values are defined via
// ::defaultProperties.
//
// @see \Drupal\webform\Plugin\WebformElementBase::form
// @see \Drupal\webform\Plugin\WebformElement\TextBase::form
return $form;
}
}
Classes
Name | Description |
---|---|
WebformExampleElement | Provides a 'webform_example_element' element. |