|
11 | 11 | use Drupal\Core\Entity\EntityManagerInterface; |
12 | 12 | use Drupal\Core\Extension\ModuleHandlerInterface; |
13 | 13 | use Drupal\Core\Form\FormStateInterface; |
| 14 | +use Drupal\Core\Link; |
14 | 15 | use Drupal\Core\Session\AccountProxyInterface; |
15 | 16 | use Drupal\dropzonejs\DropzoneJsUploadSaveInterface; |
16 | 17 | use Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent; |
@@ -137,4 +138,41 @@ public function submit(array &$element, array &$form, FormStateInterface $form_s |
137 | 138 | $this->clearFormValues($element, $form_state); |
138 | 139 | } |
139 | 140 | } |
| 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 | + } |
140 | 178 | } |
0 commit comments