The Old Man Posted October 26, 2020 Posted October 26, 2020 According the docs, the Upload Helper form has a setting to toggle on Stock Photos to uploads, but it doesn't appear to be available when using an Upload image custom theme setting. if ( \IPS\Settings::i()->pixabay_enabled ) { $options['allowStockPhotos'] = TRUE; } I tried using a Code/Other type Theme Setting, but it kept throwing errors about the method not being allowed. How do I get it to show this optional stock photo picker in my image custom field setting? Many thanks!
The Old Man Posted October 27, 2020 Author Posted October 27, 2020 Hi, basically that's the full code, but I had to give up the idea so I could try and get my Halloween theme into the market ASAP. The code snippet above I found inside a method in the pixabay class. The dev docs about the 4.5 changes mention a setting has been added to the form upload helper so you can toggle the facility on/off, so I thought I would just need to put the 'allowStockPhotos' option inside the the check if the feature is available, as per the snippet above and then it would appear as an option in the upload type of custom theme setting. I think it may not have been added yet, possibly an oversight.
Solution bfarber Posted October 28, 2020 Solution Posted October 28, 2020 If I'm understanding correctly, you're creating a custom theme setting and adding the above code here: If that's correct, then yes that won't work. There is no way to modify the options for these fields at this time, but I'll raise it internally as a suggestion.
The Old Man Posted October 28, 2020 Author Posted October 28, 2020 (edited) Hi Brandon, Actually its a normal Upload type configured as here: which produces this in the AdminCP for the end user: It works but the if you have enabled Pixaby, the option to choose a Stock Photo doesn't appear. So I tried the Other/Manual type, which fills in the PHP code for you to presumably to get you started: It inserts a Text field form helper so I tried changing it to an Upload field, thinking that as its using the form helpers, and Pixabay is enabled, it would detect and show the Pixabay stock photo option: <?php return new \IPS\Helpers\Form\Text( "core_theme_setting_title_{$row['sc_id']}", $value, FALSE, array(), NULL, NULL, NULL, 'theme_setting_' . $row['sc_key'] ); After changing the form helper from text to upload, it saves okay, but when you go to view the Theme Settings I get: InvalidArgumentException: (0) #0 C:\xampp\htdocs\dev\ips4\system\Theme\Theme.php(1772) : eval()'d code(1): IPS\Helpers\Form\_Upload->__construct('core_theme_sett...', '', false, Array, NULL, NULL, NULL, 'theme_setting_u...') #1 C:\xampp\htdocs\dev\ips4\system\Theme\Theme.php(1772): eval() #2 C:\xampp\htdocs\dev\ips4\system\Theme\Theme.php(1733): IPS\_Theme->getCustomSettingField(Array) #3 C:\xampp\htdocs\dev\ips4\system\Node\Controller.php(489): IPS\_Theme->form(Object(IPS\Helpers\Form)) #4 C:\xampp\htdocs\dev\ips4\system\Node\Controller.php(388): IPS\Node\_Controller->_addEditForm(Object(IPS\Theme)) #5 C:\xampp\htdocs\dev\ips4\system\Dispatcher\Controller.php(90): IPS\Node\_Controller->form() #6 C:\xampp\htdocs\dev\ips4\system\Node\Controller.php(62): IPS\Dispatcher\_Controller->execute() #7 C:\xampp\htdocs\dev\ips4\applications\core\modules\admin\customization\themes.php(59): IPS\Node\_Controller->execute() #8 C:\xampp\htdocs\dev\ips4\system\Dispatcher\Dispatcher.php(152): IPS\core\modules\admin\customization\_themes->execute() #9 C:\xampp\htdocs\dev\ips4\admin\index.php(14): IPS\_Dispatcher->run() #10 {main} this didn't work either: <?php if ( $form === null ) { $form = new \IPS\Helpers\Form; } if ( \IPS\Settings::i()->pixabay_enabled ) { $options['allowStockPhotos'] = TRUE; } return new \IPS\Helpers\Form\Upload( "core_theme_setting_title_{$row['sc_id']}", $value, FALSE, array($options), NULL, NULL, NULL, 'theme_setting_' . $row['sc_key'] ); Edited October 28, 2020 by The Old Man
bfarber Posted November 2, 2020 Posted November 2, 2020 Yes, the eval field is to determine whether to show the setting or not. You can't modify the form helper in this manner. I've raised your suggestion internally but there is no option to do what you are attempting to do at present. The Old Man 1
The Old Man Posted November 2, 2020 Author Posted November 2, 2020 Thanks for the confirmation and putting in the request, much appreciated.
Recommended Posts