public function PhotosUploadForm::buildForm in Album Photos 8.4
Same name and namespace in other branches
- 8.5 src/Form/PhotosUploadForm.php \Drupal\photos\Form\PhotosUploadForm::buildForm()
- 6.0.x src/Form/PhotosUploadForm.php \Drupal\photos\Form\PhotosUploadForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ PhotosUploadForm.php, line 132
Class
- PhotosUploadForm
- Defines a form to upload photos to this site.
Namespace
Drupal\photos\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('photos.settings');
// Get node object.
$node = $this->routeMatch
->getParameter('node');
$nid = $node
->id();
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['new'] = [
'#title' => $this
->t('Image upload'),
'#weight' => -4,
'#type' => 'details',
'#open' => TRUE,
];
$allow_zip = $config
->get('photos_upzip') ? ' zip' : '';
// Check if plubload is installed.
if ($config
->get('photos_plupload_status')) {
$form['new']['plupload'] = [
'#type' => 'plupload',
'#title' => $this
->t('Upload photos'),
'#description' => $this
->t('Upload multiple images.'),
'#autoupload' => TRUE,
'#submit_element' => '#edit-submit',
'#upload_validators' => [
'file_validate_extensions' => [
'jpg jpeg gif png' . $allow_zip,
],
],
'#plupload_settings' => [
'chunk_size' => '1mb',
],
];
}
else {
// Manual upload form.
$form['new']['#description'] = $this
->t('Allowed types: jpg gif png jpeg@zip', [
'@zip' => $allow_zip,
]);
for ($i = 0; $i < $config
->get('photos_num'); ++$i) {
$form['new']['images_' . $i] = [
'#type' => 'file',
];
$form['new']['title_' . $i] = [
'#type' => 'textfield',
'#title' => $this
->t('Image title'),
];
$form['new']['des_' . $i] = [
'#type' => 'textarea',
'#title' => $this
->t('Image description'),
'#cols' => 40,
'#rows' => 3,
];
}
}
// @todo pid is redundant unless albums become own entity.
// - maybe make pid serial and add nid... or entity_id.
$form['new']['pid'] = [
'#type' => 'value',
'#value' => $nid,
];
$form['new']['nid'] = [
'#type' => 'value',
'#value' => $nid,
];
$form['new']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Confirm upload'),
'#weight' => 10,
];
return $form;
}