YamlFormMarkupBase.php in YAML Form 8
File
src/Plugin/YamlFormElement/YamlFormMarkupBase.php
View source
<?php
namespace Drupal\yamlform\Plugin\YamlFormElement;
use Drupal\Core\Form\FormStateInterface;
use Drupal\yamlform\YamlFormElementBase;
use Drupal\yamlform\YamlFormSubmissionInterface;
abstract class YamlFormMarkupBase extends YamlFormElementBase {
public function isInput(array $element) {
return FALSE;
}
public function isContainer(array $element) {
return TRUE;
}
public function getDefaultProperties() {
return [
'display_on' => 'form',
] + $this
->getDefaultBaseProperties();
}
public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
parent::prepare($element, $yamlform_submission);
if (isset($element['#display_on']) && $element['#display_on'] == 'view') {
$element['#access'] = FALSE;
}
}
public function buildHtml(array &$element, $value, array $options = []) {
if (empty($element['#display_on']) || $element['#display_on'] == 'form') {
return [];
}
if (is_array($value)) {
$element = $value + $element;
}
return $element;
}
public function buildText(array &$element, $value, array $options = []) {
if (empty($element['#display_on']) || $element['#display_on'] == 'form') {
return [];
}
unset($element['#prefix'], $element['#suffix']);
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' => [
'form' => t('form only'),
'display' => t('viewed submission only'),
'both' => t('both form and viewed submission'),
],
];
return $form;
}
}