public function MediaBulkConfigForm::form in Media Bulk Upload 8
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ MediaBulkConfigForm.php, line 50
Class
- MediaBulkConfigForm
- Class MediaBulkConfigForm.
Namespace
Drupal\media_bulk_upload\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/** @var \Drupal\media_bulk_upload\Entity\MediaBulkConfigInterface $mediaBulkConfig */
$mediaBulkConfig = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $mediaBulkConfig
->label(),
'#description' => $this
->t("Label for the Media Bulk Config."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $mediaBulkConfig
->id(),
'#machine_name' => [
'exists' => '\\Drupal\\media_bulk_upload\\Entity\\MediaBulkConfig::load',
],
'#disabled' => !$mediaBulkConfig
->isNew(),
];
$media_types = $mediaBulkConfig
->get('media_types');
$form['media_types'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Media Types'),
'#description' => $this
->t('Choose the media types that will be
used to create new media entities based on matching extensions. Please be
aware that if file extensions overlap between the media types that are
chosen, that the media entity will be assigned automatically to one of
these types.'),
'#options' => $this
->getMediaTypeOptions(),
'#default_value' => isset($media_types) ? $media_types : [],
'#size' => 20,
'#multiple' => TRUE,
];
$form['form_mode'] = [
'#type' => 'select',
'#title' => $this
->t('Form Mode'),
'#description' => $this
->t('Based on the form mode the upload form
can be enriched with fields that are available, improving the speed and
usability to add (meta)data to your media entities.'),
'#options' => $this->entityDisplayRepository
->getFormModeOptions('media'),
"#empty_option" => t('- None -'),
'#default_value' => $mediaBulkConfig
->get('form_mode'),
];
return $form;
}