class ExampleDevelGenerate in Devel 8
Same name and namespace in other branches
- 8.3 devel_generate/tests/modules/devel_generate_example/src/Plugin/DevelGenerate/ExampleDevelGenerate.php \Drupal\devel_generate_example\Plugin\DevelGenerate\ExampleDevelGenerate
- 8.2 devel_generate/tests/modules/devel_generate_example/src/Plugin/DevelGenerate/ExampleDevelGenerate.php \Drupal\devel_generate_example\Plugin\DevelGenerate\ExampleDevelGenerate
- 4.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. Optionally delete current examples.",
url = "devel_generate_example",
permission = "administer devel_generate",
settings = {
"num" = 50,
"kill" = FALSE
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\devel_generate\DevelGenerateBase implements DevelGenerateBaseInterface
- class \Drupal\devel_generate_example\Plugin\DevelGenerate\ExampleDevelGenerate
- class \Drupal\devel_generate\DevelGenerateBase implements DevelGenerateBaseInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
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 {
public function settingsForm(array $form, FormStateInterface $form_state) {
$form['num'] = array(
'#type' => 'textfield',
'#title' => $this
->t('How many examples would you like to generate?'),
'#default_value' => $this
->getSetting('num'),
'#size' => 10,
);
$form['kill'] = array(
'#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 = array(
'uid' => NULL,
'name' => 'example_devel_generate',
'pass' => '',
'mail' => 'example_devel_generate@example.com',
'status' => 1,
'created' => REQUEST_TIME,
'roles' => '',
'devel_generate' => TRUE,
);
$account = user_load_by_name('example_devel_generate');
if (!$account) {
$account = entity_create('user', $edit);
}
// Populate all fields with sample values.
$this
->populateFields($account);
$account
->save();
$this
->setMessage($this
->t('@num_examples created.', array(
'@num_examples' => $this
->formatPlural($num, '1 example', '@count examples'),
)));
}
public function validateDrushParams($args) {
$values = array(
'num' => array_shift($args),
'kill' => drush_get_option('kill'),
);
return $values;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DevelGenerateBase:: |
protected | property | The random data generator. | |
DevelGenerateBase:: |
protected | property | The plugin settings. | |
DevelGenerateBase:: |
public | function |
Execute the instructions in common for all DevelGenerate plugin Overrides DevelGenerateBaseInterface:: |
|
DevelGenerateBase:: |
public | function |
Returns the default settings for the plugin. Overrides DevelGenerateBaseInterface:: |
|
DevelGenerateBase:: |
protected | function | Returns the random data generator. | |
DevelGenerateBase:: |
public | function |
Returns the array of settings, including defaults for missing settings. Overrides DevelGenerateBaseInterface:: |
|
DevelGenerateBase:: |
public | function |
Returns the current settings for the plugin. Overrides DevelGenerateBaseInterface:: |
|
DevelGenerateBase:: |
public | function | ||
DevelGenerateBase:: |
protected | function | ||
DevelGenerateBase:: |
public static | function | Check if a given param is a number. | |
DevelGenerateBase:: |
public static | function | Populate the fields on a given entity with sample values. | |
DevelGenerateBase:: |
protected | function | Set a message for either drush or the web interface. | |
DevelGenerateBase:: |
function |
Form validation handler. Overrides DevelGenerateBaseInterface:: |
1 | |
ExampleDevelGenerate:: |
protected | function |
Business logic relating with each DevelGenerate plugin Overrides DevelGenerateBase:: |
|
ExampleDevelGenerate:: |
public | function |
Returns the form for the plugin. Overrides DevelGenerateBase:: |
|
ExampleDevelGenerate:: |
public | function |
Responsible for validating Drush params. Overrides DevelGenerateBaseInterface:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |