X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fmedia_entity_image%2Fsrc%2FPlugin%2FEntityBrowser%2FWidget%2FUpload.php;fp=web%2Fmodules%2Fcontrib%2Fmedia_entity_image%2Fsrc%2FPlugin%2FEntityBrowser%2FWidget%2FUpload.php;h=0000000000000000000000000000000000000000;hp=97551b7420f455a3d26cbd37be9495250404bd86;hb=419f97be044f1aebd0713921ee604841127e9e84;hpb=052617e40b525f8b817d84c29b1c04951f427069 diff --git a/web/modules/contrib/media_entity_image/src/Plugin/EntityBrowser/Widget/Upload.php b/web/modules/contrib/media_entity_image/src/Plugin/EntityBrowser/Widget/Upload.php deleted file mode 100644 index 97551b742..000000000 --- a/web/modules/contrib/media_entity_image/src/Plugin/EntityBrowser/Widget/Upload.php +++ /dev/null @@ -1,133 +0,0 @@ - 'jpg jpeg png gif', - 'media_bundle' => NULL, - ] + parent::defaultConfiguration(); - } - - /** - * {@inheritdoc} - */ - public function getForm(array &$original_form, FormStateInterface $form_state, array $aditional_widget_parameters) { - /** @var \Drupal\media_entity\MediaBundleInterface $bundle */ - if (!$this->configuration['media_bundle'] || !($bundle = $this->entityTypeManager->getStorage('media_bundle')->load($this->configuration['media_bundle']))) { - return ['#markup' => $this->t('The media bundle is not configured correctly.')]; - } - - if ($bundle->getType()->getPluginId() != 'image') { - return ['#markup' => $this->t('The configured bundle is not using image plugin.')]; - } - - $form = parent::getForm($original_form, $form_state, $aditional_widget_parameters); - $form['upload']['#upload_validators']['file_validate_extensions'] = [$this->configuration['extensions']]; - - return $form; - } - - /** - * {@inheritdoc} - */ - protected function prepareEntities(array $form, FormStateInterface $form_state) { - $files = parent::prepareEntities($form, $form_state); - - /** @var \Drupal\media_entity\MediaBundleInterface $bundle */ - $bundle = $this->entityTypeManager - ->getStorage('media_bundle') - ->load($this->configuration['media_bundle']); - - $images = []; - foreach ($files as $file) { - /** @var \Drupal\media_entity\MediaInterface $image */ - $image = $this->entityTypeManager->getStorage('media')->create([ - 'bundle' => $bundle->id(), - $bundle->getTypeConfiguration()['source_field'] => $file, - ]); - $images[] = $image; - } - - return $images; - } - - /** - * {@inheritdoc} - */ - public function submit(array &$element, array &$form, FormStateInterface $form_state) { - if (!empty($form_state->getTriggeringElement()['#eb_widget_main_submit'])) { - $images = $this->prepareEntities($form, $form_state); - array_walk( - $images, - function (MediaInterface $media) { - $media->save(); - } - ); - - $this->selectEntities($images, $form_state); - $this->clearFormValues($element, $form_state); - } - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form = parent::buildConfigurationForm($form, $form_state); - $form['extensions'] = [ - '#type' => 'textfield', - '#title' => $this->t('Allowed extensions'), - '#default_value' => $this->configuration['extensions'], - '#required' => TRUE, - ]; - - $bundle_options = []; - $bundles = $this - ->entityTypeManager - ->getStorage('media_bundle') - ->loadByProperties(['type' => 'image']); - - foreach ($bundles as $bundle) { - $bundle_options[$bundle->id()] = $bundle->label(); - } - - if (empty($bundle_options)) { - $url = Url::fromRoute('media.bundle_add')->toString(); - $form['media_bundle'] = [ - '#markup' => $this->t("You don't have media bundle of the Image type. You should create one", ['!link' => $url]), - ]; - } - else { - $form['media_bundle'] = [ - '#type' => 'select', - '#title' => $this->t('Media bundle'), - '#default_value' => $this->configuration['media_bundle'], - '#options' => $bundle_options, - ]; - } - - return $form; - } - -}