WebformMarkupBase.php in Webform 6.x
File
src/Plugin/WebformElement/WebformMarkupBase.php
View source
<?php
namespace Drupal\webform\Plugin\WebformElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformElementBase;
use Drupal\webform\Plugin\WebformElementDisplayOnInterface;
use Drupal\webform\WebformSubmissionInterface;
abstract class WebformMarkupBase extends WebformElementBase implements WebformElementDisplayOnInterface {
use WebformDisplayOnTrait;
protected function defineDefaultProperties() {
return [
'display_on' => WebformElementDisplayOnInterface::DISPLAY_ON_FORM,
] + $this
->defineDefaultBaseProperties();
}
protected function defineDefaultBaseProperties() {
$properties = parent::defineDefaultBaseProperties();
unset($properties['prepopulate'], $properties['states_clear']);
return $properties;
}
public function isInput(array $element) {
return FALSE;
}
public function isContainer(array $element) {
return FALSE;
}
public function prepare(array &$element, WebformSubmissionInterface $webform_submission = NULL) {
parent::prepare($element, $webform_submission);
if ($this
->hasProperty('display_on') && !$this
->isDisplayOn($element, WebformElementDisplayOnInterface::DISPLAY_ON_FORM)) {
$element['#access'] = FALSE;
}
if ($this
->hasProperty('wrapper_attributes')) {
$element['#theme_wrappers'][] = 'form_element';
}
}
public function buildHtml(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
if (!$this
->isDisplayOn($element, WebformElementDisplayOnInterface::DISPLAY_ON_VIEW)) {
return [];
}
if ($this
->isContainer($element)) {
$view_builder = $this->entityTypeManager
->getViewBuilder('webform_submission');
$value = $view_builder
->buildElements($element, $webform_submission, $options, 'html');
if (is_array($value)) {
$element = $value + $element;
}
}
return $element;
}
public function buildText(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
if (!$this
->isDisplayOn($element, WebformElementDisplayOnInterface::DISPLAY_ON_VIEW)) {
return [];
}
if ($this
->isContainer($element)) {
unset($element['#prefix'], $element['#suffix']);
$view_builder = $this->entityTypeManager
->getViewBuilder('webform_submission');
$value = $view_builder
->buildElements($element, $webform_submission, $options, 'text');
if (is_array($value)) {
$element = $value + $element;
}
}
return $element;
}
public function getRelatedTypes(array $element) {
return [];
}
public function getElementSelectorOptions(array $element) {
return [];
}
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['markup'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Markup settings'),
];
$form['markup']['display_on'] = [
'#type' => 'select',
'#title' => $this
->t('Display on'),
'#options' => $this
->getDisplayOnOptions(),
];
return $form;
}
}