how to change a field widget
Submitted by dbaumeister on Tue, 10/10/2017 - 02:59
Forums:
Hello!
I would like to customize the H5P.PersonalityQuiz content type so that one (or some, or all) of the fields of type "text" can be made to allow a few basic html tags (e.g., strong, em, a, etc.). I use Drupal and am trying use hook_h5p_semantics_alter to add the 'html' widget to every field of type "text," but clearly I'm not doing it right.
Here's what my custom module (called mhl_h5p_mods) has right now:
function mhl_h5p_mods_h5p_semantics_alter(&$semantics, $machine_name, $major_version, $minor_version) { foreach ($semantics as $field) { // Go through list fields while ($field->type === 'list') { $field = $field->field; } // Go through group fields if ($field->type === 'group') { mhl_h5p_mods_h5p_semantics_alter($field->fields); continue; } // Check to see if we have the correct type if ($field->type === 'text') { // Found a field. Add the html widget. [Does not work.] $field->widget = 'html'; } } }
I'm sure I'm missing something basic and appreciate any help people can give. Thanks in advance!
Content types:
icc
Tue, 10/10/2017 - 09:15
Permalink
Your code looks fine but
Your code looks fine but appears to be missing a & symbol in front of the $field variable in the foreach to make it a reference, like so:
dbaumeister
Tue, 10/10/2017 - 14:45
Permalink
Perfect. Thank you!
Perfect. Thank you!
joshlopez
Tue, 11/14/2017 - 20:13
Permalink
I am using this code for my
I am using this code for my personality test but the buttons to add additional personalities and questions are gone now. Any suggestions? I really only need html for the description fields for the personalities. I am using drupal 7.
icc
Wed, 11/15/2017 - 11:16
Permalink
Could you share a screenshot
Could you share a screenshot of the issue and also include your code?
Have you checked the 'Recent log messages' in Drupal for anything that seems related to this after opening the editor?
joshlopez
Wed, 11/15/2017 - 19:03
Permalink
Im using the same code as
Im using the same code as above. Without the custom module and code I have the ability to add other personality types, questions, and answers but with the code in those buttons go away for some reason. The html editor shows up but the buttons disapear.
icc
Thu, 11/16/2017 - 12:47
Permalink
It sounds like something must
It sounds like something must have gone wrong when you reused the code.
Is your module named the same as well? If not did you remember to update the naming of the function and then the usage of the function inside itself to be the same?
Did you remember to apply the fix I commented?
Are you getting any error messages in your browser's console or in the web server's error_log file?
I just tried the same code in my custom module and it works as expected. Did you make any modifications?
joshlopez
Sat, 11/18/2017 - 02:02
Permalink
Hey sorry i was away for a
Hey sorry i was away for a couple days. Here is the code I have. The module is named h5p_custom.module.
fnoks
Wed, 11/22/2017 - 14:39
Permalink
Could you share a screenshot
Could you share a screenshot of the issue?