Commit 562ffc7c authored by toncic's avatar toncic Committed by Primsi

Issue #2878835 by toncic, Primsi, Berdir: Add hook function for altering...

Issue #2878835 by toncic, Primsi, Berdir: Add hook function for altering prepareEntities function in eb_widget
parent e3463914
<?php
/**
* @file
* Hooks and documentation related to dropzonejs_eb_widget module.
*/
use Drupal\file\Entity\File;
/**
* Alter media entity values before creation in eb widget.
*
* @param array $entity_values
* Entity values for current media entity.
* @param \Drupal\file\Entity\File $file
* File entity used as source for the media entity.
*/
function hook_dropzonejs_eb_media_entity_prepare_alter(array &$entity_values, File $file) {
if ($file->getMimeType() === 'image/gif') {
$entity_values['bundle'] = 'gif';
}
}
......@@ -162,13 +162,15 @@ class MediaEntityDropzoneJsEbWidget extends DropzoneJsEbWidget {
$bundle = $this->getBundle();
foreach (parent::prepareEntities($form, $form_state) as $file) {
$entities[] = $this->entityTypeManager->getStorage('media')->create([
$entity_values = [
'bundle' => $bundle->id(),
$bundle->getTypeConfiguration()['source_field'] => $file,
'uid' => $this->currentUser->id(),
'status' => TRUE,
'type' => $bundle->getType()->getPluginId(),
]);
];
$this->moduleHandler->alter('dropzonejs_eb_media_entity_prepare', $entity_values, $file);
$entities[] = $this->entityTypeManager->getStorage('media')->create($entity_values);
}
return $entities;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment