You are here

private function InsertView::processText in Advanced Insert View 2.0.x

Process text to find <drupal-view> tags and replace with placeholders.

Parameters

string $text: Text to process.

\Drupal\filter\FilterProcessResult $result: The result of filter processor.

int $count: Counter of replacements.

string $encoded_configuration: JSON encoded filter configuration.

1 call to InsertView::processText()
InsertView::process in src/Plugin/Filter/InsertView.php
Performs the filter processing.

File

src/Plugin/Filter/InsertView.php, line 121

Class

InsertView
Provides a filter for insert view.

Namespace

Drupal\insert_view_adv\Plugin\Filter

Code

private function processText(&$text, FilterProcessResult $result, &$count, $encoded_configuration) {
  if (stristr($text, '<drupal-view') === FALSE) {
    return $text;
  }
  $dom = Html::load($text);
  $xpath = new \DOMXPath($dom);
  foreach ($xpath
    ->query('//drupal-view') as $node) {

    /** @var \DOMElement $node */
    $view_name = $node
      ->getAttribute('data-view-id');
    $display_id = $node
      ->getAttribute('data-display-id');
    $args = $node
      ->getAttribute('data-arguments');
    if (!empty($args) && !empty($this->settings['hide_argument_input'])) {
      $args = NULL;
    }
    $content = $result
      ->createPlaceholder('\\Drupal\\insert_view_adv\\Plugin\\Filter\\InsertView::build', [
      $view_name,
      $display_id,
      $args,
      $encoded_configuration,
    ]);

    // Delete the consumed attributes.
    $node
      ->removeAttribute('data-view-id');
    $node
      ->removeAttribute('data-display-id');
    $node
      ->removeAttribute('data-arguments');
    static::replaceNodeContent($node, $content);
    $count++;
  }
  $text = Html::serialize($dom);
}