Personality Quiz - increase max answers from 10 to 20

Hi guys,

I'm wondering if anybody knows how to increase the max answers for the personality quiz from 10 to 20?

In the "semantics.json" file I can clearly see that on line 119 is the number limit, however if I increase it and then us the upload option when creating new content it doesn't seem to make a difference. My coding knowledge is minimal and I've only ever made tweaks to code like this.

Now another thing I tried that actually did get the additional answers to was manually entering the answers into the "content.json" file. When I did it this way the answers show in the Edit Interactive content however when I click save they disappear.

Any help would be appreciated. I feel like I'm so close but something small is in the way.

Thanks,
Steven

 

Content types: 
tim's picture

Hi Steven, changing the semantics should do the trick but you will also have to increase the library version. Try that and let me know how it goes. 

 

Sorry I don't know how to do a library increase change. I had originally tinkered with the code in "library.json" but didn't make much progress. Would you be able to point out which code I need to change below?

{
  "title": "Personality Quiz",
  "machineName": "H5P.PersonalityQuiz",
  "description": "Create a personality quiz and test which Game of Thrones or Hogwarts House your friends belong in.",
  "majorVersion": 1,
  "minorVersion": 0,
  "patchVersion": 8,
  "runnable": 1,
  "author": "Lumenia AS",
  "license": "MIT",
  "embedTypes": [
    "iframe"
  ],
  "preloadedJs": [
    {
      "path": "js/personalityQuiz.js"
    },
    {
      "path": "js/wheelAnimation.js"
    }
  ],
  "preloadedCss": [
    {
      "path": "css/personalityQuiz.css"
    }
  ],
  "editorDependencies": [
    {
      "machineName": "H5PEditor.ColorSelector",
      "majorVersion": 1,
      "minorVersion": 0
    }
  ]
}

tim's picture

If you change the minor version to '1' it should work. I recommend taking some time to read up  on the documentation to figure out how library development works for H5P:

https://h5p.org/library-development

Thanks for getting back to me Tim. Unfortunately changing minor version had no effect.

I had a crack at reading the library development documentation and I can't see where I'm going wrong. Again apologies my coding knowledge is very little hence why I stuck to some "easy" like just increasing a max value. Hasn't worked out that way but I'm very keen to use this module.

tim's picture

Hi Steven no worries! Just as a preliminary check, could you try clearing your cache (it's found under configuration -> performance)

Your coding knowledge shouldn't hold you back. You just need to take the time to do the following things:

1. Enable the development directory for H5P. It's under configuration

2. Navigate to it in your file system. yourdrupalsite/sites/default/files/h5p/development

3. Use git to clone the source code into the development directory

4. Adjust semantics as you mentioned

These specific details can be found in the documentation I linked above and using Google. 

Let me know if you get stuck!

Hi Tim!

I inserted the changes you mentioned here, but i can't get the 20 personalities either... i edited the semantics.json and library.json files.

Yannick

BV52's picture

HI Yannick,

What seems to be happening? And would you mind sharing the code that you changed?

-BV52

I want to be able to add more personalities to the personality quiz. I inserted my code here. :-) 

 

BV52's picture

Hi Yannick,

Everything seems to be in order and I even tried copying your code to my system and it works. Clearing cache should work if it doesn't check your browser console for error logs which should give us a clue on what is going on.

-BV52

Clear my browser cache doesn't work. Is there another place to clear the H5P cache?

There are no error logs. 

BV52's picture

Hi Yannick,

Sorry I wasn't clear about that it is Drupal's cache. It's found in configuration -> development -> performance.

-BV52

I'm using Wordpress, does that matter?

BV52's picture

Hi Yanick,

In WP it is located in wp-content/upload/h5p/cachedassets. This thread is also a good read for changes such as this.

-BV52

I removed the cached files and tried it again. No luck unfortunatly. Kinda weird right? 

BV52's picture

Hi Yannick,

I tested this in WP and we are actually getting the same result. Although I found another way thanks to some hints from a colleague. Here are the steps:

  • Download this file from github.
  • Unzip it then edit the h5pmods.php file with this code.
// If this file is called directly, abort.
if (!defined('WPINC')) {
  die;
}

function h5pmods_alter_semantics(&$semantics, $library_name) {
  if ($library_name === 'H5P.PersonalityQuiz') {
    foreach ($semantics as $semantic_field) {
      if ($semantic_field->name === 'personalities') {
        $semantic_field->max = 20;
      }
    }
  }
}
add_action('h5p_alter_library_semantics', 'h5pmods_alter_semantics', 10, 2);
  • Zip the folder again and upload as a plugin

Please note that this will not change the values in existing content, but just replace the default values for new content and exported content will not include the changes.

-BV52