public function UploadForm::buildForm in Image Entity Browser 8
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/ UploadForm.php, line 34 - Contains \Drupal\image_browser\Form.
Class
- UploadForm
- Class TestModalForm.
Namespace
Drupal\image_browser\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
//We only accept ajax request for that page
if (false == \Drupal::request()
->isXmlHttpRequest()) {
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
}
$form['image'] = array(
'#type' => 'managed_file',
'#title' => $this
->t('Upload a new file'),
'#required' => TRUE,
'#upload_location' => 'public://',
'#upload_validators' => array(
'file_validate_extensions' => array(
'gif png jpg jpeg svg',
),
),
'#description' => $this
->t('Supports file types: gif png jpg jpeg svg'),
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Submit'),
'#ajax' => array(
'callback' => '::submitForm',
),
);
return $form;
}