-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DP-36788 Add support for
gf_token
in Mass Forms iframe URLs
Implemented logic to append the `gf_token` query parameter to iframe URLs on form page nodes in full view mode. Added Mass Forms ddev domain to the list of allowed domains.
- Loading branch information
1 parent
ea6f1fa
commit 35f3b13
Showing
5 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# Write your changelog entry here. Every pull request must have a changelog yml file. | ||
# | ||
# Change types: | ||
# ############################################################################# | ||
# You can use one of the following types: | ||
# - Added: For new features. | ||
# - Changed: For changes to existing functionality. | ||
# - Deprecated: For soon-to-be removed features. | ||
# - Removed: For removed features. | ||
# - Fixed: For any bug fixes. | ||
# - Security: In case of vulnerabilities. | ||
# | ||
# Format | ||
# ############################################################################# | ||
# The format is crucial. Please follow the examples below. For reference, the requirements are: | ||
# - All 3 parts are required and you must include "Type", "description" and "issue". | ||
# - "Type" must be left aligned and followed by a colon. | ||
# - "description" must be indented with 2 spaces followed by a colon | ||
# - "issue" must be indented with 4 spaces followed by a colon. | ||
# - "issue" is for the Jira ticket number only e.g. DP-1234 | ||
# - No extra spaces, indents, or blank lines are allowed. | ||
# | ||
# Example: | ||
# ############################################################################# | ||
# Fixed: | ||
# - description: Fixes scrolling on edit pages in Safari. | ||
# issue: DP-13314 | ||
# | ||
# You may add more than 1 description & issue for each type using the following format: | ||
# Changed: | ||
# - description: Automating the release branch. | ||
# issue: DP-10166 | ||
# - description: Second change item that needs a description. | ||
# issue: DP-19875 | ||
# - description: Third change item that needs a description along with an issue. | ||
# issue: DP-19843 | ||
# | ||
Added: | ||
- description: Posibility to route the `gf_token` request paramater to Mass Forms iframe URL if it exists in the request. | ||
issue: DP-36788 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
docroot/modules/custom/mass_utility/src/EntityViewBuildAlterGravityFormToken.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Drupal\mass_utility; | ||
|
||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; | ||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface; | ||
use Drupal\Core\Entity\EntityInterface; | ||
use Drupal\Core\Url; | ||
use Drupal\node\NodeInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
/** | ||
* Class EntityViewBuildAlterGravityFormToken. | ||
* | ||
* This class provides functionality to alter the render array of an entity. | ||
* It injects a `gf_token` query parameter into an iframe URL for nodes of a | ||
* specific type and view mode. | ||
*/ | ||
class EntityViewBuildAlterGravityFormToken implements ContainerInjectionInterface { | ||
|
||
/** | ||
* @var \Symfony\Component\HttpFoundation\RequestStack | ||
*/ | ||
private RequestStack $requestStack; | ||
|
||
/** | ||
* Alters the render array of a specified entity. | ||
* | ||
* @param array $build | ||
* The render array of the entity to be altered, passed by reference. | ||
* @param EntityInterface $entity | ||
* The entity object being rendered. | ||
* @param EntityViewDisplayInterface $display | ||
* The display configuration for the entity's view mode. | ||
* | ||
* @return void | ||
* This method does not return a value, it alters the render array by reference. | ||
*/ | ||
public function alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) { | ||
if ($entity instanceof NodeInterface | ||
&& $entity->bundle() == 'form_page' | ||
&& $build['#view_mode'] == 'full') { | ||
if (empty($build["field_form_url"][0]["#url"])) { | ||
return; | ||
} | ||
|
||
$iframe_url = $build["field_form_url"][0]["#url"]; | ||
if (!($iframe_url instanceof Url)) { | ||
return; | ||
} | ||
|
||
$build["field_form_url"]["iframe_url"] = $iframe_url->toString(); | ||
|
||
$gf_token = $this->requestStack->getCurrentRequest()->get('gf_token'); | ||
if (empty($gf_token)) { | ||
return; | ||
} | ||
|
||
$iframe_url->setOption('query', ['gf_token' => $gf_token]); | ||
|
||
$build["field_form_url"]["iframe_url"] = $iframe_url->toString(); | ||
} | ||
} | ||
|
||
/** | ||
* Constructs a EntityViewBuildAlterGravityFormToken object. | ||
* | ||
* @param RequestStack $request_stack | ||
* The RequestStack service. | ||
*/ | ||
public function __construct(RequestStack $request_stack) { | ||
$this->requestStack = $request_stack; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
return new static($container->get('request_stack')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters