Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CommentsRegistry.php

function CommentsRegistry::associateComments

Adds comments to the given node

Parameters

Node\Node $node Node:

array $comments Array of comments to add:

bool $leading True to add comments as leading comments: or false to add them as trailing comments

Return value

void

1 call to CommentsRegistry::associateComments()
CommentsRegistry::findNodeForCommentsGroup in vendor/mck89/peast/lib/Peast/Syntax/CommentsRegistry.php
Finds the node to attach the given comments group

File

vendor/mck89/peast/lib/Peast/Syntax/CommentsRegistry.php, line 306

Class

CommentsRegistry
Comments registry class. Internal class used to manage comments

Namespace

Peast\Syntax

Code

public function associateComments($node, $comments, $leading) {
    $fn = ($leading ? "Leading" : "Trailing") . "Comments";
    $currentComments = $node->{"get{$fn}"}();
    foreach ($comments as $comment) {
        $loc = $comment->location;
        $commentNode = new Node\Comment();
        $commentNode->location->start = $loc->start;
        $commentNode->location->end = $loc->end;
        $commentNode->setRawText($comment->value);
        $currentComments[] = $commentNode;
    }
    $node->{"set{$fn}"}($currentComments);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal