New answers tagged

0

I ended up using the IMCE module which was the simplest solution for me, following the Leigh's suggestion. After installing, I had to click the settings icon on the top right corner in the Manage Form Display page. There is the magic Allow IMCE checkbox.


3

Projects are built from the start to use the Media module and reference entities instead of files directly. That is how Entity Browser can help. Here is how it's usually done: https://www.drupal.org/docs/8/modules/entity-browser/how-to-configure-an-image-widget-to-re-use-existing-files. More useful resouces: https://www.drupal.org/docs/8/core/modules/...


0

As far as I know, there is not a way to add a validation handler for the file field type in general. You'll need to set a hook form alter and add a custom form validate handler for the edit forms, webforms, etc that you want to override. Refer to: How do I add a custom validation handler to an existing form/field? Alternatively, if your site is a ...


0

I ended up creating a new managed file, pretty easy as the following: $user = \Drupal::currentUser()->id(); $image = File::create([ 'uri' => $image_local_path, 'uid' => $user, 'status' => FILE_STATUS_PERMANENT, ]); $image->save();


1

Drupal places an .htaccess file in the files directory to prevent files inside from being executed. Check the status report on your site to ensure that this is correctly configured.


3

This error is often caused by a "stale" autoloader file. The first and most effective step would be to call composer dump-autoload from inside your drupal installation folder (presumably /var/www/sites/drupalroot/) in order to force an updating of the autoloader file in your vendor folder. Try clearing the composer caches as well in combination with this ...


3

Here are some pointers that might help: Run drush cr to clear cache and see if the error persists. Enable error backtraces from the Config > Development > Logging & Errors page to see if you get more info in the error message about where the class is being redeclared. Search your project for the name MyFormatter and see if you find anything ...


0

You can override the required = true in file_field_instance_settings_form function that returns and form array and then remove the extensions from your ui config so that drupal use with out the validate function that also checks the resource suffixes. Same for Drupal 8. e.g. use Drupal\Core\Form\FormStateInterface; /** * Implements ...


0

I finally found the solution, instead of $zip->addFile($file_path, $media->entity->field_media_image->entity->name); I simply put $zip->addFile($file_path, basename($file_path)); and it does the job.


0

To load the entity by ID you can use the following code: /** @var \Drupal\file\FileInterface|null $file*/ $file = \Drupal::entityTypeManager() ->getStorage('file') ->load($entityId); But if you need to load the file entity by the given file URI there is a method called loadByProperties in EntityStorageInterface: /** @var \Drupal\file\...


Top 50 recent answers are included