Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS-57 SBSIP XML element - Computed TWIG #54

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ before starting to add changes. Use example [placed in the end of the page](#exa

## [Unreleased]

- [OS-57] - SBSIP XML element - Computed TWIG

## [3.8.3] 2023-08-17

- Fixed webform fetching from NemID Nemlogin link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Form\FormStateInterface;
use Drupal\os2forms\Plugin\WebformElement\WebformAttachmentXml;
use Drupal\os2forms_nemid\Plugin\WebformElement\NemidElementBase;
use Drupal\webform\Plugin\WebformElement\DateBase;
use Drupal\webform\Plugin\WebformElement\TextBase;
use Drupal\webform\Plugin\WebformElement\WebformComputedBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand Down Expand Up @@ -110,31 +114,19 @@ public function form(array $form, FormStateInterface $form_state) {
$elements = $webform->getElementsInitializedAndFlattened();
$element_options = ['' => $this->t('None')];
foreach ($elements as $element_key => $element) {
$element_plugin = $this->elementManager->getElementInstance($element);
$allowed_elements = [
'textfield',
'select',
'email',
'os2forms_nemid_cpr',
'os2forms_nemid_name',
'os2forms_nemid_pid',
'os2forms_nemid_address',
'os2forms_nemid_coaddress',
'os2forms_nemid_zipcode',
'os2forms_nemid_city',
'os2forms_nemid_company_cvr',
'os2forms_nemid_company_name',
'os2forms_nemid_company_address',
'os2forms_nemid_company_city',
'os2forms_nemid_company_rid',
'date',
];
if (!$element_plugin->isInput($element)
|| !isset($element['#type'])
|| !in_array($element['#type'], $allowed_elements)
|| $element_plugin->hasMultipleValues($element)) {
$elementInstance = $this->elementManager->getElementInstance($element);

// Skipping if not input or has multiple values.
if (!$elementInstance->isInput($element)
|| $elementInstance->hasMultipleValues($element)) {
continue;
}

// Skipping if is of type we do not support.
if (!$elementInstance instanceof TextBase && !$elementInstance instanceof NemidElementBase && !$elementInstance instanceof DateBase && !$elementInstance instanceof WebformComputedBase) {
continue;
}

$element_options[$element_key] = (isset($element['#title'])) ? new FormattableMarkup('@title (@key)', [
'@title' => $element['#title'],
'@key' => $element_key,
Expand Down