class ExampleDevelGenerate
Same name in other branches
- 8.x-1.x devel_generate/tests/modules/devel_generate_example/src/Plugin/DevelGenerate/ExampleDevelGenerate.php \Drupal\devel_generate_example\Plugin\DevelGenerate\ExampleDevelGenerate
- 5.x devel_generate/tests/modules/devel_generate_example/src/Plugin/DevelGenerate/ExampleDevelGenerate.php \Drupal\devel_generate_example\Plugin\DevelGenerate\ExampleDevelGenerate
Provides a ExampleDevelGenerate plugin.
Plugin annotation
@DevelGenerate(
id = "devel_generate_example",
label = "Example",
description = "Generate a given number of examples.",
url = "devel_generate_example",
permission = "administer devel_generate",
settings = {
"num" = 50,
"kill" = FALSE
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\devel_generate\DevelGenerateBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\devel_generate\DevelGenerateBaseInterface
- class \Drupal\devel_generate_example\Plugin\DevelGenerate\ExampleDevelGenerate extends \Drupal\devel_generate\DevelGenerateBase
- class \Drupal\devel_generate\DevelGenerateBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\devel_generate\DevelGenerateBaseInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of ExampleDevelGenerate
File
-
devel_generate/
tests/ modules/ devel_generate_example/ src/ Plugin/ DevelGenerate/ ExampleDevelGenerate.php, line 23
Namespace
Drupal\devel_generate_example\Plugin\DevelGenerateView source
class ExampleDevelGenerate extends DevelGenerateBase {
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$form['num'] = [
'#type' => 'textfield',
'#title' => $this->t('How many examples would you like to generate?'),
'#default_value' => $this->getSetting('num'),
'#size' => 10,
];
$form['kill'] = [
'#type' => 'checkbox',
'#title' => $this->t('Delete all examples before generating new examples.'),
'#default_value' => $this->getSetting('kill'),
];
return $form;
}
/**
* {@inheritdoc}
*/
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'),
]));
}
/**
* {@inheritdoc}
*/
public function validateDrushParams(array $args, array $options = []) {
$values = [
'num' => $options['num'],
'kill' => $options['kill'],
];
return $values;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
DevelGenerateBase::$entityTypeManager | protected | property | The entity type manager service. | ||
DevelGenerateBase::$random | protected | property | The random data generator. | ||
DevelGenerateBase::$settings | protected | property | The plugin settings. | ||
DevelGenerateBase::generate | public | function | Execute the instructions in common for all DevelGenerate plugin. | Overrides DevelGenerateBaseInterface::generate | |
DevelGenerateBase::getDefaultSettings | public | function | Returns the default settings for the plugin. | Overrides DevelGenerateBaseInterface::getDefaultSettings | |
DevelGenerateBase::getEntityTypeManager | protected | function | Gets the entity type manager service. | ||
DevelGenerateBase::getLangcode | protected | function | Return a language code. | 1 | |
DevelGenerateBase::getLanguageForm | protected | function | Creates the language and translation section of the form. | ||
DevelGenerateBase::getRandom | protected | function | Returns the random data generator. | ||
DevelGenerateBase::getSetting | public | function | Returns the array of settings, including defaults for missing settings. | Overrides DevelGenerateBaseInterface::getSetting | |
DevelGenerateBase::getSettings | public | function | Returns the current settings for the plugin. | Overrides DevelGenerateBaseInterface::getSettings | |
DevelGenerateBase::handleDrushParams | public | function | |||
DevelGenerateBase::isNumber | public static | function | Check if a given param is a number. | ||
DevelGenerateBase::populateFields | public static | function | Populate the fields on a given entity with sample values. | ||
DevelGenerateBase::randomSentenceOfLength | protected | function | Generates a random sentence of specific length. | ||
DevelGenerateBase::setMessage | protected | function | Set a message for either drush or the web interface. | ||
DevelGenerateBase::settingsFormValidate | public | function | Form validation handler. | Overrides DevelGenerateBaseInterface::settingsFormValidate | 2 |
ExampleDevelGenerate::generateElements | protected | function | Business logic relating with each DevelGenerate plugin. | Overrides DevelGenerateBase::generateElements | |
ExampleDevelGenerate::settingsForm | public | function | Returns the form for the plugin. | Overrides DevelGenerateBase::settingsForm | |
ExampleDevelGenerate::validateDrushParams | public | function | Responsible for validating Drush params. | Overrides DevelGenerateBaseInterface::validateDrushParams | |
PluginInspectionInterface::getPluginDefinition | public | function | Gets the definition of the plugin implementation. | 6 | |
PluginInspectionInterface::getPluginId | public | function | Gets the plugin_id of the plugin instance. | 2 |