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;
class WebformHorizontalRule extends WebformElementBase implements WebformElementDisplayOnInterface {
use WebformDisplayOnTrait;
protected function defineDefaultProperties() {
return [
'states' => [],
'attributes' => [],
'display_on' => WebformElementDisplayOnInterface::DISPLAY_ON_FORM,
];
}
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
->isDisplayOn($element, WebformElementDisplayOnInterface::DISPLAY_ON_FORM)) {
$element['#access'] = FALSE;
}
}
public function buildHtml(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
if (!$this
->isDisplayOn($element, WebformElementDisplayOnInterface::DISPLAY_ON_VIEW)) {
return [];
}
return $element;
}
public function buildText(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
if (!$this
->isDisplayOn($element, WebformElementDisplayOnInterface::DISPLAY_ON_VIEW)) {
return [];
}
return [
'#plain_text' => PHP_EOL . '---' . PHP_EOL,
];
}
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['horizontal_rule'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Horizontal rule settings'),
];
$form['horizontal_rule']['display_on'] = [
'#type' => 'select',
'#title' => $this
->t('Display on'),
'#options' => $this
->getDisplayOnOptions(),
];
$form['horizontal_rule_attributes'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Horizontal rule attributes'),
];
$form['horizontal_rule_attributes']['attributes'] = [
'#type' => 'webform_element_attributes',
'#title' => $this
->t('Horizontal rule'),
'#classes' => $this->configFactory
->get('webform.settings')
->get('element.horizontal_rule_classes'),
];
unset($form['element_attributes']['attributes']);
return $form;
}
public function preview() {
return [
'#type' => $this
->getTypeName(),
'#attributes' => [
'class' => [
'webform-horizontal-rule--dotted',
'webform-horizontal-rule--thick',
],
],
];
}
}