public function MediaDevelGenerate::settingsForm in Media entity 8
File
- src/
Plugin/ DevelGenerate/ MediaDevelGenerate.php, line 147
Class
- MediaDevelGenerate
- Provides a MediaDevelGenerate plugin.
Namespace
Drupal\media_entity\Plugin\DevelGenerateCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$bundles = $this->mediaBundleStorage
->loadMultiple();
if (empty($bundles)) {
$create_url = $this->urlGenerator
->generateFromRoute('media.bundle_add');
$this
->setMessage($this
->t('You do not have any media bundles that can be generated. <a href="@create-bundle">Go create a new media bundle</a>', [
'@create-bundle' => $create_url,
]), 'error', FALSE);
return [];
}
$options = [];
foreach ($bundles as $bundle) {
$options[$bundle
->id()] = [
'bundle' => [
'#markup' => $bundle
->label(),
],
];
}
$form['media_bundles'] = [
'#type' => 'tableselect',
'#header' => [
'bundle' => $this
->t('Media bundle'),
],
'#options' => $options,
];
$form['kill'] = [
'#type' => 'checkbox',
'#title' => $this
->t('<strong>Delete all media</strong> in these bundles before generating new media.'),
'#default_value' => $this
->getSetting('kill'),
];
$form['num'] = [
'#type' => 'number',
'#title' => $this
->t('How many media items would you like to generate?'),
'#default_value' => $this
->getSetting('num'),
'#required' => TRUE,
'#min' => 0,
];
$options = [
1 => $this
->t('Now'),
];
foreach ([
3600,
86400,
604800,
2592000,
31536000,
] as $interval) {
$options[$interval] = $this->dateFormatter
->formatInterval($interval, 1) . ' ' . $this
->t('ago');
}
$form['time_range'] = [
'#type' => 'select',
'#title' => $this
->t('How far back in time should the media be dated?'),
'#description' => $this
->t('Media creation dates will be distributed randomly from the current time, back to the selected time.'),
'#options' => $options,
'#default_value' => 604800,
];
$form['name_length'] = [
'#type' => 'number',
'#title' => $this
->t('Maximum number of words in names'),
'#default_value' => $this
->getSetting('name_length'),
'#required' => TRUE,
'#min' => 1,
'#max' => 255,
];
$options = [];
// We always need a language.
$languages = $this->languageManager
->getLanguages(LanguageInterface::STATE_ALL);
foreach ($languages as $langcode => $language) {
$options[$langcode] = $language
->getName();
}
$form['add_language'] = [
'#type' => 'select',
'#title' => $this
->t('Set language on media'),
'#multiple' => TRUE,
'#description' => $this
->t('Requires locale.module'),
'#options' => $options,
'#default_value' => [
$this->languageManager
->getDefaultLanguage()
->getId(),
],
];
$form['#redirect'] = FALSE;
return $form;
}