Asset Field: Select a folder instead of all images Is there a way to pick a folder from an asset field? 

The goal is to render a dynamic gallery from an asset folder (which is on S3) instead of selecting all images inside a folder by hand.

Use case:
In an asset field, I select folder 'XYZ' and render a gallery from all images which are inside. If a user uploads a new image to the folder 'XYZ', the gallery will be updated automatically.

Problem: 
Currently, I can only handpick the images from a folder. If someone uploads a new image, he/she also has to pick the new image in the asset field. So it is not dynamic.

Thanks in advance!
You can create a new field with these functions. Note: this is a very basic example, you would usually want to do this with a template but I don't have much time

class FolderAssetField extends Field {
    // Static Methods
    // =========================================================================

    public $folderId;

    /**
     * Returns the display name of this class.
     *
     * @return string The display name of this class.
     */
    public static function displayName(): string{
        return 'Folder';
    }

    /**
     * @param $value
     * @param ElementInterface|null $element
     * @return string
     */
    public function getInputHtml($value, ElementInterface $element = null): string
    {
        $allFileModels = \craft\records\VolumeFolder::find()-&gt;all();
        $string = 'select a folder&lt;br&gt;&lt;select name="' . $this-&gt;handle .  '"&gt;';
        /** @var VolumeFolder $folder */
        foreach ($allFileModels as $folder){
            $selected = ((int)$value === $folder-&gt;id)? 'selected="selected' : '';
            $string .= '&lt;option ' . $selected .  ' value="' . $folder-&gt;id . '"&gt;' . $folder-&gt;name .  '&lt;/option&gt;';
        }
        $string .= '&lt;/select&gt;';

        return $string;
    }

}


Your field will then contain the folderId of the selected folder. You can then  get all assets for this folder with

/** @var AssetQuery $assetQuery */
$assetQuery = \craft\elements\Asset::find();
$assets = $assetQuery-&gt;folderId($value)-&gt;all();


or in Twig

{% set assets = craft.assets.folderId(entry.fieldHanlde).all() %}
{% for file in assets %}
    {{ file.title }}&lt;br&gt;
{% endfor %}


You could also use the normalizeValue function to prepare this Query. The Redactor plugin has some good examples here