Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / migrate / tests / src / Kernel / NodeCommentCombinationTrait.php
1 <?php
2
3 namespace Drupal\Tests\migrate\Kernel;
4
5 use Drupal\comment\Entity\CommentType;
6 use Drupal\node\Entity\NodeType;
7
8 /**
9  * Provides methods for testing node and comment combinations.
10  */
11 trait NodeCommentCombinationTrait {
12
13   /**
14    * Creates a node type with a corresponding comment type.
15    *
16    * @param string $node_type
17    *   The node type ID.
18    * @param string $comment_type
19    *   (optional) The comment type ID, if not provided defaults to
20    *   comment_node_{type}.
21    */
22   protected function createNodeCommentCombination($node_type, $comment_type = NULL) {
23     if (!$comment_type) {
24       $comment_type = "comment_node_$node_type";
25     }
26     NodeType::create([
27       'type' => $node_type,
28       'label' => $this->randomString(),
29     ])->save();
30
31     CommentType::create([
32       'id' => $comment_type,
33       'label' => $this->randomString(),
34       'target_entity_type_id' => 'node',
35     ])->save();
36   }
37
38 }