Minnur Yunusov Senior Drupal Developer Follow
July 11, 2020

External Media module for Drupal 8 and 9 is a successor of the File Chooser Field module that was bulit for Drupal 7. The same functionality was implemented for Wordpress too. The module provides custom form element.

The new form element would allow you to add external services such as Google Drive, Dropbox, Box, OneDrive, AWS, Unsplash, Instagram, Pixabay, Pexels and other services, in addition to regular file choose field. 

External Media form element.

Implementation is very simple. Just like you would do it with managed_file form element you would change it to external_media and you are all set. To make sure the module is supported in your custom modules I would suggest to add the following:

'#type' => (\Drupal::moduleHandler()->moduleExists('external_media'))
  ? 'external_media' : 'managed_file',

If you would like to force your module to use External Media add dependency to the module's .info file:

  - drupal:external_media

The module supports both File and Image field types and allows control of visibility of each plugin individually in addition to permissions. File extension and cardinality field settings are respected in popup widgets when supported.

External Media form display

Download External Media