public function ContentDevelGenerate::settingsForm in Devel 8
Same name and namespace in other branches
- 8.3 devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::settingsForm()
- 8.2 devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::settingsForm()
- 4.x devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::settingsForm()
Returns the form for the plugin.
Return value
array The array of default setting values, keyed by setting names.
Overrides DevelGenerateBase::settingsForm
File
- devel_generate/
src/ Plugin/ DevelGenerate/ ContentDevelGenerate.php, line 141
Class
- ContentDevelGenerate
- Provides a ContentDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$types = $this->nodeTypeStorage
->loadMultiple();
if (empty($types)) {
$create_url = $this->urlGenerator
->generateFromRoute('node.type_add');
$this
->setMessage($this
->t('You do not have any content types that can be generated. <a href=":create-type">Go create a new content type</a>', array(
':create-type' => $create_url,
)), 'error', FALSE);
return;
}
$options = array();
foreach ($types as $type) {
$options[$type
->id()] = array(
'type' => array(
'#markup' => $type
->label(),
),
);
if ($this->commentManager) {
$comment_fields = $this->commentManager
->getFields('node');
$map = array(
$this
->t('Hidden'),
$this
->t('Closed'),
$this
->t('Open'),
);
$fields = array();
foreach ($comment_fields as $field_name => $info) {
// Find all comment fields for the bundle.
if (in_array($type
->id(), $info['bundles'])) {
$instance = FieldConfig::loadByName('node', $type
->id(), $field_name);
$default_value = $instance
->getDefaultValueLiteral();
$default_mode = reset($default_value);
$fields[] = new FormattableMarkup('@field: @state', array(
'@field' => $instance
->label(),
'@state' => $map[$default_mode['status']],
));
}
}
// @todo Refactor display of comment fields.
if (!empty($fields)) {
$options[$type
->id()]['comments'] = array(
'data' => array(
'#theme' => 'item_list',
'#items' => $fields,
),
);
}
else {
$options[$type
->id()]['comments'] = $this
->t('No comment fields');
}
}
}
$header = array(
'type' => $this
->t('Content type'),
);
if ($this->commentManager) {
$header['comments'] = array(
'data' => $this
->t('Comments'),
'class' => array(
RESPONSIVE_PRIORITY_MEDIUM,
),
);
}
$form['node_types'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
);
$form['kill'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('<strong>Delete all content</strong> in these content types before generating new content.'),
'#default_value' => $this
->getSetting('kill'),
);
$form['num'] = array(
'#type' => 'number',
'#title' => $this
->t('How many nodes would you like to generate?'),
'#default_value' => $this
->getSetting('num'),
'#required' => TRUE,
'#min' => 0,
);
$options = array(
1 => $this
->t('Now'),
);
foreach (array(
3600,
86400,
604800,
2592000,
31536000,
) as $interval) {
$options[$interval] = $this->dateFormatter
->formatInterval($interval, 1) . ' ' . $this
->t('ago');
}
$form['time_range'] = array(
'#type' => 'select',
'#title' => $this
->t('How far back in time should the nodes be dated?'),
'#description' => $this
->t('Node creation dates will be distributed randomly from the current time, back to the selected time.'),
'#options' => $options,
'#default_value' => 604800,
);
$form['max_comments'] = array(
'#type' => $this->moduleHandler
->moduleExists('comment') ? 'number' : 'value',
'#title' => $this
->t('Maximum number of comments per node.'),
'#description' => $this
->t('You must also enable comments for the content types you are generating. Note that some nodes will randomly receive zero comments. Some will receive the max.'),
'#default_value' => $this
->getSetting('max_comments'),
'#min' => 0,
'#access' => $this->moduleHandler
->moduleExists('comment'),
);
$form['title_length'] = array(
'#type' => 'number',
'#title' => $this
->t('Maximum number of words in titles'),
'#default_value' => $this
->getSetting('title_length'),
'#required' => TRUE,
'#min' => 1,
'#max' => 255,
);
$form['add_alias'] = array(
'#type' => 'checkbox',
'#disabled' => !$this->moduleHandler
->moduleExists('path'),
'#description' => $this
->t('Requires path.module'),
'#title' => $this
->t('Add an url alias for each node.'),
'#default_value' => FALSE,
);
$form['add_statistics'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Add statistics for each node (node_counter table).'),
'#default_value' => TRUE,
'#access' => $this->moduleHandler
->moduleExists('statistics'),
);
$options = array();
// We always need a language.
$languages = $this->languageManager
->getLanguages(LanguageInterface::STATE_ALL);
foreach ($languages as $langcode => $language) {
$options[$langcode] = $language
->getName();
}
$form['add_language'] = array(
'#type' => 'select',
'#title' => $this
->t('Set language on nodes'),
'#multiple' => TRUE,
'#description' => $this
->t('Requires locale.module'),
'#options' => $options,
'#default_value' => array(
$this->languageManager
->getDefaultLanguage()
->getId(),
),
);
$form['#redirect'] = FALSE;
return $form;
}