Skip to content

Instantly share code, notes, and snippets.

@scottrigby
Created April 15, 2015 21:11
Show Gist options
  • Save scottrigby/28ce7e69eb0870650c5b to your computer and use it in GitHub Desktop.
Save scottrigby/28ce7e69eb0870650c5b to your computer and use it in GitHub Desktop.
Video expired plugin sites/all/modules/custom/nbcuuse_video/plugins/access/video_expired.inc
<?php
/**
* @file
* Plugin to provide access control based on video expiration.
*/
$plugin = array(
'title' => t('Video expired'),
'description' => t('Is this video expired.'),
'callback' => 'nbcuuse_video_expired_ctools_access_check',
'default' => array('negate' => 0),
'summary' => 'nbcuuse_video_expired_ctools_access_summary',
'required context' => new ctools_context_required(t('File'), 'entity:file'),
);
/**
* Check for access.
*/
function nbcuuse_video_expired_ctools_access_check($conf, $context) {
if (empty($context) || empty($context->data)) {
return FALSE;
}
$file = isset($context->data) ? clone($context->data) : NULL;
// @todo Use field_get_items() to support future localization
$expired = FALSE;
if (isset($file->field_featured_video[LANGUAGE_NONE])) {
$exp_date = $file->field_featured_video[LANGUAGE_NONE][0]['field_mpx_expiration_date'][LANGUAGE_NONE][0]['value'];
if ($exp_date && $exp_date < REQUEST_TIME) {
$expired = TRUE;
}
}
return $expired;
}
/**
* Provide a summary description based upon the checked terms.
*/
function nbcuuse_video_expired_ctools_access_summary($conf, $context) {
return t('Video expired');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment