public function BynderUpload::getForm in Bynder 8
Same name and namespace in other branches
- 8.3 src/Plugin/EntityBrowser/Widget/BynderUpload.php \Drupal\bynder\Plugin\EntityBrowser\Widget\BynderUpload::getForm()
- 8.2 src/Plugin/EntityBrowser/Widget/BynderUpload.php \Drupal\bynder\Plugin\EntityBrowser\Widget\BynderUpload::getForm()
- 4.0.x src/Plugin/EntityBrowser/Widget/BynderUpload.php \Drupal\bynder\Plugin\EntityBrowser\Widget\BynderUpload::getForm()
Overrides BynderWidgetBase::getForm
File
- src/
Plugin/ EntityBrowser/ Widget/ BynderUpload.php, line 123
Class
- BynderUpload
- Uses upload to create media entities.
Namespace
Drupal\bynder\Plugin\EntityBrowser\WidgetCode
public function getForm(array &$original_form, FormStateInterface $form_state, array $additional_widget_parameters) {
$form = parent::getForm($original_form, $form_state, $additional_widget_parameters);
$has_upload_permissions = $this->bynderApi
->hasUploadPermissions();
if (empty($this->configuration['brand'])) {
(new BrandNotSetException($this->configuration['entity_browser_id']))
->logException()
->displayMessage();
return [];
}
elseif (!$has_upload_permissions) {
$form['actions']['submit']['#access'] = FALSE;
(new UploadPermissionException($this->configuration['entity_browser_id']))
->logException();
$form['message'] = [
'#markup' => t("Unable to upload files to Bynder. Make sure your user account has enough permissions."),
];
}
else {
if ($form_state
->getValue('errors')) {
$form['actions']['submit']['#access'] = FALSE;
return $form;
}
$form['upload'] = [
'#title' => $this
->t('File upload'),
'#type' => 'dropzonejs',
'#dropzone_description' => $this
->getConfiguration()['settings']['dropzone_description'],
];
$form['description'] = [
'#title' => $this
->t('Description'),
'#type' => 'textarea',
'#description' => $this
->t('Description text to be added to the assets.'),
];
$this->session
->set('upload_permissions', $has_upload_permissions);
if ($uploaded_assets = $this->session
->get('bynder_upload_batch_result', [])) {
$form_state
->set('uploaded_entities', $uploaded_assets);
$this->session
->remove('bynder_upload_batch_result');
$form['upload']['#access'] = FALSE;
$form['description']['#access'] = FALSE;
$form['#attached']['library'][] = 'bynder/upload';
$form['actions']['submit']['#attributes']['class'][] = 'visually-hidden';
$form['message']['#markup'] = $this
->t('Finishing upload. Please wait...');
}
else {
$form['actions']['submit']['#eb_widget_main_submit'] = FALSE;
$form['actions']['submit']['#bynder_upload_submit'] = TRUE;
}
}
return $form;
}