Styles in CP Editor lost after update

Hi,

Recently updated H5P to 7.x-1.26  on our Drupal install. We had included some custom CSS and JS previously for the Course Presentation in a custom module as:

function cdclearning_h5p_styles_alter(&$styles, $libraries, $mode) {
  if (isset($libraries['H5P.CoursePresentation']) && $libraries['H5P.CoursePresentation']['majorVersion'] == '1'){
    $styles[] = (object) array(
      // Path relative to drupal root         
      'path' => drupal_get_path('theme', 'cdc_platon') . '/css/eff_cp.css',            
      // Cache buster
      'version' => '?ver=2',
    );

 (and the the script hook for the JS).

Previously the custom CSS and JS worked when both viewing the CP and when creating CP content with the editor.

However, now the editor doesn't pick up any of the CSS and JS files that were included. When saved and viewing the CP the CSS is applied correctly. But writing content semi-blind to how it will appear when saved is proving to be a bit of a headache!

Checking the <head> of the iframe shows the extra files when viewing the CP but not when on the editor page.

I've tried adding the hooks as described on: https://h5p.org/change-color-of-the-editor but even then I'm unsuccessful.

function cdclearning_h5p_scripts_alter(&$scripts, $libraries, $mode) { 
  if ($mode == 'editor') {
    $scripts[] = (object) array(
      // Path relative to drupal root
      'path' => drupal_get_path('theme', 'cdc_platon') . '/js/eff_h5peditor_html.js',
    // Cache buster
    'version' => '?ver=2',
    );  
  }
}

If you can spot anything I might have made a mistake with, or if the recent improvements to the editor require some extra steps, would really make my day!

Thanks!

Content types: 
fnoks's picture

Hi,

Is your site set up to aggregate JavaScript and CSS? If so, is it possible for you to test this without the aggregation enabled? Also, please check the Drupal's dblog (http://<yoursite>/admin/reports/dblog)

Ah, forgot had JS and CSS aggregation turned on. 

Looking through the logs, I get this warning for the files I'm trying to include:

"Warning: file_get_contents(sites/default/files/h5psites/default/themes/cdc_platon/css/eff_cp.css): failed to open stream: No such file or directory in H5PDefaultStorage->getContent() (line 288 of /srv/councilfordisabledchildren.org.uk/public/htdocs/sites/all/modules/h5p/library/h5p-default-storage.class.php)."

In the hooks though, the path im setting for the files to be included is: (I tried both approaches of using drupal_get_path and giving the full hardcoded path)

$styles[] = (object) array(
      // Path relative to drupal root 
      //'path' => drupal_get_path('theme', 'cdc_platon') . '/css/eff_cp.css',  
      'path' => 'sites/default/themes/cdc_platon/css/eff_cp.css',
      // Cache buster
      'version' => '?ver=3',
    );

watchdog("cdclearning_h5p_styles_alter", drupal_get_path('theme', 'cdc_platon'));

The watchdog returns the path as it should be:

Array ( [0] => stdClass Object ( [path] => sites/default/themes/cdc_platon/css/eff_cp.css [version] => ?ver=3 ) )

I'm not sure where the "sites/default/files/h5psites/" first part of path that is being included in the warning is being applied.

fnoks's picture

Thank you for your followup. What you are experiencing is a bug we actually fixed a few days ago, but it is not yet tested or released. In the meantime you could make the URL's to the files absolute (including scheme and domain), e.g:

'path' => 'https://yoursite.com/sites/default/themes/cdc_platon/css/eff_cp.css'

This should fix it temporarily

Perfect, that's fixed it for now!

Thank you very much for your help! :)

 

fnoks's picture

Good to hear :)