WebformComposite.php in Webform Composite Tools 8
File
src/Plugin/WebformElement/WebformComposite.php
View source
<?php
namespace Drupal\webform_composite\Plugin\WebformElement;
use Drupal\webform\WebformSubmissionInterface;
use Drupal\webform\Plugin\WebformElement\WebformCompositeBase;
class WebformComposite extends WebformCompositeBase {
private $compositeDefinition;
public function initializeCompositeElements(array &$element) {
$class = $this
->getFormElementClassDefinition();
$element['#webform_composite_elements'] = $class::initializeCompositeElements($element);
if (method_exists($this, 'initializeCompositeElementsRecursive')) {
$this
->initializeCompositeElementsRecursive($element, $element['#webform_composite_elements']);
}
}
public function getCompositeDefinition() {
if (!isset($this->compositeDefinition)) {
$this->compositeDefinition = $this->entityTypeManager
->getStorage($this
->getBaseId())
->load($this
->getDerivativeId());
}
return $this->compositeDefinition;
}
public function preview() {
return [
'#type' => $this
->getBaseId(),
'#webform_composite' => $this
->getPluginId(),
'#title' => $this
->getPluginLabel(),
];
}
public function finalize(array &$element, WebformSubmissionInterface $webform_submission = NULL) {
parent::finalize($element, $webform_submission);
if ($element['#type'] === $this
->getPluginId()) {
$base_id = $this
->getBaseId();
$element['#type'] = $base_id;
$element['#' . $base_id] = $this
->getPluginId();
}
elseif ($element['#type'] === 'webform_multiple' && empty($element['#multiple__header'])) {
if (isset($element['#element']['#type']) && $element['#element']['#type'] === $this
->getPluginId()) {
$base_id = $this
->getBaseId();
$element['#element']['#type'] = $base_id;
$element['#element']['#' . $base_id] = $this
->getPluginId();
}
}
}
public function getCompositeElements() {
return $this
->getCompositeDefinition()
->getElementsDecoded();
}
}