Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Access extension options value in custom.php

Open SynapsisIT opened this issue 10 years ago • 14 comments

This is not a bug, so please accept my appologies for using GitHub as a "how to" help.

What I am trying to do is create an extra option for a custom extension (slider in this case), and so far I am able to do it from options.php of the extension. But what I really need is to get the value and create a condition in custom.php.

I've tried using fw_get_db_ext_settings_option() but it just gives me an array() as result on print_r()

Any hint or direction would be much appreciated.

SynapsisIT avatar Oct 29 '16 12:10 SynapsisIT

i'm not sure if i understand you but did you tried this:

fw_get_db_extension_data($extension_name, $key, $default_value = null) //- get a value from the database of some private data stored by an extension.
fw_set_db_extension_data($extension_name, $key, $value) //- extensions uses this function to store private values in the database.

fw_get_db_ext_settings_option($extension_name, $option_id, $default_value = null) //- get extension settings option value from the database.
fw_set_db_ext_settings_option($extension_name, $option_id, $value) //- update extension settings option value in the database.

DevWael avatar Oct 29 '16 14:10 DevWael

Hello, Thanks for taking your time to reply. And yes i have did try to get the extension data, but i keep getting "null" printed out (perhaps something I am missing, i am even starting to just "guess" things out after so many hours).

What I am trying to do is the next, in framework-customizations/extensions/media/extensions/slider/extensions/bx-slider/options/options.php i have created the extra option (for testing purpose - i will later on change it to switch rather than text as it is now)

'testing' => array( 'type' => 'text', 'value' => 'tested' ) What i am trying to do in custom.php (same destination as above) is to check for the "testing" option value and construction a $options = array() based on the "testing" value.

But every time i run fw_get_db_extension_data() i get a null

SynapsisIT avatar Oct 29 '16 14:10 SynapsisIT

you want to display an option to users based on the value of other option? right?

DevWael avatar Oct 29 '16 21:10 DevWael

Technically yes.

What I want to do is, set a switch option in "options.php" with values "multi_element" and "single_element".

Then on custom.php I want to check for value of the switch option and construct options based on it, example;

If switch = multi_element > create options like: title, description, image, author name etc.. else if single_element I will set other options.

The issue I am having is that I can't access the "switch" value from custom.php, but when I print_r($options) from options.php I can very well access that information. (not sure if I explained my self or created more confusion).

thank you once again for bearing with me on this.

SynapsisIT avatar Oct 29 '16 21:10 SynapsisIT

i think the multi-picker suits your needs http://manual.unyson.io/en/latest/options/built-in/multi-picker.html

did you tried it ? if it worked with you, no need for the custom.php

DevWael avatar Oct 29 '16 21:10 DevWael

Oh yes, i've played with the multi-picker, and it is an awesome feature, but it doesn't help for my case.

If I use the multi-picker then for each slide user would need to "select" again the type of slider he wants to build.

If I set this option while "creating" the slider, then each slide will have the set options that will be determined from the previous choice made during the creatin (options.php).

Let me try and illustrate the case exactly what I am trying to achieve.

I've created a custom slider option (based on bx-slider), when user chooses this slider he will need to chose the population method (which will be i will upload images by myself) and the slider type (the switch I am referring to) that will have 2 options: Custom Built and Featured Products (based on woocommerce).

If user choses custom built, then he will get all elements (including some features hidden behind multi-picker), while if he choses Featured products then he is supposed to get different options (like, specify number of products, speed of transitions etc).

This will additionally help me create a custom "views" template, where for custom built I can structure the HTML output in a different way, and for featured products in a different way.

The only thing I do need to achieve that is to know how to access in "custom.php" the value of the custom option that I will need to create in "options.php".

Sorry if I am creating more confusion with my limited english..

SynapsisIT avatar Oct 29 '16 22:10 SynapsisIT

this is confusing :D

you want the user to select an option and depending on this select, new options will appear, then if he selected one of the new options also new options will appear to him ? right?

select option ---> new options (select one of them) ---> new options will appear

if this is right you still can use the multi-picker because it supports the nesting you can create a multi-picker inside another multi-picker

DevWael avatar Oct 29 '16 22:10 DevWael

Haha, sorry about the confusion ;)

Multi-picker could be an option, but it would also mean that user will need to "specify" the style for each slide.

With what I am trying to achieve is that users specifies the style at the beginning when creating the "slider" and then all slides will have the options that are designed for that style. (pretty much same scenario as population method works > "Automatically fetch images from categories" vs "Manually, i'll upload images myself" .. depend on the population method user choses a new set of options is presented).

Hope this explains at least a little bit my wicked idea and the end goal i am trying to achieve.

(owe you a beer, at least for the confusion I am creating :D)

SynapsisIT avatar Oct 29 '16 22:10 SynapsisIT

okay i understand you, but i want to tell you something related to multi-picker if it can help you

i have made in my magazine something like this: see: http://imgur.com/5iWbYVm select (on) and you will have the options or select off and you will have another options (you will create them)

then : http://imgur.com/xRY08rg after you selected (on) you will have the available options (you have made)

then: http://imgur.com/xzNoIcO select one of the available options (selected categories) and you will have a new option to select categories (or the option you will made)

i hope this can help you, if it doesn't help you i think this man @moldcraft can help you

Best Regards...

DevWael avatar Oct 29 '16 22:10 DevWael

Thank you man, I do really appreciate you bearing with me on this.

My first instict for me was to use the multi-picker. But given that the case is for a slider (which usually has more slides in it) the same operation would need to be made again and again for each slide (in fact, I had built most of the options with multi-picker, to only figure out that it was more exhausting to "set the options" for each slide (and making sure you are selecting same/similar options on second slide as you did on first slide). I just wanted to save users the hassle of doing that for each and every slide and determine the slide options based on the choice they make during the creation of the slider (in some way I am limiting them, but in the other hand I believe i am saving time during creation of the slides), I still do have the options with multi-picker that I created, and if I can't access the $data['settings'] value from within custom.php .. i guess i'll stick with the multi-picker option.

Thank you very much @eyeswizard , i'll keep the topic open for some more time perhaps @moldcraft will have a suggestion or point me to a direction to get that value.

Cheers mate!

SynapsisIT avatar Oct 29 '16 22:10 SynapsisIT

you can change the logic a bit: create your slider setting steps with the multi-picker and at the last step create an addable option with the image and slide data upload.

with this way the user will set the slider settings and select the images without the need of re set this options for each slide.

DevWael avatar Oct 29 '16 23:10 DevWael

I've tried using fw_get_db_ext_settings_option() but it just gives me an array()

fw_get_db_ext_settings_option() works for {extension}/settings-options.php which can't be overwritten.


What is custom.php ?

ghost avatar Oct 31 '16 08:10 ghost

scratch-child\framework-customizations\extensions\media\extensions\slider\extensions\bx-slider\options*custom.php*

I've tried eyezwizards suggestion, and so far it seems to work fine tho (not simple at all, multi steps construct is a pain + getting template/titles from nested multi picker aint working) but user friendliness is quiet a mess.

Knowing how to get the value of 'testing' which is set/created in scratch-child\framework-customizations\extensions\media\extensions\slider\extensions\bx-slider\options\options.php would help me simplify the user interface to add layers to a slider

SynapsisIT avatar Oct 31 '16 15:10 SynapsisIT

Options from custom.php are available only in slider view.php in the $data variable.

ghost avatar Nov 02 '16 09:11 ghost