craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.21k stars 624 forks source link

forms.elementSelectField sources can no longer be an array #1377

Closed khalwat closed 7 years ago

khalwat commented 7 years ago

Description

I have a plugin that lets the user pick an Asset to use, via the following Twig code:

                {{ forms.elementSelectField({
                    elements: elements,
                    id: id ~ 'imageId',
                    name: name ~ '[imageId]',
                    label: 'Recipe Image' |t,
                    instructions: 'Pick an image that represents this recipe' |t,
                    elementType: elementType,
                    criteria: {
                        'kind': [],
                        'localeEnabled': null,
                    },
                    sourceElementId: value.imageId,
                    sources: assetSources,
                    jsClass: 'Craft.AssetSelectInput',
                    addButtonLabel: "Select an Image" |t,
                    limit: 1,
                }) }}

I pass in the assetSources as follows:

'assetSources' => Asset::sources()

In Craft 2.x, this could be an array of sources; in Craft 3.x, this causes the error below. If I omit sources: assetSources, everything works fine (but I'm not able to limit the asset sources they can choose from).

Additional info


Stack trace:
#0 /home/vagrant/sites/craftcms/cms/src/controllers/ElementsController.php(58): craft\helpers\ElementHelper::findSource('craft\\elements\\...', Array, 'modal')
#1 [internal function]: craft\controllers\ElementsController->actionGetModalBody()
#2 /home/vagrant/sites/craft3/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#3 /home/vagrant/sites/craft3/vendor/yiisoft/yii2/base/Controller.php(154): yii\base\InlineAction->runWithParams(Array)
#4 /home/vagrant/sites/craft3/vendor/yiisoft/yii2/base/Module.php(454): yii\base\Controller->runAction('get-modal-body', Array)
#5 /home/vagrant/sites/craftcms/cms/src/web/Application.php(329): yii\base\Module->runAction('elements/get-mo...', Array)
#6 /home/vagrant/sites/craftcms/cms/src/web/Application.php(468): craft\web\Application->runAction('elements/get-mo...', Array)
#7 /home/vagrant/sites/craftcms/cms/src/web/Application.php(205): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#8 /home/vagrant/sites/craft3/vendor/yiisoft/yii2/base/Application.php(375): craft\web\Application->handleRequest(Object(craft\web\Request))
#9 /home/vagrant/sites/craft3/public/index.php(17): yii\base\Application->run()
#10 {main}
2017-02-15 00:31:07 [192.168.10.1][1][p6ebumm79hlfjogcn5l229u4t6][info][application] $_GET = [
    'p' => 'admin/actions/elements/get-modal-body'
]```
khalwat commented 7 years ago

eh... don't bother, this one is my fault.