{"id":1680,"date":"2020-10-01T22:17:03","date_gmt":"2020-10-01T22:17:03","guid":{"rendered":"https:\/\/jrdingwall.ca\/blogwall\/?p=1680"},"modified":"2020-10-01T22:23:27","modified_gmt":"2020-10-01T22:23:27","slug":"playing-tag-with-h5p-mods-adding-buttons","status":"publish","type":"post","link":"https:\/\/jrdingwall.ca\/blogwall\/playing-tag-with-h5p-mods-adding-buttons\/","title":{"rendered":"Playing Tag with H5P Mods &#8211; Adding Buttons"},"content":{"rendered":"<p>All tools have their limitations, that&#8217;s just a fact. What is nice about using something like H5P is that there is a bit of a community that works on customizing it in addition to the core team of developers. That&#8217;s actually how I managed to snag a flashcard content type (built in dialog cards) prior to the official flashcard content type coming out.<\/p>\n<p>The CKEditor varies across H5P content types, which can really bring a project to a screeching halt. For example, take a look at the text editor for the Accordion type (first) and the Multiple Choice content type (second).<\/p>\n<figure id=\"attachment_1681\" aria-describedby=\"caption-attachment-1681\" style=\"width: 904px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1681 size-full\" src=\"https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-3.33.09-PM.png\" alt=\"h5p accordion ckeditor\" width=\"904\" height=\"187\" srcset=\"https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-3.33.09-PM.png 904w, https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-3.33.09-PM-300x62.png 300w, https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-3.33.09-PM-768x159.png 768w\" sizes=\"auto, (max-width: 904px) 100vw, 904px\" \/><figcaption id=\"caption-attachment-1681\" class=\"wp-caption-text\">h5p accordion ckeditor<\/figcaption><\/figure>\n<figure id=\"attachment_1682\" aria-describedby=\"caption-attachment-1682\" style=\"width: 937px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1682 size-full\" src=\"https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-3.32.48-PM.png\" alt=\"h5p multiple choice ckeditor\" width=\"937\" height=\"188\" srcset=\"https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-3.32.48-PM.png 937w, https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-3.32.48-PM-300x60.png 300w, https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-3.32.48-PM-768x154.png 768w\" sizes=\"auto, (max-width: 937px) 100vw, 937px\" \/><figcaption id=\"caption-attachment-1682\" class=\"wp-caption-text\">h5p multiple choice ckeditor<\/figcaption><\/figure>\n<p>I encountered my first roadblock with this years ago working on a pharmaceutical calculations course. At the time we used MCQs in the course content to provide practice opportunities for students, with some feedback built in, but the feedback field in H5P at the time would not allow us to provide a full equation solution so we opted for the Accordion to do that. However, what is something that you see in the MCQ editor that you don&#8217;t see in the Accordion editor? It&#8217;s pretty important for math AND chemical compound notation. That&#8217;s right, sub and super script isn&#8217;t there. Even copying and pasting from word wouldn&#8217;t make it stick. So this required some extra work. At the time I added to the <a href=\"https:\/\/github.com\/h5p\/h5pmods-wordpress-plugin\">H5P Mods WordPress Plugin<\/a> and managed to get it working (I broke my entire WPMS multiple times trying this). Over time though, H5P kept getting updates and I didn&#8217;t touch the Mods plugin and it ended up jamming the H5P hub. All the current activities worked and I could upload new H5P content to the site, but I could not create anything new right within WordPress.<\/p>\n<p>Recently, I did an activity\u00a0<a href=\"https:\/\/jrdingwall.ca\/blogwall\/converting-static-content-into-interactive-e-learning-299\/\" target=\"_blank\" rel=\"noopener noreferrer\">Converting Static Content Into Interactive E-Learning #299<\/a> and ran into a similar issue which brought me back to this idea of the H5P Mods plugin.<\/p>\n<p>I went back to the original H5P Mods plugin, got it again, and started from there (not using any of the work I&#8217;d done before), I needed a fresh start. If you look at the sample H5P Mods plugin, you&#8217;ll see it has some sample sections. Some are for score keeping of activities, one is a CSS reference (going to have to try playing with that later), and so on. I cleared out most of that, and then had to add some php to connect to the CKeditor (you&#8217;re about to find out I don&#8217;t use any of this lingo correctly).<\/p>\n<div class=\"dm-code-snippet dark default  dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"wrap language-php\">\n<pre class=\"dm-pre-admin-side\">\/**\r\n  *Adding extra buttons to the WYSIWYG text editor\r\n*\/\r\nfunction mymods_h5p_semantics_alter(&amp;$semantics, $library_name = NULL) {\r\n    foreach ($semantics as $field) {\r\n      \/\/ Go through list fields\r\n      while ($field-&gt;type === 'list') {\r\n        $field = $field-&gt;field;\r\n      }\r\n   \r\n      \/\/ Go through group fields\r\n      if ($field-&gt;type === 'group') {\r\n        mymods_h5p_semantics_alter($field-&gt;fields, $library_name); \/\/ Check your function name!\r\n        continue;\r\n      }\r\n   \r\n      \/\/ Check to see if we have the correct type and widget\r\n      if ($field-&gt;type === 'text' &amp;&amp; isset($field-&gt;widget) &amp;&amp; $field-&gt;widget === 'html') {\r\n         \/\/ Found a field. Add support for the following tags.\r\nif (!isset($field-&gt;tags)) {\r\n$field-&gt;tags = array();\r\n}\r\n\r\n\r\n\r\n\r\n\r\nadd_action('h5p_alter_library_semantics', 'mymods_h5p_semantics_alter');<\/pre>\n<\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>This gets us down to the point where we can now specify the tags we are interested in adding. If you check out the\u00a0 <a href=\"https:\/\/github.com\/h5p\/h5p-editor-php-library\/blob\/master\/scripts\/h5peditor-html.js\">h5p-editor-php-library<\/a> you&#8217;ll be able to see that a number of markup items are labelled as tags such as:<\/p>\n<ul>\n<li>u<\/li>\n<li>sup<\/li>\n<li>sub<\/li>\n<\/ul>\n<p>and more. The way I wrote this up isn&#8217;t slick, as I&#8217;m sure I should be able to merge the array, but this worked for me:<\/p>\n<div class=\"dm-code-snippet dark default  dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-php\">\n<pre class=\"dm-pre-admin-side\">\/\/ Add format group if formatters in tags (h1, h2, etc). Formats use their\r\n        \/\/ own format_tags to filter available formats.\r\n        if (!in_array($field-&gt;tags)) {\r\n          $field-&gt;tags[] = 'strong';\r\n          $field-&gt;tags[] = 'em';\r\n          $field-&gt;tags[] = 'u';\r\n          $field-&gt;tags[] = 'del\/strike\/s';\r\n          $field-&gt;tags[] = 'h1';\r\n          $field-&gt;tags[] = 'h2';\r\n          $field-&gt;tags[] = 'h3';\r\n          $field-&gt;tags[] = 'h4';\r\n          $field-&gt;tags[] = 'h5';\r\n          $field-&gt;tags[] = 'h6';\r\n          $field-&gt;tags[] = 'a';\r\n          $field-&gt;tags[] = 'ul';\r\n          $field-&gt;tags[] = 'ol';\r\n          $field-&gt;tags[] = 'hr';\r\n          $field-&gt;tags[] = 'sup';\r\n          $field-&gt;tags[] = 'sub';\r\n          $field-&gt;tags[] = 'blockquote';\r\n          $field-&gt;tags[] = 'img';\r\n          $field-&gt;tags[] = 'address';\r\n          $field-&gt;tags[] = 'pre';\r\n          $field-&gt;tags[] = 'p';\r\n          $field-&gt;tags[] = 'div';\r\n          $field-&gt;tags[] = 'span';\r\n          $field-&gt;tags[] = 'code';\r\n        }<\/pre>\n<\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>So now when we go look at both the Accordion and MCQ content type editors we get the following:<\/p>\n<figure id=\"attachment_1688\" aria-describedby=\"caption-attachment-1688\" style=\"width: 723px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1688 size-full\" src=\"https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-4.02.53-PM.png\" alt=\"h5p mods accordion ckeditor\" width=\"723\" height=\"213\" srcset=\"https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-4.02.53-PM.png 723w, https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-4.02.53-PM-300x88.png 300w\" sizes=\"auto, (max-width: 723px) 100vw, 723px\" \/><figcaption id=\"caption-attachment-1688\" class=\"wp-caption-text\">h5p mods accordion ckeditor<\/figcaption><\/figure>\n<figure id=\"attachment_1687\" aria-describedby=\"caption-attachment-1687\" style=\"width: 725px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1687 size-full\" src=\"https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-4.02.36-PM.png\" alt=\"h5p mods mcq ckeditor\" width=\"725\" height=\"203\" srcset=\"https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-4.02.36-PM.png 725w, https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/Screen-Shot-2020-10-01-at-4.02.36-PM-300x84.png 300w\" sizes=\"auto, (max-width: 725px) 100vw, 725px\" \/><figcaption id=\"caption-attachment-1687\" class=\"wp-caption-text\">h5p mods mcq ckeditor<\/figcaption><\/figure>\n<p>So we are beginning to see more overlap between the two. Both now have\u00a0<em>underline<\/em> and the Accordion picked up\u00a0<em>sub\u00a0<\/em>and\u00a0<em>superscript.<\/em> AND my site didn&#8217;t break. In each case I&#8217;ve also now got way more heading levels and paragraph format types than we had before.<\/p>\n<p>If you have a keen eye you&#8217;ll notice something though, not ALL of the tags are appearing. For example, p, div, and span don&#8217;t appear and neither does\u00a0<em>img<\/em>. Doing a bit of digging I found that some of these items appear along the bottom when using the editor and are not necessarily buttons, but also some tags such as\u00a0<em>img<\/em> require adding some additional Javascript to the website. I haven&#8217;t made it that far yet.<\/p>\n<p>Now, onto the next hurdle for me to jump. You&#8217;ll notice in the MCQ editor that <em>font size<\/em>, <em>text color<\/em>, and <em>background color<\/em> don&#8217;t appear, and yet they appear in the Accordion. This was a bit of a pain when I was working on the elearning hero challenge #299, because the background I was using made the MCQ question text impossible to read, and I could NOT change the text color. I had to do a bit of a work around which was ok, but not ideal. Going back to the h5p editor php library I can see that say font color is an available item:<\/p>\n<div class=\"dm-code-snippet dark default  dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-php\">\n<pre class=\"dm-pre-admin-side\">if (this.field.font.color) {\r\n      \/\/ Text color chooser\r\n      colors.items.push('TextColor');\r\n\r\n      if (this.field.font.color instanceof Array) {\r\n        ret.colorButton_colors = getColors(this.field.font.color);\r\n        ret.colorButton_enableMore = false;\r\n      }\r\n    }<\/pre>\n<\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>But the big difference is that it is not executed simply with a tag. When I looked up the <a href=\"https:\/\/github.com\/h5p\/h5p-advanced-text\/blob\/master\/semantics.json\">h5p advance text \/ semantics.json<\/a> I see that they list tags, and that font is identified lower down:<\/p>\n<div class=\"dm-code-snippet dark default  dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-markup\">\n<pre class=\"dm-pre-admin-side\">[\r\n  {\r\n    \"name\": \"text\",\r\n    \"type\": \"text\",\r\n    \"widget\": \"html\",\r\n    \"label\": \"Text\",\r\n    \"importance\": \"high\",\r\n    \"enterMode\": \"p\",\r\n    \"tags\": [\r\n      \"strong\",\r\n      \"em\",\r\n      \"del\",\r\n      \"a\",\r\n      \"ul\",\r\n      \"ol\",\r\n      \"h2\",\r\n      \"h3\",\r\n      \"hr\",\r\n      \"pre\",\r\n      \"code\"\r\n    ],\r\n    \"font\": {\r\n      \"size\": true,\r\n      \"color\": true,\r\n      \"background\": true\r\n    }\r\n  }\r\n]<\/pre>\n<\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n<p>When you edit the text color with the Accordion content type, the tag it throws is\u00a0<em>span<\/em> so on the one hand I think I&#8217;ve got this part way there, but what I&#8217;m currently missing is how to get hooks into the buttons and have them display in all content type editors. Given the headached I have from getting this far, I&#8217;ll put this project down for a bit and maybe I&#8217;ll have some ideas come to mind over the next couple of days.<\/p>\n<hr \/>\n<p>Photo by <a href=\"https:\/\/unsplash.com\/@lucabravo?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Luca Bravo<\/a> on <a href=\"https:\/\/unsplash.com\/s\/photos\/php?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\">Unsplash<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>All tools have their limitations, that&#8217;s just a fact. What is nice about using something like H5P is that there is a bit of a community that works on customizing it in addition to the core team of developers. That&#8217;s actually how I managed to snag a flashcard content type (built in dialog cards) prior [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1689,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"webmentions_disabled":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[16],"tags":[],"class_list":["post-1680","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-educational-technology-and-design"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/jrdingwall.ca\/blogwall\/files\/2020\/10\/luca-bravo-XJXWbfSo2f0-unsplash.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/jrdingwall.ca\/blogwall\/wp-json\/wp\/v2\/posts\/1680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jrdingwall.ca\/blogwall\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jrdingwall.ca\/blogwall\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jrdingwall.ca\/blogwall\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jrdingwall.ca\/blogwall\/wp-json\/wp\/v2\/comments?post=1680"}],"version-history":[{"count":6,"href":"https:\/\/jrdingwall.ca\/blogwall\/wp-json\/wp\/v2\/posts\/1680\/revisions"}],"predecessor-version":[{"id":1691,"href":"https:\/\/jrdingwall.ca\/blogwall\/wp-json\/wp\/v2\/posts\/1680\/revisions\/1691"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jrdingwall.ca\/blogwall\/wp-json\/wp\/v2\/media\/1689"}],"wp:attachment":[{"href":"https:\/\/jrdingwall.ca\/blogwall\/wp-json\/wp\/v2\/media?parent=1680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jrdingwall.ca\/blogwall\/wp-json\/wp\/v2\/categories?post=1680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jrdingwall.ca\/blogwall\/wp-json\/wp\/v2\/tags?post=1680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}