Verified Commit 1ed197bc authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3504582 by artem_sylchuk, nod_, smustgrave, reinfate, anjaliprasannan,...

Issue #3504582 by artem_sylchuk, nod_, smustgrave, reinfate, anjaliprasannan, alexdoma: [regression] Tags td, tr or th ignored by new parseHTML implementation

(cherry picked from commit fa598067)
parent f0525143
Loading
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -1335,14 +1335,16 @@
      // Parse response.data into an element collection.
      const parseHTML = (htmlString) => {
        const fragment = document.createDocumentFragment();
        // Create a temporary div element
        const tempDiv = fragment.appendChild(document.createElement('div'));
        // Create a temporary template element.
        const template = fragment.appendChild(
          document.createElement('template'),
        );

        // Set the innerHTML of the div to the provided HTML string
        tempDiv.innerHTML = htmlString;
        // Set the innerHTML of the template to the provided HTML string.
        template.innerHTML = htmlString;

        // Return the contents of the temporary div
        return tempDiv.childNodes;
        // Return the contents of the temporary template.
        return template.content.childNodes;
      };

      let $newContent = $(parseHTML(response.data));
+7 −0
Original line number Diff line number Diff line
@@ -43,6 +43,13 @@ ajax_test.insert_links_inline_wrapper:
  requirements:
    _access: 'TRUE'

ajax_test.insert_links_table_wrapper:
  path: '/ajax-test/insert-table-wrapper'
  defaults:
    _controller: '\Drupal\ajax_test\Controller\AjaxTestController::insertLinksTableWrapper'
  requirements:
    _access: 'TRUE'

ajax_test.dialog_close:
  path: '/ajax-test/dialog-close'
  defaults:
+31 −0
Original line number Diff line number Diff line
@@ -138,6 +138,36 @@ public function insertLinksInlineWrapper() {
    return $build;
  }

  /**
   * Returns a render array of links that directly Drupal.ajax().
   *
   * @return array
   *   Renderable array of AJAX response contents.
   */
  public function insertLinksTableWrapper(): array {
    $build['links'] = [
      'ajax_target' => [
        '#markup' => '<div class="ajax-target-wrapper"><table><tbody id="ajax-target"></tbody></table></div>',
      ],
      'links' => [
        '#theme' => 'links',
        '#attached' => ['library' => ['ajax_test/ajax_insert']],
      ],
    ];

    $build['links']['links']['#links']['table-row'] = [
      'title' => 'Link table-row',
      'url' => Url::fromRoute('ajax_test.ajax_render_types', ['type' => 'table-row']),
      'attributes' => [
        'class' => ['ajax-insert'],
        'data-method' => 'html',
        'data-effect' => 'none',
      ],
    ];

    return $build;
  }

  /**
   * Returns a render array that will be rendered by AjaxRenderer.
   *
@@ -334,6 +364,7 @@ protected function getRenderTypes() {
      'comment-not-wrapped' => '<!-- COMMENT --><div class="comment-not-wrapped">comment-not-wrapped</div>',
      'svg' => '<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><rect x="0" y="0" height="10" width="10" fill="green"></rect></svg>',
      'empty' => '',
      'table-row' => '<tr><td>table-row</td></tr>',
    ];
    $render_multiple_root = [
      'mixed' => ' foo <!-- COMMENT -->  foo bar<div class="a class"><p>some string</p></div> additional not wrapped strings, <!-- ANOTHER COMMENT --> <p>final string</p>',
+6 −0
Original line number Diff line number Diff line
@@ -157,6 +157,12 @@ public function testInsertAjaxResponse(): void {
JS;
    $expected = '<div class="div-wrapper-forever"></div>';
    $this->assertInsert('empty', $expected, $custom_wrapper_new_content);

    // Checking inserting table elements.
    $expected = '<tr><td>table-row</td></tr>';
    $this->drupalGet('ajax-test/insert-table-wrapper');
    $this->clickLink('Link table-row');
    $this->assertWaitPageContains('<div class="ajax-target-wrapper"><table><tbody id="ajax-target">' . $expected . '</tbody></table></div>');
  }

  /**