Notify.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Fixer/Notify.php
View source
<?php
namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer;
use Drupal\drupalmoduleupgrader\FixerBase;
use Pharborist\DocCommentNode;
use Pharborist\LineCommentBlockNode;
use Pharborist\NodeInterface;
class Notify extends FixerBase {
use NodeCollectorTrait;
public function execute() {
foreach ($this
->getObjects() as $node) {
$comment = $this
->getComment($node);
if ($comment) {
$comment .= "\n\n";
}
$this
->setComment($node, $comment . $this->configuration['note']);
}
$this->target
->save();
}
protected function getComment(NodeInterface $node) {
if ($this
->supportsDocComments($node)) {
$comment = $node
->getDocComment() ?: DocCommentNode::create('');
return $comment
->getCommentText();
}
else {
return '';
}
}
protected function setComment(NodeInterface $node, $comment_text) {
if ($this
->supportsDocComments($node)) {
$node
->setDocComment(DocCommentNode::create($comment_text));
}
else {
LineCommentBlockNode::create($comment_text)
->insertBefore($node
->getStatement());
}
}
protected function supportsDocComments(NodeInterface $node) {
return $this
->usesTrait('Pharborist\\DocCommentTrait', $node);
}
}
Classes
Name |
Description |
Notify |
Plugin annotation
@Fixer(
id = "notify"
) |