As an improvement over configuring the file directory path, this module should leverage the Libraries API to scan the video-js library from any valid library path. This doesn't add a hard-dependency on the Libraries API, rather, it just checks if it's functions exist. If not, it uses the path variable as a fallback.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

helior’s picture

Status: Active » Needs review
FileSize
1.07 KB
Jorrit’s picture

Status: Needs review » Postponed (maintainer needs more info)

I don't understand why you refer to version 2 of the Libraries API in your patch, as there is no version 2 of the Libraries API for Drupal 6.

Jorrit’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Status: Postponed (maintainer needs more info) » Active

I'll try to add Libraries 2 support to 7.x-2.x. For Drupal 6, the libraries API doesn't add much value.

Jorrit’s picture

Status: Active » Fixed

Committed to 7.x-2.x. Currently, the module only offers a hook_libraries_info() implementation, it does not require the libraries API as I do not want to force site maintainers to install alpha modules.

helior’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev
Status: Fixed » Needs review
FileSize
997 bytes

Thanks for looking into this Jorrit! I appreciate you implementing hook_libraries_info(). Hopefully in future releases of Libraries we can leverage all the meta data you provided to make it easier to download those assets.

I apologize about #2, that was something I overlooked about Libraries 6.x-1.x. However, there /is/ still a need to use its API to discover the location of external assets. I entirely agree with you about not forcing a dependency; using "function_exist" is a great way to basically say "It's nice to have if available, but not a requirement." Several grade-A contrib modules already use this approach to make them more adaptable to the environments they are used in (for instance, in my case where I'm developing for a multi-site installation, and I don't have access to either "sites/all" or even know the name of the subdirectory the multisite will be hosted in – this is currently not deployable without this patch.)

I hope you'll reconsider adding this to VideoJS. I re-rolled the patch from #1 with the added corrections. This patch will be for the 6.x-1.x branch, and I will eventually post a patch against 6.x-2.x as well.

helior’s picture

FileSize
3.41 KB

Please disregard the previous patch in #5. This is an updated patch that should be applied to 6.x-1.x. The process of deriving a path has been abstracted to videojs_get_path() and is replacing most instances of variable_get('videojs_directory');

helior’s picture

FileSize
2.88 KB

Here is a patch for the 6.x-2.x branch.

Jorrit’s picture

The problem I am having with this approach is that the user has no way of overriding the path when the Libraries API has detected it at some location. Lets say that I have two versions, one at sites/all/libraries/video-js and one at sites/all/libraries/video-js-old. I can't select the last directory version because the libraries API will always detect the first. I think it is best to give preference to the path that the user has given.

I'll commit the changes soon.

Jorrit’s picture

Status: Needs review » Fixed

Committed.

helior’s picture

Ah, that is a valid point. That makes sense in the rare case when two copies of the library are on the site, (sites/all/libraries might contain version 2, while sites/{site_name}/libraries can contain version 3) -- and reversing the preference in videojs_get_path() allows the configuration to override the Libraries API fallback.

Thanks for committing that!

helior’s picture

Edit: double post.

helior’s picture

Priority: Normal » Major
Status: Fixed » Needs work

Hey Jorrit, I just noticed that the code you committed had a typo that causes this feature to fail :\

module_exists('libraries_get_path');

should be

module_exists('libraries');

or

function_exists('libraries_get_path');

Also, the concept we mentioned in #8 and #10 doesn't actually currently work the way we expect it to. VideoJS still takes precedence of sites/all over multi-site installations. Libraries API can figure out the correct order of preference, and we can still have the path overridable by the user, all it takes is a little bit of rearranging in videojs_get_path(). I'll post a patch against 6.x-2.x soon.

helior’s picture

Status: Needs work » Needs review
FileSize
4.98 KB

Also added a checkbox to reset the configured path if the user wants the system to just figure it out.

Jorrit’s picture

Why isn't the code section that checks the user-provided path before the libraries path? Now, when a user has entered a path, the libraries code is always invoked, but the result is never used. Or am I missing something?

helior’s picture

function videojs_get_path() {
  // Default directory path.
  $directory = 'sites/all/libraries/video-js';

  // Libraries API integration - In case VideoJS library is in multiple
  // locations (profiles/{profile_name}/libraries, sites/all/libraries,
  // sites{site_name}/libraries ) Libraries API can determine which copy should
  // take presidence...
  if (module_exists('libraries') && $libraries_dir = libraries_get_path('video-js')) {
    if (file_exists($libraries_dir . '/video.js')) {
      $directory = $libraries_dir;
    }
  }

  // ...However, we also give the user the opportunity to override the path.
  if ($conf_dir = variable_get('videojs_directory', NULL)) {
    if (file_exists($conf_dir . '/video.js')) {
      $directory = $conf_dir;
    }
  }

  return $directory;
}

In videojs_get_path() the $directory variable is altered from lowest priority to highest:

It starts with the default path "sites/all/libraries/video-js";
Then, if the Libraries API is available it will discover paths that /actually/ exist and reassign $directory;
Finally we check if the user had in fact configured the "videojs_directory" setting, and use that path over any previous discovered path.

Previously, "sites/all/libraries" was taking preference over Libraries API paths, which is incorrect. The idea is to use the most specific library path available, but still let the user configure a custom path, if they choose.

Order of library path specificity should be:
profiles/{profile_name}/libraries
sites/all/libraries
sites/{site_name}/libraries
** path/to/user/defined/directory **

Once the "videojs_directory" setting is configured however, Library API paths are ignored completely. That's why I added a checkbox to "reset" the variable so the system can continue to decide what path is best.

helior’s picture

FileSize
4.96 KB

Re-rolling patch to accommodate for recent changes in 6.x-2.x

Jorrit’s picture

I am still not happy with this. Consider the following sequence of events. Lets say someone wants to use the Libraries API provided path. That person would toggle the new "Reset file directory setting" checkbox and submit the form. This would work. However, lets say that person later decides to change the resolution and submits the settings form. The path would now once again be fixed to sites/all/libraries/video-js, without the user having changed anything to those settings.

helior’s picture

FileSize
7.14 KB

Yea, I know what you mean. I've ran into that also, but felt it was just a bit out of scope to what this issue is addressing. I can solve that "UI wtf" by splitting up the configuration into a different local task. Like this..?

helior’s picture

With this patch I am now finally able to use it with multi-site installations (where access to sites/all is not an option), as well as install profiles. I think I have pretty much addressed all of your concerns in a fair amount of detail -- what direction do you want to go with this issue Jorrit?

Jorrit’s picture

I still don't understand why the current version is not working for you. What the current version does, is the following:

1) Look at the value provided by the user
2) If Video.js is not found and the libraries API is installed, ask the libraries API for a path

Could you describe how your directory layout looks like? And why the above procedure is not working for you?

Jorrit’s picture

Status: Needs review » Postponed (maintainer needs more info)

I have found a way to combine your patch with a simpler administrative UI, see the following commit: http://drupalcode.org/project/videojs.git/commit/ee5a43e

I hope you like this approach.

Jorrit’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Closed because of lack of response.