You are here

protected function ExampleDevelGenerate::generateElements in Devel 8.3

Same name and namespace in other branches
  1. 8 devel_generate/tests/modules/devel_generate_example/src/Plugin/DevelGenerate/ExampleDevelGenerate.php \Drupal\devel_generate_example\Plugin\DevelGenerate\ExampleDevelGenerate::generateElements()
  2. 8.2 devel_generate/tests/modules/devel_generate_example/src/Plugin/DevelGenerate/ExampleDevelGenerate.php \Drupal\devel_generate_example\Plugin\DevelGenerate\ExampleDevelGenerate::generateElements()
  3. 4.x devel_generate/tests/modules/devel_generate_example/src/Plugin/DevelGenerate/ExampleDevelGenerate.php \Drupal\devel_generate_example\Plugin\DevelGenerate\ExampleDevelGenerate::generateElements()

Business logic relating with each DevelGenerate plugin.

Parameters

array $values: The input values from the settings form.

Overrides DevelGenerateBase::generateElements

File

devel_generate/tests/modules/devel_generate_example/src/Plugin/DevelGenerate/ExampleDevelGenerate.php, line 49

Class

ExampleDevelGenerate
Provides a ExampleDevelGenerate plugin.

Namespace

Drupal\devel_generate_example\Plugin\DevelGenerate

Code

protected function generateElements(array $values) {
  $num = $values['num'];
  $kill = $values['kill'];
  if ($kill) {
    $this
      ->setMessage($this
      ->t('Old examples have been deleted.'));
  }

  // Creating user in order to demonstrate
  // how to override default business login generation.
  $edit = [
    'uid' => NULL,
    'name' => 'example_devel_generate',
    'pass' => '',
    'mail' => 'example_devel_generate@example.com',
    'status' => 1,
    'created' => \Drupal::time()
      ->getRequestTime(),
    'roles' => '',
    // A flag to let hook_user_* know that this is a generated user.
    'devel_generate' => TRUE,
  ];
  $account = user_load_by_name('example_devel_generate');
  if (!$account) {
    $account = $this
      ->getEntityTypeManager()
      ->getStorage('user')
      ->create($edit);
  }

  // Populate all fields with sample values.
  $this
    ->populateFields($account);
  $account
    ->save();
  $this
    ->setMessage($this
    ->t('@num_examples created.', [
    '@num_examples' => $this
      ->formatPlural($num, '1 example', '@count examples'),
  ]));
}