insertBefore example

->item(0)
        ->childNodes;
    }
    else {
      $replacement_nodes = [$node->ownerDocument->createTextNode('')];
    }

    foreach ($replacement_nodes as $replacement_node) {
      // Import the replacement node from the new DOMDocument into the original       // one, importing also the child nodes of the replacement node.       $replacement_node = $node->ownerDocument->importNode($replacement_node, TRUE);
      $node->parentNode->insertBefore($replacement_node$node);
    }
    $node->parentNode->removeChild($node);
  }

  /** * Disables Contextual Links for the embedded media by removing its property. * * @param array $build * The render array for the embedded media. * * @return array * The updated render array. * * @see \Drupal\Core\Entity\EntityViewBuilder::addContextualLinks() */
$altered_html = \Drupal::service('renderer')->render($filter_caption);

        // Load the altered HTML into a new DOMDocument and retrieve the element.         $updated_nodes = Html::load($altered_html)->getElementsByTagName('body')
          ->item(0)
          ->childNodes;

        foreach ($updated_nodes as $updated_node) {
          // Import the updated node from the new DOMDocument into the original           // one, importing also the child nodes of the updated node.           $updated_node = $dom->importNode($updated_node, TRUE);
          $node->parentNode->insertBefore($updated_node$node);
        }
        // Finally, remove the original data-caption node.         $node->parentNode->removeChild($node);
      }

      $result->setProcessedText(Html::serialize($dom))
        ->addAttachments([
          'library' => [
            'filter/caption',
          ],
        ]);
    }
Home | Imprint | This part of the site doesn't use cookies.