diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fbe0c8c..2c45b26c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,31 @@ before starting to add changes. Use example [placed in the end of the page](#exa - [OSF-55] DAWA Address-Matrikula (autocomplete) (required) - [OSF-56] DAWA Address-Matrikula (autocomplete) (value in XML-file) +## [3.9.0] 2023-08-22 + +- [OS-57] - SBSIP XML element - Computed TWIG + +## [3.8.3] 2023-08-17 + +- Fixed webform fetching from NemID Nemlogin link + +## [3.8.2] 2023-08-17 + +- Fixed webform fetching from NemID Nemlogin link + +## [3.8.1] 2023-08-02 + +- Fixed issue with wrong authorization provider used when multiple are enabled +- Fixed NemID fields populate caching issue + +## [3.8.0] 2023-07-12 + +- [S2FRMS-37] - PDF attachment elements choosing + +## [3.7.0] 2023-06-22 + +- [S2FRMS-18] - Fixing PDF styles + ## [3.6.0] 2023-06-07 - [OSF-25] added modules/os2forms_forloeb diff --git a/modules/os2forms_attachment/src/Element/AttachmentElement.php b/modules/os2forms_attachment/src/Element/AttachmentElement.php index 6957e9ec..05d37e4c 100644 --- a/modules/os2forms_attachment/src/Element/AttachmentElement.php +++ b/modules/os2forms_attachment/src/Element/AttachmentElement.php @@ -2,6 +2,7 @@ namespace Drupal\os2forms_attachment\Element; +use Drupal\webform\Entity\WebformSubmission; use Drupal\webform\WebformSubmissionInterface; use Drupal\webform_attachment\Element\WebformAttachmentBase; @@ -27,6 +28,9 @@ public function getInfo() { * {@inheritdoc} */ public static function getFileContent(array $element, WebformSubmissionInterface $webform_submission) { + // Override webform settings. + static::overrideWebformSettings($element, $webform_submission); + /** @var \Drupal\entity_print\Plugin\EntityPrintPluginManagerInterface $print_engine_manager */ $print_engine_manager = \Drupal::service('plugin.manager.entity_print.print_engine'); @@ -87,4 +91,50 @@ public static function getFileName(array $element, WebformSubmissionInterface $w } } + /** + * Overrides connected webform settings. + * + * Does that by creating a duplicate webform element with connected to a + * webform with the settings updated. + * + * @param array $element + * The webform attachment element. + * @param \Drupal\webform\WebformSubmissionInterface $webform_submission + * A webform submission. + */ + public static function overrideWebformSettings(array $element, WebformSubmissionInterface &$webform_submission) { + $webform = $webform_submission->getWebform(); + + // Rewriting webform settings. + $webform->setSetting('submission_excluded_elements', $element['#excluded_elements'] ?? FALSE); + $webform->setSetting('submission_exclude_empty', $element['#exclude_empty'] ?? FALSE); + $webform->setSetting('submission_exclude_empty_checkbox', $element['#exclude_empty_checkbox'] ?? FALSE); + + // Creating temporary submission to be able to swap original webform + // settings. + $webform_submission_temp = WebformSubmission::create([ + 'webform' => $webform, + 'entity_type' => $webform_submission->getEntityTypeId(), + 'entity_id' => $webform_submission->id(), + 'data' => $webform_submission->getData(), + ]); + // Clone ids. + $webform_submission_temp->set('serial', $webform_submission->get('serial')->value); + $webform_submission_temp->set('token', $webform_submission->get('token')->value); + // Clone states. + $webform_submission_temp->set('in_draft', $webform_submission->get('in_draft')->value); + $webform_submission_temp->set('current_page', $webform_submission->get('current_page')->value); + // Clone timestamps. + $webform_submission_temp->set('created', $webform_submission->get('created')->value); + $webform_submission_temp->set('changed', $webform_submission->get('changed')->value); + $webform_submission_temp->set('completed', $webform_submission->get('completed')->value); + // Clone admin notes, sticky, and locked. + $webform_submission_temp->set('notes', $webform_submission->get('notes')->value); + $webform_submission_temp->set('sticky', $webform_submission->get('sticky')->value); + $webform_submission_temp->set('sticky', $webform_submission->get('locked')->value); + + // Finalize cloning: swap the webform submission. + $webform_submission = $webform_submission_temp; + } + } diff --git a/modules/os2forms_attachment/src/Form/AttachmentComponentDeleteForm.php b/modules/os2forms_attachment/src/Form/AttachmentComponentDeleteForm.php index e3db6d10..123dc3e1 100644 --- a/modules/os2forms_attachment/src/Form/AttachmentComponentDeleteForm.php +++ b/modules/os2forms_attachment/src/Form/AttachmentComponentDeleteForm.php @@ -3,8 +3,8 @@ namespace Drupal\os2forms_attachment\Form; use Drupal\Core\Entity\EntityConfirmFormBase; -use Drupal\Core\Url; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; /** * Class AttachmentComponentDeleteForm. diff --git a/modules/os2forms_attachment/src/Form/AttachmentComponentForm.php b/modules/os2forms_attachment/src/Form/AttachmentComponentForm.php index b75010a7..05dd93a6 100644 --- a/modules/os2forms_attachment/src/Form/AttachmentComponentForm.php +++ b/modules/os2forms_attachment/src/Form/AttachmentComponentForm.php @@ -6,8 +6,8 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\webform\WebformTokenManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form handler for the Attachment component add and edit forms. diff --git a/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php b/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php index 27c42e1a..4f2215d6 100644 --- a/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php +++ b/modules/os2forms_attachment/src/Plugin/WebformElement/AttachmentElement.php @@ -27,6 +27,9 @@ protected function defineDefaultProperties() { 'view_mode' => 'html', 'template' => '', 'export_type' => '', + 'exclude_empty' => '', + 'exclude_empty_checkbox' => '', + 'excluded_elements' => '', ] + parent::defineDefaultProperties(); // PDF documents should never be trimmed. unset($properties['trim']); @@ -88,6 +91,34 @@ public function form(array $form, FormStateInterface $form_state) { // Set #access so that help is always visible. WebformElementHelper::setPropertyRecursive($form['attachment']['help'], '#access', TRUE); + // Elements. + $form['elements'] = [ + '#type' => 'details', + '#title' => $this->t('Included elements'), + '#description' => $this->t('The selected elements will be included in the [webform_submission:values] token. Individual values may still be printed if explicitly specified as a [webform_submission:values:?] in the email body template.'), + '#open' => $this->configuration['excluded_elements'] ? TRUE : FALSE, + ]; + $form['elements']['excluded_elements'] = [ + '#type' => 'webform_excluded_elements', + '#exclude_markup' => FALSE, + '#webform_id' => $this->webform->id(), + '#default_value' => $this->configuration['excluded_elements'], + ]; + $form['elements']['exclude_empty'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Exclude empty elements'), + '#description' => $this->t('If checked, empty elements will be excluded from the email values.'), + '#return_value' => TRUE, + '#default_value' => $this->configuration['exclude_empty'], + ]; + $form['elements']['exclude_empty_checkbox'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Exclude unselected checkboxes'), + '#description' => $this->t('If checked, empty checkboxes will be excluded from the email values.'), + '#return_value' => TRUE, + '#default_value' => $this->configuration['exclude_empty_checkbox'], + ]; + return $form; } diff --git a/modules/os2forms_consent/os2forms_consent.module b/modules/os2forms_consent/os2forms_consent.module index d48a5050..71bcdd69 100644 --- a/modules/os2forms_consent/os2forms_consent.module +++ b/modules/os2forms_consent/os2forms_consent.module @@ -5,8 +5,8 @@ * OS2Forms Consent functionality module. */ -use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\MigrateSourceInterface; +use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; use Symfony\Component\Yaml\Yaml; diff --git a/modules/os2forms_consent/src/Element/WebformAttachmentConsentXml.php b/modules/os2forms_consent/src/Element/WebformAttachmentConsentXml.php index 43344aa2..9f7eaa6f 100644 --- a/modules/os2forms_consent/src/Element/WebformAttachmentConsentXml.php +++ b/modules/os2forms_consent/src/Element/WebformAttachmentConsentXml.php @@ -2,9 +2,9 @@ namespace Drupal\os2forms_consent\Element; -use Drupal\webform\WebformSubmissionInterface; use Drupal\os2forms\Element\WebformAttachmentXml; use Drupal\os2forms_consent\Plugin\WebformElement\WebformAttachmentConsentXml as WebformElementAttachmentConsentXml; +use Drupal\webform\WebformSubmissionInterface; /** * Provides a 'webform_attachment_os2forms_consent_xml' element. diff --git a/modules/os2forms_forloeb/os2forms_forloeb.module b/modules/os2forms_forloeb/os2forms_forloeb.module index 1d70c116..4c5fac0d 100644 --- a/modules/os2forms_forloeb/os2forms_forloeb.module +++ b/modules/os2forms_forloeb/os2forms_forloeb.module @@ -5,17 +5,17 @@ * Install, update and uninstall functions for the os2forms_forloeb. */ -use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Entity\EntityInterface; -use Drupal\webform\WebformInterface; use Drupal\Core\Access\AccessResult; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\BubbleableMetadata; +use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\maestro\Engine\MaestroEngine; use Drupal\os2forms_forloeb\Plugin\EngineTasks\MaestroWebformInheritTask; -use Drupal\webform\Entity\WebformSubmission; use Drupal\user\Entity\User; +use Drupal\webform\Entity\WebformSubmission; +use Drupal\webform\WebformInterface; use Drupal\webform\WebformSubmissionInterface; /** diff --git a/modules/os2forms_forloeb/src/Controller/ForloebTaskConsoleController.php b/modules/os2forms_forloeb/src/Controller/ForloebTaskConsoleController.php index 5866b48c..8f2e95b0 100644 --- a/modules/os2forms_forloeb/src/Controller/ForloebTaskConsoleController.php +++ b/modules/os2forms_forloeb/src/Controller/ForloebTaskConsoleController.php @@ -5,12 +5,12 @@ use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\maestro\Engine\MaestroEngine; use Drupal\maestro\Utility\TaskHandler; use Drupal\os2forms_forloeb\ForloebTaskConsole; -use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RequestStack; diff --git a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroSelectContentTask.php b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroSelectContentTask.php index e2affa3e..64141120 100644 --- a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroSelectContentTask.php +++ b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroSelectContentTask.php @@ -2,15 +2,15 @@ namespace Drupal\os2forms_forloeb\Plugin\EngineTasks; -use Drupal\node\Entity\Node; -use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormState; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; -use Drupal\maestro\MaestroTaskTrait; +use Drupal\Core\Routing\TrustedRedirectResponse; +use Drupal\maestro\Engine\MaestroEngine; use Drupal\maestro\Form\MaestroExecuteInteractive; use Drupal\maestro\MaestroEngineTaskInterface; -use Drupal\maestro\Engine\MaestroEngine; -use Drupal\Core\Routing\TrustedRedirectResponse; +use Drupal\maestro\MaestroTaskTrait; +use Drupal\node\Entity\Node; /** * Maestro Select a Content Item. diff --git a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php index 5d6642a9..b33bf4b3 100644 --- a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php +++ b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformInheritTask.php @@ -2,13 +2,13 @@ namespace Drupal\os2forms_forloeb\Plugin\EngineTasks; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; +use Drupal\maestro\Engine\MaestroEngine; +use Drupal\maestro\Form\MaestroExecuteInteractive; +use Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask; use Drupal\webform\Entity\WebformSubmission; use Drupal\webform\WebformSubmissionForm; -use Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask; -use Drupal\maestro\Form\MaestroExecuteInteractive; -use Drupal\maestro\Engine\MaestroEngine; -use Drupal\Core\Form\FormStateInterface; use Drupal\webform\WebformSubmissionInterface; use Symfony\Component\HttpFoundation\RedirectResponse; diff --git a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformMultipleTask.php b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformMultipleTask.php index 6c33d25c..22c26a71 100644 --- a/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformMultipleTask.php +++ b/modules/os2forms_forloeb/src/Plugin/EngineTasks/MaestroWebformMultipleTask.php @@ -2,11 +2,11 @@ namespace Drupal\os2forms_forloeb\Plugin\EngineTasks; +use Drupal\maestro\Engine\MaestroEngine; +use Drupal\maestro\Form\MaestroExecuteInteractive; +use Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask; use Drupal\webform\Entity\WebformSubmission; use Drupal\webform\WebformSubmissionForm; -use Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask; -use Drupal\maestro\Form\MaestroExecuteInteractive; -use Drupal\maestro\Engine\MaestroEngine; /** * Maestro Webform Task Plugin for Multiple Submissions. diff --git a/modules/os2forms_nemid/src/Element/NemidNemloginLink.php b/modules/os2forms_nemid/src/Element/NemidNemloginLink.php index 8574ad47..e8f8563a 100644 --- a/modules/os2forms_nemid/src/Element/NemidNemloginLink.php +++ b/modules/os2forms_nemid/src/Element/NemidNemloginLink.php @@ -4,6 +4,7 @@ use Drupal\Core\Link as CoreLink; use Drupal\Core\Render\Element\Link; +use Drupal\webform\Entity\Webform; /** * Provides a render element for more. @@ -19,6 +20,8 @@ public static function preRenderLink($element) { /** @var \Drupal\os2web_nemlogin\Service\AuthProviderService $authProviderService */ $authProviderService = \Drupal::service('os2web_nemlogin.auth_provider'); + $route_name = \Drupal::routeMatch()->getRouteName(); + $nemlogin_link_login_text = NULL; if (isset($element['#nemlogin_link_login_text'])) { $nemlogin_link_login_text = $element['#nemlogin_link_login_text']; @@ -29,13 +32,40 @@ public static function preRenderLink($element) { $nemlogin_link_logout_text = $element['#nemlogin_link_logout_text']; } + /** @var \Drupal\webform\WebformInterface $webform */ + $webform = NULL; + + if ($route_name === 'entity.webform.canonical') { + $webform = \Drupal::request()->attributes->get('webform'); + } + elseif ($route_name == 'entity.node.canonical') { + $node = \Drupal::request()->attributes->get('node'); + $nodeType = $node->getType(); + + // Search if this node type is related with field of type 'webform'. + $webformFieldMap = \Drupal::service('entity_field.manager')->getFieldMapByFieldType('webform'); + if (isset($webformFieldMap['node'])) { + foreach ($webformFieldMap['node'] as $field_name => $field_meta) { + // We found field of type 'webform' in this node, let's try fetching + // the webform. + if (in_array($nodeType, $field_meta['bundles'])) { + if ($webformId = $node->get($field_name)->target_id) { + $webform = Webform::load($webformId); + break; + } + } + } + } + } + // Getting auth plugin ID override. $authPluginId = NULL; - /** @var \Drupal\webform\Entity\Webform $webform */ - $webform = \Drupal::request()->attributes->get('webform'); - $webformNemidSettings = $webform->getThirdPartySetting('os2forms', 'os2forms_nemid'); - if (isset($webformNemidSettings['session_type']) && !empty($webformNemidSettings['session_type'])) { - $authPluginId = $webformNemidSettings['session_type']; + + if ($webform) { + $webformNemidSettings = $webform->getThirdPartySetting('os2forms', 'os2forms_nemid'); + if (isset($webformNemidSettings['session_type']) && !empty($webformNemidSettings['session_type'])) { + $authPluginId = $webformNemidSettings['session_type']; + } } // Checking if we have a share webform route, if yes open link in a new @@ -44,7 +74,6 @@ public static function preRenderLink($element) { 'entity.webform.share_page', 'entity.webform.share_page.javascript', ]; - $route_name = \Drupal::routeMatch()->getRouteName(); $options = []; if (in_array($route_name, $webformShareRoutes)) { diff --git a/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php b/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php index 22cc78df..6297a076 100644 --- a/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php +++ b/modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php @@ -9,13 +9,13 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; -use Drupal\os2web_nemlogin\Service\AuthProviderService; use Drupal\os2forms_nemid\Form\SettingsForm; +use Drupal\os2web_nemlogin\Service\AuthProviderService; use Drupal\webform\Entity\Webform; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\KernelEvents; /** * Event subscriber subscribing to KernelEvents::REQUEST. @@ -147,6 +147,9 @@ public function redirectToNemlogin(GetResponseEvent $event) { return; } + // Killing cache on webform so that populated values are never cached. + $this->pageCacheKillSwitch->trigger(); + $webformNemidSettings = $webform->getThirdPartySetting('os2forms', 'os2forms_nemid'); // Getting nemlogin_auto_redirect setting. @@ -156,10 +159,6 @@ public function redirectToNemlogin(GetResponseEvent $event) { } // Checking if $nemlogin_auto_redirect is on. if ($nemlogin_auto_redirect) { - // Killing cache so that positive or negative redirect decision is not - // cached. - $this->pageCacheKillSwitch->trigger(); - // Getting auth plugin ID override. $authPluginId = NULL; if (isset($webformNemidSettings['session_type']) && !empty($webformNemidSettings['session_type'])) { @@ -171,7 +170,7 @@ public function redirectToNemlogin(GetResponseEvent $event) { if (!$authProviderPlugin->isAuthenticated()) { // Redirect directly to the external IdP. - $response = new RedirectResponse($this->nemloginAuthProvider->getLoginUrl()->toString()); + $response = new RedirectResponse($this->nemloginAuthProvider->getLoginUrl([], $authProviderPlugin->getPluginId())->toString()); $event->setResponse($response); $event->stopPropagation(); } diff --git a/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.module b/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.module index d63be5f6..79185ac9 100644 --- a/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.module +++ b/modules/os2forms_permissions_by_term/os2forms_permissions_by_term.module @@ -7,11 +7,11 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Session\AccountInterface; use Drupal\node\NodeInterface; use Drupal\views\Plugin\views\query\QueryPluginBase; use Drupal\views\ViewExecutable; use Drupal\webform\WebformInterface; -use Drupal\Core\Session\AccountInterface; /** * Implements hook_module_implements_alter(). diff --git a/modules/os2forms_sbsys/os2forms_sbsys.module b/modules/os2forms_sbsys/os2forms_sbsys.module index e2a66bd8..6c161633 100644 --- a/modules/os2forms_sbsys/os2forms_sbsys.module +++ b/modules/os2forms_sbsys/os2forms_sbsys.module @@ -5,8 +5,8 @@ * OS2Forms SBSYS functionality module. */ -use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\MigrateSourceInterface; +use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; use Symfony\Component\Yaml\Yaml; diff --git a/modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php b/modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php index b08fc042..b5a9db69 100644 --- a/modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php +++ b/modules/os2forms_sbsys/src/Element/WebformAttachmentSbsysXml.php @@ -2,9 +2,9 @@ namespace Drupal\os2forms_sbsys\Element; -use Drupal\webform\WebformSubmissionInterface; use Drupal\os2forms\Element\WebformAttachmentXml; use Drupal\os2forms_sbsys\Plugin\WebformElement\WebformAttachmentSbsysXml as WebformElementAttachmentSbsysXml; +use Drupal\webform\WebformSubmissionInterface; /** * Provides a 'webform_attachment_os2forms_sbsys_xml' element. diff --git a/modules/os2forms_sbsys/src/Plugin/WebformElement/WebformAttachmentSbsysXml.php b/modules/os2forms_sbsys/src/Plugin/WebformElement/WebformAttachmentSbsysXml.php index aa7ebbce..4fde7727 100644 --- a/modules/os2forms_sbsys/src/Plugin/WebformElement/WebformAttachmentSbsysXml.php +++ b/modules/os2forms_sbsys/src/Plugin/WebformElement/WebformAttachmentSbsysXml.php @@ -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; /** @@ -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, diff --git a/os2forms.module b/os2forms.module index eb42f898..1357b459 100644 --- a/os2forms.module +++ b/os2forms.module @@ -5,10 +5,10 @@ * OS2Forms functionality module. */ -use Drupal\migrate\Plugin\MigrationInterface; +use Drupal\Core\Form\FormStateInterface; use Drupal\migrate\Plugin\MigrateSourceInterface; +use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; -use Drupal\Core\Form\FormStateInterface; /** * Implements hook_entity_type_build(). diff --git a/src/Plugin/WebformHandler/SaveToFileWebformHandler.php b/src/Plugin/WebformHandler/SaveToFileWebformHandler.php index d2f16107..fcb783fa 100644 --- a/src/Plugin/WebformHandler/SaveToFileWebformHandler.php +++ b/src/Plugin/WebformHandler/SaveToFileWebformHandler.php @@ -5,9 +5,9 @@ use Drupal\Component\Serialization\Json; use Drupal\Core\File\Exception\FileWriteException; use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\Core\Serialization\Yaml; -use Drupal\Core\Form\FormStateInterface; use Drupal\file\Entity\File; use Drupal\webform\Element\WebformMessage; use Drupal\webform\Plugin\WebformElement\BooleanBase;