Skip to content
This repository was archived by the owner on Jan 5, 2018. It is now read-only.

Commit 32dc164

Browse files
committed
Issue #2671914: Implement EB configuration UI
1 parent 62f7b78 commit 32dc164

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,20 @@ protected function validateExtension($filename, $extensions) {
211211
return TRUE;
212212
}
213213

214+
/**
215+
* {@inheritdoc}
216+
*/
217+
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
218+
$configuration = $this->getConfiguration();
219+
$settings = $configuration['settings'];
220+
$form += parent::buildConfigurationForm($form, $form_state);
221+
222+
$form['dropzone_description'] = [
223+
'#type' => 'textfield',
224+
'#title' => $this->t('Dropzone drag-n-drop zone text'),
225+
'#default_value' => $settings['dropzone_description'],
226+
];
227+
228+
return $form;
229+
}
214230
}

modules/eb_widget/src/Plugin/EntityBrowser/Widget/MediaEntityDropzoneJsEbWidget.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Drupal\Core\Entity\EntityManagerInterface;
1212
use Drupal\Core\Extension\ModuleHandlerInterface;
1313
use Drupal\Core\Form\FormStateInterface;
14+
use Drupal\Core\Link;
1415
use Drupal\Core\Session\AccountProxyInterface;
1516
use Drupal\dropzonejs\DropzoneJsUploadSaveInterface;
1617
use Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent;
@@ -137,4 +138,41 @@ public function submit(array &$element, array &$form, FormStateInterface $form_s
137138
$this->clearFormValues($element, $form_state);
138139
}
139140
}
141+
142+
/**
143+
* {@inheritdoc}
144+
*/
145+
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
146+
$configuration = $this->getConfiguration();
147+
$settings = $configuration['settings'];
148+
$form += parent::buildConfigurationForm($form, $form_state);
149+
150+
$options = [];
151+
$media_bundles = $this->entityManager->getBundleInfo('media');
152+
if (!empty($media_bundles)) {
153+
foreach ($media_bundles as $id => $bundle) {
154+
$options[$id] = $bundle['label'];
155+
}
156+
$disabled = FALSE;
157+
$description = $this->t('Select the type of media entity that you want to create from the uploaded files.');
158+
}
159+
else {
160+
$disabled = TRUE;
161+
$description = $this->t('You must @create_bundle before using this widget.', [
162+
'@create_bundle' => Link::createFromRoute($this->t('create a media bundle'), 'media.bundle_add')->toString()
163+
]);
164+
}
165+
166+
$form['media_entity_bundle'] = [
167+
'#type' => 'select',
168+
'#title' => $this->t('Media bundle to create'),
169+
'#default_value' => $settings['media_entity_bundle'],
170+
'#description' => $description,
171+
'#options' => $options,
172+
'#disabled' => $disabled,
173+
'#required' => TRUE,
174+
];
175+
176+
return $form;
177+
}
140178
}

0 commit comments

Comments
 (0)