Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
stankut authored Aug 23, 2023
2 parents 1bf6e04 + 1da8ba5 commit 0f96a9c
Show file tree
Hide file tree
Showing 20 changed files with 190 additions and 64 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions modules/os2forms_attachment/src/Element/AttachmentElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\os2forms_attachment\Element;

use Drupal\webform\Entity\WebformSubmission;
use Drupal\webform\WebformSubmissionInterface;
use Drupal\webform_attachment\Element\WebformAttachmentBase;

Expand All @@ -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');

Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/os2forms_consent/os2forms_consent.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions modules/os2forms_forloeb/os2forms_forloeb.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
41 changes: 35 additions & 6 deletions modules/os2forms_nemid/src/Element/NemidNemloginLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'];
Expand All @@ -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
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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'])) {
Expand All @@ -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();
}
Expand Down
Loading

0 comments on commit 0f96a9c

Please sign in to comment.