Unfortunately it was going to be difficult to break this functionality into separate patches, since the code is so closely interconnected. We are including four items in this patch:

* Include preset sources option
* Include Sharing Sites option
* Include Mute option
* Improve form validation

The preset sources option in particular needs some explanation. The current 7.x-2.x setup does not allow for local preset settings to override player settings. Also, there is no option to allow developers to use a predefined JW Player preset on the site. What we're attempting to do is meet the conditions shown shown here in this 2x2 diagram:

https://support.jwplayer.com/customer/portal/articles/1406723#fndtn-meth...

There needs to be support for choosing to use JW Player or Drupal as the source for preset information.

The other items in the list are fairly straightforward. Sharing Sites allows for configuration of sharing options with the player (facebook, twitter, email, etc.). Mute allows for the player to start with sound disabled. This is extremely important for sites that want to autostart the player, but do so with sound disabled (this is a common feature on many websites these days).

The final piece is improved validation. There are lots of places in the admin forms that need better data checking, such as:

* Display only the necessary fields on the admin settings page based on version and hosting.
* Require cloud player URL if hosting is set to cloud-based.
* Require cloud player URL to match format of JW Player's URLs.
* Require license key if hosting type is self-hosted.
* Require width field to be between 0% and 100% if dimensions are responsive.
* Require aspect ratio format to be two numbers separated by a colon.
* Require width and height formats to be greater than 0.
* Require player library URL to match format set by JW Player.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ron_s created an issue. See original summary.

ron_s’s picture

Status: Active » Needs review
Related issues: +#2713687: Improve formatter summaries
FileSize
31.86 KB

Attached is the patch for review. Please note, the playlist options have been re-enabled in this patch with a check against using the legacy version of JW Player. More about this will be seen in the next patch we have for refactoring the module theming.

Also very important to note, the formatter summaries for Sharing Sites and Mute will *not* be shown without another patch we created: https://www.drupal.org/node/2713687

Please apply the #2713687 patch to see the options.

ron_s’s picture

Making a note regarding this request for the Loop option: https://www.drupal.org/node/1330634

Once we're able to get these patches committed, it will be easy to add Loop to the updated admin layout.

Berdir’s picture

Status: Needs review » Needs work
  1. +++ b/jw_player.admin.inc
    @@ -25,6 +25,28 @@ function jw_player_settings_form($form) {
    +  $form['jw_player_hosting'] = array(
    +    '#type' => 'radios',
    +    '#title' => t('Hosting type'),
    +    '#options' => array(
    +      'self' => t('Self-Hosted'),
    +      'cloud' => t('Cloud-Hosted'),
    

    Isn't this implied by the license key vs cloud hosted option? What do we gain from an additional setting?

    Can't we just say that either the license key or the cloud url must be provided? Not sure what we should do when both are added.

  2. +++ b/jw_player.admin.inc
    @@ -61,7 +102,82 @@ function jw_player_settings_form($form) {
    +  // Including a "preset source" allows for local Drupal presets that override
    +  // cloud-hosted player settings in JW Player 7.
    +  $form['jw_player_preset_source'] = array(
    +    '#type' => 'radios',
    +    '#title' => t('Preset source'),
    +    '#options' => array(
    +      'drupal' => t('Use Drupal-defined presets'),
    +      'jwplayer' => t('Use presets defined on JWPlayer.com'),
    +    ),
    +    '#default_value' => variable_get('jw_player_preset_source', 'drupal'),
    +    '#description' => t('When creating JW Player presets, select if the source should be defined on Drupal, or by using definitions set within your JWPlayer.com account.'),
    +    '#states' => array(
    +      'visible' => array(
    +        array(
    +          'select[name="jw_player_version"]' => array('value' => '7'),
    +          ':input[name="jw_player_hosting"]' => array('value' => 'cloud'),
    +        ),
    +      ),
    

    What if each preset has a checkbox "[x] Override cloud presets" or so? That's something that I've been thinking about. The other idea we've had is to have a per-preset cloud url (that's why the default one is called... default).

  3. +++ b/plugins/export_ui/jw_player_ctools_export_ui.inc
    @@ -115,174 +115,330 @@ function jw_player_ctools_export_ui_form(&$form, &$form_state) {
    +  else {
    +    $form['settings']['player_library_url'] = array(
    +      '#type' => 'textfield',
    +      '#title' => t('Player Library URL'),
    +      '#description' => t('Enter the URL to the player created on JWPlayer.com that contains the settings for this preset.'),
    +      '#required' => TRUE,
    +    );
       }
    

    I see, that's basically what you did here.

  4. +++ b/plugins/export_ui/jw_player_ctools_export_ui.inc
    @@ -115,174 +115,330 @@ function jw_player_ctools_export_ui_form(&$form, &$form_state) {
    +  $form['settings']['#attached']['js'] = array(
    +    drupal_get_path('module', 'jw_player') . '/js/jw_player.admin.js',
    

    why make it a library when you then add it with #attached js?

ron_s’s picture

Isn't this implied by the license key vs cloud hosted option? What do we gain from an additional setting?

There are two main ideas. The first is to try to streamline the process. For someone who is not as knowledgeable about self vs. cloud, 6 vs. 7, etc. it is possible to create a situation where settings are saved that won't work. For example, I'm quite sure cloud-hosting wasn't an option in JW Player 5. However the form as constructed will allow that to happen.

The second idea is clearly identifying if the user will or will not be using the cloud. This is what allows us to later in the options ask for the Preset Source setting. If a user has decided to self-host, we don't need to ask about Preset Sources, because we know everything will be done on Drupal.

Can't we just say that either the license key or the cloud url must be provided? Not sure what we should do when both are added.

Sure, we are saying that indirectly... but I want to clearly know "self" or "cloud", because license keys, URLs, etc. change all the time. In the future, maybe JW Player won't even require a license key for self-hosting... but self vs. cloud is a clear delineation that allows us to determine if Preset Sources should be an option.

As for not sure what to do when both are added, I'm assuming you mean existing users? I definitely think it should default to self-hosting. Anyone using cloud-hosting (today) is limited in what they can do... basically all the Drupal preset options are not used, and JW Player 7's configuration overrides everything. With self-hosting, we know that whatever Drupal presets are created will be honored.

What if each preset has a checkbox "[x] Override cloud presets" or so ... I see, that's basically what you did here.

Yes, exactly. Depending on the Preset Sources options selected, either the user gets the full Drupal preset experience, or can enter URLs to reference JW Player configurations. Maybe you're suggesting it would be better to have this as a toggle, where if a checkbox is selected, it switches between the Drupal-defined presets and the JW Player URL. Let me know your thoughts.

why make it a library when you then add it with #attached js?

Good question. Would like to load it as a library, but there's something strange with jw_player_ctools_export_ui_form. The JavaScript was acting unpredictably... it would work correctly, then stop working. Didn't have this problem with other libraries, and no issue when we tried to attach jw_player.admin.js as a library to other forms. Not sure if it might be something to do with the fact that it's a ctools hack.

ron_s’s picture

One additional comment about the idea of overriding cloud presets. The reason we created it the way we did is it would allow users to set up multiple cloud presets if they wish. For example, if users want a smaller "thumbnail" size player on Views that use a teaser view mode, a larger size player on full nodes, and want to host all of the configuration on JW Player, they can do so.

Just having an "override cloud presets" option won't allow this to work. I think if we wanted to have an override option, it should be an override to whatever the default is. We could take this type of approach on the preset forms, with just a radio button toggle, and the #default_value is based on what is set in the general settings:

( ) Drupal-defined preset
(*) JW Player cloud-based preset

Player URL Library: ____________________________
Enter the URL to the player created on JWPlayer.com that contains the settings for this preset

==========================

(*) Drupal-defined preset
( ) JW Player cloud-based preset

Skin
[____________v]

Stretching
[________________________v]

[X] Autostart

[X] Use a Responsive Design

etc...

Berdir’s picture

Right, that's pretty much what I had in mind. But for that, you don't need a global setting. That's something that you can and want to do per-preset.

Only suggestion on that would be to clarify in the description for the cloud based mode that providing a preset for the override is optional and it will use the global one by default. There is a default url, you're going to be using that for at least one of your presets I guess.

Berdir’s picture

Some more things.

* The cloud URL validation fails on protocol-relative URLs (//content.jwplatform.com/libraries/...)
* is the skin really supposed to be the only thing shown when using cloud? why just that and not the other things?
* Based on what I wrote above, the library URL should be non-required for a preset.

Berdir’s picture

And one more thing, sorry for the many comments.

As far as I see, the per-preset cloud URL isn't used yet? In 7.x, that's relatively easy to address, as you can add #attached js directly. But we do need to prevent that the global one isn't added.

In 8.x, it will be a bit more complicated, we'll have to register a library for each preset that uses a cloud-override and use that in place of the global one.

And because this wasn't enough fun yet. What happens if you mix multiple presets on the same page? One of the URL's will win then, so afaik, you can't have a big and some smaller players on the same page with cloud-based presets? Might be worth documenting the limitations somewhere.

ron_s’s picture

Only suggestion on that would be to clarify in the description for the cloud based mode that providing a preset for the override is optional and it will use the global one by default. There is a default url, you're going to be using that for at least one of your presets I guess.

Yes, there should be additional information in the description. Should also add a #default_value for this form field to be the cloud-based URL:

+    $form['settings']['player_library_url'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Player Library URL'),
+      '#description' => t('Enter the URL to the player created on JWPlayer.com that contains the settings for this preset.'),
+      '#required' => TRUE,
+    );
The cloud URL validation fails on protocol-relative URLs (//content.jwplatform.com/libraries/...)

Correct... we're already removing http/https on all URLs to make them protocol-relative, but need to address the case where users try to "outsmart" what JW Player provides and remove the http themselves.

is the skin really supposed to be the only thing shown when using cloud? why just that and not the other things?

No it shouldn't be there. I think that occurred from making the skin edits previously. It should be URL only on cloud-based, all fields on Drupal-based.

As far as I see, the per-preset cloud URL isn't used yet?

No it's not, that's why we're trying to implement these patches! :-)

In 7.x, that's relatively easy to address, as you can add #attached js directly. But we do need to prevent that the global one isn't added.

Sure, but won't we address this in the next patch for the theme? Just trying to keep our work as focused as possible.

What happens if you mix multiple presets on the same page? One of the URL's will win then, so afaik, you can't have a big and some smaller players on the same page with cloud-based presets? Might be worth documenting the limitations somewhere.

Yes, I would assume one of them is going to win. We'll add some documentation notes. We need to explain is if this use case is needed, developers should override all presets to use Drupal-based settings.

ron_s’s picture

Attached is a new patch for review. The only way to see the full picture is by combining patch #11 on "Improve formatter summaries" with this issue. That is what we have done in this version.

If you want us to try to split them again between the two tasks we can, but there's just so much change in the formatter functions due to the new preset_source field in the preset settings. Compare to the patch #11 on https://www.drupal.org/node/2713687 and you'll see the difference.

Take a look and let me know your thoughts... I think we've addressed your previous comments in this thread. Thanks.

ron_s’s picture

Here are some images that show the different options in this patch. Let me know if you have questions.

ron_s’s picture

One additional comment... my understanding had been that JW Player 6 does not support preset overrides for cloud like 7 does. Because of this, we disabled changing the option for legacy versions (see the picture). If this is not the case, let me know.

deanflory’s picture

I was successful in applying jw_player-preset_sharing_mute_validate-2713701-2.patch, but this was the resulting error after running update.php without the other patch further below because it failed to apply:

Warning: include_once(/.../sites/all/modules/jw_player/theme/jw_player.theme.inc): failed to open stream: No such file or directory in _theme_process_registry() (line 565 of /.../includes/theme.inc).
Warning: include_once(): Failed opening '/.../sites/all/modules/jw_player/theme/jw_player.theme.inc' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in _theme_process_registry() (line 565 of /.../includes/theme.inc).

But, I just got this when trying to apply jw_player-refactor_theming-2713725-2.patch to jw_player-7.x-2.x-dev:

(Stripping trailing CRs from patch.)
patching file README.txt
(Stripping trailing CRs from patch.)
patching file jw_player.drupal.js
(Stripping trailing CRs from patch.)
patching file jw_player.api.php
(Stripping trailing CRs from patch.)
patching file jw_player.module
Hunk #1 FAILED at 64.
Hunk #2 FAILED at 89.
Hunk #3 FAILED at 116.
Hunk #4 FAILED at 238.
Hunk #5 FAILED at 283.
Hunk #6 FAILED at 298.
Hunk #7 FAILED at 482.
patch: **** malformed patch at line 761: function jw_player_preset_plugins($name = NULL) {

Just putting this here to make it easier to find via searches. Thanks for everyone's time and effort!

ron_s’s picture

@deanflory, just mentioned on the other thread that these are a bit of work in process. Waiting for some feedback from @Berdir.

Also regarding this message:

include_once(/.../sites/all/modules/jw_player/theme/jw_player.theme.inc): failed to open stream: No such file or directory in _theme_process_registry() (line 565 of /.../includes/theme.inc).

I'm quite sure this is because of the way you applied the patch. Check to see if the file is located in a /theme directory at the root. When applying patches and a new file is created, it will be placed at the root if the command is run outside of the module directory.

ron_s’s picture

One other comment... I wouldn't use patch #2 at this point. It's been hidden on this thread as an old version. #11 is the most current.

deanflory’s picture

Note that file is created here:
/.../sites/all/modules/jw_player/jw_player.theme.inc

but the error is looking for it here:
/.../sites/all/modules/jw_player/theme/jw_player.theme.inc

ron_s’s picture

I'm not having that issue, and it is correct at the top of the patch. The file is being created in "theme/jw_player.theme.inc":

 README.txt                                       |  37 +-
 js/jw_player.admin.js                            |  49 +++
 jw_player.admin.inc                              |  93 ++++-
 jw_player.module                                 | 242 ++++++++++---
 plugins/export_ui/jw_player_ctools_export_ui.inc | 410 +++++++++++++++++++----
 theme/jw_player.theme.inc                        |  45 +++
 6 files changed, 748 insertions(+), 128 deletions(-)
 create mode 100644 js/jw_player.admin.js
 create mode 100644 theme/jw_player.theme.inc

Very last line is create mode 100644 theme/jw_player.theme.inc. That's correct.

Berdir’s picture

Version: 7.x-2.x-dev » 8.x-1.x-dev
Status: Needs review » Patch (to be ported)

Nice work. Applies fine here as well.

  1. +++ b/plugins/export_ui/jw_player_ctools_export_ui.inc
    @@ -77,6 +77,26 @@ function jw_player_ctools_export_ui_form(&$form, &$form_state) {
    +  if (jw_player_use_legacy()) {
    +    $disabled = TRUE;
    +    $desc = t('When creating JW Player presets, select if the source should be defined on Drupal, or by using definitions set within your JWPlayer.com account. <strong>This option is only available for sites using JW Player 7 or above.</strong>');
    +  }
    +  else {
    +    $disabled = FALSE;
    +    $desc = t('When creating JW Player presets, select if the source should be defined on Drupal, or by using definitions set within your JWPlayer.com account.');
    +  }
    +  $form['settings']['preset_source'] = array(
    +    '#type' => 'radios',
    +    '#title' => t('Preset source'),
    +    '#disabled' => $disabled,
    +    '#options' => array(
    +      'drupal' => t('Use Drupal-defined presets'),
    +      'jwplayer' => t('Use presets defined on JWPlayer.com'),
    +    ),
    

    I've been wondering if it makes sense to allow overriding a local player with a preset.

    You might end up with a locally loaded jw player and another cloud player JS file.

    But I guess not a bigger problem than multiple cloud players. So, why not...

  2. +++ b/plugins/export_ui/jw_player_ctools_export_ui.inc
    @@ -284,25 +421,150 @@ function jw_player_ctools_export_ui_form(&$form, &$form_state) {
    +      '!admin' => l('JW Player general settings', 'admin/config/media/jw_player/settings'),
    +    )),
    +    '#default_value' => !empty($settings['player_library_url']) ? $settings['player_library_url'] : variable_get('jw_player_cloud_player_default', FALSE),
    +    '#states' => array(
    +      'required' => array(
    +        ':input[name="settings[preset_source]"]' => array('value' => 'jwplayer'),
    +      ),
    

    Hm, still not convinced that it is better to have this required with the default. It might not behave as expected when you change the default because the unchanged presets would still use the old default then. But if you change the default settings, you have to revisit all your presets anyway I guess.

Decided to commit this like this. We can open a new issue if we want to discus the preset cloud URL behavior. I could also imagine an explicit third option "Use default cloud settings" when using the cloud player.

PS: I managed to trick the validation by accidentally copying the license key into the cloud URL, then switch to local and save. Was confused when the cloud-preset default value was the license key. But I don't think that's worth to care about.

PPS: Would be awesome If you're interesting in porting those patches to 8.x after they are in. Could be a good opportunity to learn about D8 and I can help when you get stuck.

  • Berdir committed c5dd3f5 on 7.x-2.x authored by ron_s
    Issue #2713701 by ron_s: Add preset sources, sharing, mute and...
Berdir’s picture

Another thing that I forgot. We need to check if this needs an update function when we start to rely on thew new cloud/local variable and set it automatically, according to the existing settings.

ron_s’s picture

I've been wondering if it makes sense to allow overriding a local player with a preset.

Overriding a local player with a preset is one of the core reasons why we're building these patches. Otherwise, the only option is to give developers/site builders access to the JW Player dashboard to create players. Since the JW Player dashboard also includes analytics and metrics similar to what someone might see in Google Analytics, there are some businesses who might not feel comfortable providing access to this information to staff.

Hm, still not convinced that it is better to have this required with the default. It might not behave as expected when you change the default because the unchanged presets would still use the old default then.

Let's add a warning message: "Changing the existing URL will require review and updates to all existing presets that use JW Player as the source for preset information. Caution is recommended."

PS: I managed to trick the validation by accidentally copying the license key into the cloud URL, then switch to local and save. Was confused when the cloud-preset default value was the license key. But I don't think that's worth to care about.

Simple enough to add some code to clear the other value when switched. We already started doing this for the width setting in presets, since it makes no sense to be at 300px when fixed, then switch to responsive and see 300%.

Another thing that I forgot. We need to check if this needs an update function when we start to rely on thew new cloud/local variable and set it automatically, according to the existing settings.

Yes, probably need to do a check for that. If you don't mind, I'll post these as a new issue. Thanks.

Berdir’s picture

Yes, new issue is fine.

Sorry, the first part was wrong/unclear. What I meant is overriding a local player with a *cloud* preset. But as I said, likely not weirder/more problematic than multiple cloud players.

Berdir’s picture

Some improvements were also committed in #2713687: Improve formatter summaries.

Berdir’s picture

johnchque’s picture

Assigned: Unassigned » johnchque
johnchque’s picture

Status: Patch (to be ported) » Needs review
FileSize
33.2 KB

Not finished yet, but most of the port is done, need to fix the formatter summary for the image field.

Status: Needs review » Needs work

The last submitted patch, 27: add_preset_sources-2713701-27.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review
FileSize
39.11 KB
15.25 KB

Added working version, just realized that autoplay is not working, I will open a followup for it.

Status: Needs review » Needs work

The last submitted patch, 29: add_preset_sources-2713701-29.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review
FileSize
41.97 KB
3.95 KB

Finally got a working version and it tests fixed.

johnchque’s picture

Fixed some other things, now when no sharing site is selected all are selected by default. :D

johnchque’s picture

Followup for fixing autostart created: #2767145: Fix autostart

Berdir’s picture

+++ b/jw_player.module
@@ -193,3 +195,144 @@ function jw_player_get_key() {
+/**
+ * Helper function to display JW Player preset settings.
+ *
+ * @param string $preset_machine_name
+ *   Value set of the preset's machine name.
+ * @param string $format (optional)
+ *   Whether the preset settings are returned as an 'array' or formatted 'string'.
+ *
+ * @return array|string
+ *   The preset settings stored in an array or as an imploded string for rendering.
+ */
+function jw_player_preset_settings($preset_machine_name, $format = 'string') {
+  $summary = [];
+  $preset = Jw_player::load($preset_machine_name);

we have an entity in D8, so instead of passing in a preset machine name, we can make this a method on the entity.

johnchque’s picture

Function moved. Also made some other small changes. :)

Berdir’s picture

Status: Needs review » Needs work
+++ b/src/Form/JwplayerSettingsForm.php
@@ -57,6 +75,23 @@ class JwplayerSettingsForm extends ConfigFormBase {
+            [
+              'select[name="jw_player_version"]' => ['value' => '5']
+            ]

lets drop support for selecting 5.x completely in a separate issue.

As discussed:

* Drop the stored hosting setting, it just makes things complicated (update function, ..) and it's not used yet. we can still introduce it if we really need it but I doubt it
* Some more tests for the legacy vs. non-legacy conditions in the preset form and selecting some more options and making sure it shows up in the UI.

johnchque’s picture

Status: Needs work » Needs review
FileSize
46.77 KB
5.92 KB

As discussed changes made. Follow up opened: #2769853: Remove Jw Player 5 support.

  • Berdir committed 0b0edd7 on 8.x-1.x authored by yongt9412
    Issue #2713701 by yongt9412, ron_s: Add preset sources, sharing, mute...
Berdir’s picture

Status: Needs review » Fixed

Thanks, committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.