We have a custom form with an image field and want to use the entity_browser widget from the File Entity Browser module, however it isn't displaying the uploaded content.

The code we have so far:

$fields['testing'] = [
  '#type' => 'container',
  'widget' => array(
    '#title' => t('Test'),
    '#description' => t('The content to be linked in the menu.'),
    '#type' => 'entity_browser',
    '#entity_browser' => 'browse_files_modal',
    '#field_widget_remove' => true,
    '#open' => true,
    '#selection_mode' => 'selection_edit',
    '#preview_image_style' => 'thumbnail',
    '#field_widget_edit' => true,
    '#view_mode' => 'default'

The "Browse files" button appears and clicking this opens the correct popup to select files / browser library. The problem comes next as the uploaded files are not listed out after uploading (No Preview / Filename / Metadata / Operations etc). There are no errors on the page.

  • 1
    You might want to be able to use this widget in such a form, but it's never going to work like that. It is explicitly for use with the entity and field apis. Your form presumably stores something - why not an entity? – Alfred Armstrong May 1 '18 at 13:25
  • 1
    Yes, you need an entity to use the widget. You can provide a mock entity with a null storage, like Message of the core Contact module, if you want to process the data in other ways like sending an email. – 4k4 May 1 '18 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.