Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Utils / Create / RoleData.php
diff --git a/vendor/drupal/console/src/Utils/Create/RoleData.php b/vendor/drupal/console/src/Utils/Create/RoleData.php
new file mode 100644 (file)
index 0000000..53fb216
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Console\Utils\Create\RoleData.
+ */
+
+namespace Drupal\Console\Utils\Create;
+
+use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\Core\Entity\EntityFieldManagerInterface;
+use Drupal\Core\Datetime\DateFormatterInterface;
+
+/**
+ * Class Roles
+ *
+ * @package Drupal\Console\Utils\Create
+ */
+class RoleData extends Base
+{
+    /**
+     * Create and returns an array of new Roles.
+     *
+     * @param $limit
+     *
+     * @return array
+     */
+    public function create(
+        $limit
+    ) {
+        $roles = [];
+        for ($i = 0; $i < $limit; $i++) {
+            try {
+                $rolename = $this->getRandom()->word(mt_rand(6, 12));
+
+                $role = $this->entityTypeManager->getStorage('user_role')->create(
+                    [
+                        'id' => $rolename,
+                        'label' => $rolename,
+                        'originalId' => $rolename
+                    ]
+                );
+
+                $role->save();
+
+                $roles['success'][] = [
+                    'role-id' => $role->id(),
+                    'role-name' => $role->get('label')
+                ];
+            } catch (\Exception $error) {
+                $roles['error'][] = $error->getMessage();
+            }
+        }
+
+        return $roles;
+    }
+}