Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Utils / Create / NodeData.php
index da6405112a78fb23b2c9aa75ce61ea92e0da27f0..f4d1f41feadd9dc95bdf1731b84cda41644bb91d 100644 (file)
@@ -19,31 +19,6 @@ use Drupal\Core\Language\LanguageInterface;
  */
 class NodeData extends Base
 {
-    /* @var array */
-    protected $bundles = [];
-
-    /**
-     * Nodes constructor.
-     *
-     * @param EntityTypeManagerInterface  $entityTypeManager
-     * @param EntityFieldManagerInterface $entityFieldManager
-     * @param DateFormatterInterface      $dateFormatter
-     * @param array                       $bundles
-     */
-    public function __construct(
-        EntityTypeManagerInterface $entityTypeManager,
-        EntityFieldManagerInterface $entityFieldManager,
-        DateFormatterInterface $dateFormatter,
-        $bundles
-    ) {
-        $this->bundles = $bundles;
-        parent::__construct(
-            $entityTypeManager,
-            $entityFieldManager,
-            $dateFormatter
-        );
-    }
-
     /**
      * @param $contentTypes
      * @param $limit
@@ -60,30 +35,29 @@ class NodeData extends Base
         $language = LanguageInterface::LANGCODE_NOT_SPECIFIED
     ) {
         $nodes = [];
-        for ($i=0; $i<$limit; $i++) {
-            $contentType = $contentTypes[array_rand($contentTypes)];
-            $node = $this->entityTypeManager->getStorage('node')->create(
-                [
-                    'nid' => null,
-                    'type' => $contentType,
-
-                    'created' => REQUEST_TIME - mt_rand(0, $timeRange),
-                    'uid' => $this->getUserID(),
-                    'title' => $this->getRandom()->sentences(mt_rand(1, $titleWords), true),
-                    'revision' => mt_rand(0, 1),
-                    'status' => true,
-                    'promote' => mt_rand(0, 1),
-                    'langcode' => $language
-                ]
-            );
-
-            $this->generateFieldSampleData($node);
-
+        $bundles = $this->drupalApi->getBundles();
+        for ($i = 0; $i < $limit; $i++) {
             try {
+                $contentType = $contentTypes[array_rand($contentTypes)];
+                $node = $this->entityTypeManager->getStorage('node')->create(
+                    [
+                        'nid' => null,
+                        'type' => $contentType,
+                        'created' => REQUEST_TIME - mt_rand(0, $timeRange),
+                        'uid' => $this->getUserID(),
+                        'title' => $this->getRandom()->sentences(mt_rand(1, $titleWords), true),
+                        'revision' => mt_rand(0, 1),
+                        'status' => true,
+                        'promote' => mt_rand(0, 1),
+                        'langcode' => $language
+                    ]
+                );
+
+                $this->generateFieldSampleData($node);
                 $node->save();
                 $nodes['success'][] = [
                     'nid' => $node->id(),
-                    'node_type' => $this->bundles[$contentType],
+                    'node_type' => $bundles[$contentType],
                     'title' => $node->getTitle(),
                     'created' => $this->dateFormatter->format(
                         $node->getCreatedTime(),
@@ -92,11 +66,7 @@ class NodeData extends Base
                     )
                 ];
             } catch (\Exception $error) {
-                $nodes['error'][] = [
-                    'node_type' =>  $this->bundles[$contentType],
-                    'title' => $node->getTitle(),
-                    'error' => $error->getMessage()
-                ];
+                $nodes['error'][] = $error->getMessage();
             }
         }