Languages override bug with semantics
Submitted by clonecorp on Sat, 08/21/2021 - 15:31
Forums:
Hi,
I added this piece of code to remove some of the fields I don't need in the H5P admin section but when doing so, the selector for the languages bugs and doesn't load the translations if I change the language.
This is my code :
function h5pmods_alter_sem(&$semantics, $name) { if ($name === 'H5P.DragText') { array_splice($semantics, 0 , 1); array_splice($semantics, 1 , 1); } if ($name === 'H5P.Dictation') { array_splice($semantics, 1 , 1); array_splice($semantics, 2 , 3); } } add_action('h5p_alter_library_semantics', 'h5pmods_alter_sem', 10, 4);
Is it a problem with the code or H5P itself?
Thanks,
Jordan.
otacke
Mon, 08/23/2021 - 18:18
Permalink
Hi Jordan!If you remove
Hi Jordan!
If you remove fields with splice, then the internal structure that has been built for the translations doesn't match with the fields of the editor. That's why it breaks.
You should rather add the property widget with the value "none" to fields that you want to hide. That will do exactly that.
Also, I'd suggest not to address fields by their position in the editor, as the position might change when fields get added, removed or moved. Have a look at https://github.com/h5p/h5pmods-wordpress-plugin/blob/master/h5pmods.php#L209-L244 and https://github.com/h5p/h5pmods-wordpress-plugin/blob/master/h5pmods.php#L256-L284 that can be used to find the fields that you want to change.
Cheers,
Oliver