Skip to content

Commit

Permalink
Merge pull request #1104 from USEPA/EPAD8-2111-media-wysiwyg-missing-…
Browse files Browse the repository at this point in the history
…web-area

[EPAD8-2111] [MAIN] Media uploaded through WYSIWYG missing web area
  • Loading branch information
carsoncho authored May 24, 2023
2 parents 2126627 + cc0e0d9 commit cf6669d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
3 changes: 2 additions & 1 deletion services/drupal/composer.patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@
"Prevent the reuse of embedded paragraphs": "https://www.drupal.org/files/issues/2020-04-30/paragraphs_entity_embed-single_use-3132549-2.patch",
"Allow modal to be larger": "https://www.drupal.org/files/issues/2021-10-22/paragraphs_entity_embed-dialog_too_small-3117524-5.patch",
"Allow use of buttons for selecting paragraph type": "https://www.drupal.org/files/issues/2020-04-30/paragraphs_entity_embed-add_mode-3089674-3.patch",
"Make compatible with new security in embed module": "https://www.drupal.org/files/issues/2022-05-27/paragraphs_entity_embed_csrf_token.patch"
"Make compatible with new security in embed module": "https://www.drupal.org/files/issues/2022-05-27/paragraphs_entity_embed_csrf_token.patch",
"Add openerParameters": "patches/drupalparagraph_add_opener_parameters-rolled-with-3004077-7-and-3117524-5-and-csrf_token-patch.patch"
},
"drupal/linked_field": {
"Generate relative links rather than absolute": "https://www.drupal.org/files/issues/2020-05-22/linked_field-relative-destination-url-3139179-1-D8.patch"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
diff --git a/js/plugins/drupalparagraph/plugin.js b/js/plugins/drupalparagraph/plugin.js
index f90864f..0f06666 100644
--- a/js/plugins/drupalparagraph/plugin.js
+++ b/js/plugins/drupalparagraph/plugin.js
@@ -77,6 +77,9 @@
if ('data-paragraph-revision-id' in existingValues) {
url = url + '/' + existingValues['data-paragraph-revision-id']
}
+
+ url = url + "?" + editor.config.DrupalParagraph_openerParameters;
+
// Open the Paragraph embed dialog for corresponding EmbedButton.
Drupal.ckeditor.openDialog(editor, url, existingValues, paragraphSaveCallback, dialogSettings);
}
diff --git a/src/Plugin/CKEditorPlugin/DrupalParagraph.php b/src/Plugin/CKEditorPlugin/DrupalParagraph.php
index 249ced2..0540944 100644
--- a/src/Plugin/CKEditorPlugin/DrupalParagraph.php
+++ b/src/Plugin/CKEditorPlugin/DrupalParagraph.php
@@ -2,6 +2,7 @@

namespace Drupal\paragraphs_entity_embed\Plugin\CKEditorPlugin;

+use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\editor\Entity\Editor;
use Drupal\embed\EmbedCKEditorPluginBase;

@@ -16,6 +17,25 @@ use Drupal\embed\EmbedCKEditorPluginBase;
*/
class DrupalParagraph extends EmbedCKEditorPluginBase {

+ /**
+ * The current route match.
+ *
+ * @var \Drupal\Core\Routing\RouteMatchInterface
+ */
+ protected $currentRouteMatch;
+
+ /**
+ * Get the current route match.
+ *
+ * @return \Drupal\Core\Routing\RouteMatchInterface
+ */
+ protected function getCurrentRouteMatch() {
+ if (!$this->currentRouteMatch) {
+ $this->currentRouteMatch = \Drupal::routeMatch();
+ }
+ return $this->currentRouteMatch;
+ }
+
/**
* {@inheritdoc}
*/
@@ -27,11 +47,21 @@ class DrupalParagraph extends EmbedCKEditorPluginBase {
* {@inheritdoc}
*/
public function getConfig(Editor $editor) {
+ $opener_parameters = ['entity_type_id' => '', 'entity_bundle' => ''];
+ foreach ($this->getCurrentRouteMatch()->getParameters()->all() as $parameter) {
+ if ($parameter instanceof ContentEntityInterface) {
+ $opener_parameters['entity_type_id'] = $parameter->getEntityTypeId();
+ $opener_parameters['entity_bundle'] = $parameter->bundle();
+ break;
+ }
+ }
+
return [
'DrupalParagraph_dialogTitleAdd' => t('Insert Paragraph'),
'DrupalParagraph_dialogTitleEdit' => t('Edit Paragraph'),
'DrupalParagraph_buttons' => $this->getButtons(),
'DrupalParagraph_previewCsrfToken' => \Drupal::csrfToken()->get('X-Drupal-EmbedPreview-CSRF-Token'),
+ 'DrupalParagraph_openerParameters' => http_build_query($opener_parameters),
];
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\group\Entity\Group;
use Drupal\group\Entity\GroupContent;
use Drupal\group\Entity\GroupInterface;
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
Expand Down Expand Up @@ -197,6 +198,16 @@ function epa_web_areas_form_media_library_add_form_alter(&$form, FormStateInterf
}
}

/**
* Implements hook_form_FORM_ID_alter().
*/
function epa_web_areas_form_embedded_paragraphs_paragraphs_entity_embed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Add a custom submit handler that runs after media is added and saved.
if (!empty($form['actions'])) {
$form['#submit'][] = 'epa_web_areas_group_media_submit';
}
}

/**
* Implements hook_editor_js_settings_alter().
*/
Expand Down Expand Up @@ -229,6 +240,12 @@ function epa_web_areas_editor_js_settings_alter(&$settings) {
}
}

$query = \Drupal::request()->query->all();
if (empty($group) && isset($query['opener_parameters']['group'])) {
$group_id = $query['opener_parameters']['group'];
$group = Group::load($group_id);
}

// If we have a group object, add group id as a query parameter
// to the opener parameters and rebuild query for media library
// ckeditor widgets. The MediaLibraryState will preserve the group id.
Expand All @@ -252,6 +269,15 @@ function epa_web_areas_editor_js_settings_alter(&$settings) {
$url = implode('?', [$parts['path'], $query]);
$settings['editor']['formats'][$format]['editorSettings'][$key] = $url;
}

// Add group ID as query parameter for DrupalParagraph entity embed.
if ($key == 'DrupalParagraph_openerParameters') {
$parts = parse_url($value);
parse_str($parts['path'], $query);
$query['opener_parameters']['group'] = $group->id();
$out = http_build_query($query);
$settings['editor']['formats'][$format]['editorSettings'][$key] = $out;
}
}
}
}
Expand Down

0 comments on commit cf6669d

Please sign in to comment.