Created
February 25, 2025 16:06
-
-
Save Spurlos/80fc871ff37b6b1ad0c5d21b7c16b4b7 to your computer and use it in GitHub Desktop.
Paragraph entity embeds convertion to AJAX
This file contains hidden or 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
| async _loadPreview(modelElement) { | |
| return new Promise((resolve, reject) => { | |
| const query = { | |
| text: this._renderElement(modelElement), | |
| }; | |
| const ajaxSettings = { | |
| url: Drupal.url('embed/preview/' + this.options.format + '?' + new URLSearchParams(query)), | |
| // element: modelElement, | |
| submit: { text: query.text }, | |
| error: function () { | |
| reject({ label: this.labelError, preview: this.previewError }); | |
| }, | |
| beforeSend: (jqXHR) => { | |
| jqXHR.setRequestHeader('X-Drupal-EmbedPreview-CSRF-Token', this.options.previewCsrfToken); | |
| } | |
| }; | |
| // Create the AJAX instance | |
| const ajax = new Drupal.ajax(ajaxSettings); | |
| // const originalSuccess = ajax.success; | |
| ajax.success = function (response, status) { | |
| Drupal.Ajax.prototype.success.call(ajax, response, status); | |
| const label = Drupal.t('Paragraph embed widget'); | |
| resolve({ label, preview: response[3].data }); | |
| }; | |
| // Execute the AJAX request | |
| ajax.execute(); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment