Hi,

I would like a little help and direction on how to add a new provider to video_embed_field.api.php

I am specifically trying to work out how to make the module work with a cloud storage service such as Dropbox or Google Drive

Does anyone have any experience with video_embed_field.api.php, they liked to share?

Thanks,
- Christian

Comments

S@ilor created an issue. See original summary.

Sam152’s picture

Just for clarification, the video_embed_field.api.php file demonstrates HOW to use the API. It's an example of how you might use the hooks to create a new provider.

S@ilor’s picture

Thanks for this, Sam152

It should have been evident to me, if I had studied it a bit longer. Still, if you have anything to share regarding adding a cloud storage service, I'd appreciate it.

SAW-James’s picture

@S@ilor

Below is a simple implementation of the google drive video_embed_field module extension.

The URL to be added to the field is the Embed URL Google Drive provides without the iframe tag.

video_embed_google_drive.module:

<?php

/**
 * @file
 * Adds a handler for Google Drive videos to Video Embed Field.
 *
 * @see video_embed_field.api.php for more documentation
 */

/**
 * Implements hook_video_embed_handler_info().
 */
function video_embed_google_drive_video_embed_handler_info() {
  $handlers = array();
  $handlers['google_drive'] = array(
    'title' => 'Google Drive Video',
    'function' => 'video_embed_google_drive_handle_video',
    'form' => 'video_embed_google_drive_form',
    'form_validate' => 'video_embed_field_handler_youtube_form_validate',
    'domains' => array(
      'drive.google.com',
    ),
    'defaults' => array(
      'width' => 640,
      'height' => 480,
      'class' => '',
    ),
  );

  return $handlers;
}

/**
 * Defines the form elements for the Google Drive videos configuration form.
 *
 * @param array $defaults
 *   The form default values.
 *
 * @return array
 *   The provider settings form array.
 */
function video_embed_google_drive_form($defaults) {
  $form = array();

  $form['width'] = array(
    '#type' => 'textfield',
    '#title' => t('Player Width'),
    '#description' => t('The width of the player.'),
    '#default_value' => $defaults['width'],
  );

  $form['height'] = array(
    '#type' => 'textfield',
    '#title' => t('Player Height'),
    '#description' => t('The height of the player.'),
    '#default_value' => $defaults['height'],
  );

  $form['class'] = array(
    '#type' => 'textfield',
    '#title' => t('Player CSS class'),
    '#description' => t('CSS class to add to the player'),
    '#default_value' => $defaults['class'],
  );

  return $form;
}

/**
 * Validates the form elements for the Google Drive video configuration form.
 *
 * @param array $element
 *   The form element to validate.
 * @param array $form_state
 *   The form to validate state.
 * @param array $form
 *   The form to validate structure.
 */
function video_embed_field_handler_google_drive_form_validate($element, &$form_state, $form) {
  video_embed_field_validate_dimensions($element);
}

/**
 * Handler for Google Drive videos.
 *
 * @param string $url
 *   The video URL.
 * @param array $settings
 *   The settings array.
 *
 * @return string|bool
 *   The video iframe, or FALSE in case the ID can't be retrieved from the URL.
 */
function video_embed_google_drive_handle_video($url, $settings) {
  if ($url) {
    // Our embed code.
    $embed='<iframe class="@class" src="@url" width="@width" height="@height" allowfullscreen></iframe> ';
    // Use format_string to replace our placeholders with the settings values.
    $embed = format_string($embed, array(
      '@url' => $url,
      '@width' => $settings['width'],
      '@height' => $settings['height'],
      '@class' => $settings['class'],
    ));

    $video = array(
      '#markup' => $embed,
    );
    return $video;
  }

  return FALSE;
}
S@ilor’s picture

@SAW-James

Apologies for my belated thanks. May come in handy in the next project.

S@ilor’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

StryKaizer’s picture

For drupal 8 users, see:
https://www.drupal.org/project/video_embed_google_drive

d7 not (yet) supported though