Jump to content

Stock Photo in Custom Theme Settings


Go to solution Solved by bfarber,

Recommended Posts

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!

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

  • Solution

If I'm understanding correctly, you're creating a custom theme setting and adding the above code here:

image.png

 

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.

Link to comment
Share on other sites

Hi Brandon,

Actually its a normal Upload type configured as here:

image.thumb.png.4153cf0742a556ce71c9d1d7cb59c98c.png

 

which produces this in the AdminCP for the end user:

image.thumb.png.a39a430d39e2d0802eb29997ddc9d631.png

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:

image.thumb.png.3a385c5b9fc68c3170890e8d4370c752.png

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 by The Old Man
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Upcoming Events

    No upcoming events found
×
×
  • Create New...