Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
function ds_extras_field_template_settings_form(array &$form, array &$form_state, array $context) {
$functions = module_invoke_all('ds_field_theme_functions_info');
...
First line in the function allows us to add templates, but we cannot provide our own settings for the template (at least from what I can tell). I am not sure where best to place the hook, either before or after DS's settings are setup, but can we add in something like:
$form = module_invoke_all('ds_field_theme_functions_settings', $form, $form_state, $context);
We would then be able to inject our own settings into the form. Thanks
Comment | File | Size | Author |
---|---|---|---|
#18 | 1639846-18.patch | 1.3 KB | aspilicious |
#1 | hook_ds_extras_field_template_settings_form-1639846-1.patch | 743 bytes | nicholas.alipaz |
Comments
Comment #1
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedAttached is a patch and below what implementation in my custom module looks like:
And the corresponding mymodule.admin.js file:
Comment #2
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedBTW, the implementation in my module simply makes the colon default to off and you must explicitely turn it on.
Comment #3
swentel CreditAttribution: swentel commentedThanks, committed and pushed!
Comment #4
swentel CreditAttribution: swentel commentedHad to rework this one, forms where completelely broken.
Comment #5
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedHmmm, I hadn't experience any issue on my sites. What are you seeing that is broken?
Comment #6
swentel CreditAttribution: swentel commentedThere form is just completely empty, will debug this weekend on it.
Comment #7
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedperhaps if no modules are invoking then it would be empty? I can try that with a default install. We likely need to check if any modules invoke first.
Comment #8
swentel CreditAttribution: swentel commentedMaybe it's a better a idea to use an alter hook instead of module_invoke_all as well ? That way, the receiving function needs to take the form parameter by ref and we're always safe as well.
Comment #9
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedHi,
Is there any news on this ?
I created a custom field template using hook_ds_field_theme_functions_info() but I can't figure out how to add custom settings for this template the same way the 'Expert' template has.
I am going to try the solution above but the post is quite old, so if someone has more updated info I would appreciate it!
Thanks !
Comment #10
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedHow would you add an alter hook for example ?
Comment #11
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedHow about this ? Could it be pushed in next version ? Sorry I don't know how to create a patch yet.
Comment #12
aspilicious CreditAttribution: aspilicious commentedTo be honest, the field template stuff in D7 is not really extendable for various reasons.
For the D8 versions I'm rewriting this.
So I'm not sure I can do anything for you.
I can add an alter but It would not behave correctly in every situation.
I prefer no solution than a half baked one.
Unless you can proove I'm wrong :) (I hope I'm wrong)
Comment #13
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedOk so far the code above is working for me except one major problem : the value of the setting is not saved into the database. When I click Update on the field settings form it gets saved as long as I stay on the Manage Display page. But if I click Save at the end of the manage display page the value is not saved into the database. Is there any _submit function I should alter too in order to save my values ?
Comment #14
aspilicious CreditAttribution: aspilicious commentedThats the whole problem. :)
Thats why it isn't working properly and why I'm rewriting it for D8.
Comment #15
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedAlright I finally figured it out!
For the data to be saved, one must implement hook_ds_field_settings_alter()
To understand what must be done, one can have a look at the implementation inside ds_extra.module arround line 800
in my case I wrote the following :
Be careful that in ds_extra implementation, the $field_settings[$key]['formatter_settings']['ft'] array gets re-initialized!
So one must make sure its custom module is called after DS Extra. From what I read, hook_alter implementations are called in order of the module's weight. Because DS Extra's weight is 2, I had to set the weight of my module to be 3 at least.
Ok so in the end the only core modification I had to do is the one mentioned above so if you could add it to the next 7.x version that would be awesome :) Here it is again...
Comment #16
aspilicious CreditAttribution: aspilicious commentedI'll look at it somewhere this week.
Comment #17
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedgreat thx!
Comment #18
aspilicious CreditAttribution: aspilicious commentedCan you try the attached patch?
Comment #19
Nicolas Bouteille CreditAttribution: Nicolas Bouteille commentedBig rush last week before leaving in holidays right now. Will not be able to test before feb. 3rd but will do! Thx a lot.
Comment #20
aspilicious CreditAttribution: aspilicious commentedThis is already in ds for months :D