class context_reaction_addassets_base in Context Add Assets 7
Same name and namespace in other branches
- 6 plugins/context_reaction_addassets_base.inc \context_reaction_addassets_base
Expose themes as context reactions.
Hierarchy
- class \context_reaction
Expanded class hierarchy of context_reaction_addassets_base
3 string references to 'context_reaction_addassets_base'
- context_reaction_addcss.inc in plugins/
context_reaction_addcss.inc - The Context reaction plugin to add CSS files
- context_reaction_addjs.inc in plugins/
context_reaction_addjs.inc - The Context reaction plugin to add JS files
- context_reaction_addless.inc in plugins/
context_reaction_addless.inc - The Context reaction plugin to add Less files
File
- plugins/
context_reaction_addassets_base.inc, line 13 - The Context reaction plugin to add asset files
View source
class context_reaction_addassets_base extends context_reaction {
var $search_scope;
function __construct($plugin, $info) {
parent::__construct($plugin, $info);
// defaults are for js - but should never be picked up.
$this->title = t('JS from Themes');
$this->search_type = 'js';
}
/**
* Editor form.
*/
function editor_form($context) {
$form = $this
->options_form($context);
return $form;
}
/**
* Submit handler for editor form.
*/
function editor_form_submit($context, $values) {
return $values;
}
/**
* Prepare formatted form array showing grouped assets
* grouped by location and show as checkboxes
*/
function options_form($context) {
$values = $this
->fetch_from_context($context);
$options = $this
->_context_addassets_search();
$options = !$options ? array() : $options;
$options_array = array();
foreach ($options as $key => $value) {
$path = $key;
$key = explode(' -- ', $value);
$value = $key[1];
$key = trim($key[0]);
$options_array[$key][$path] = $value;
}
$form['#tree'] = TRUE;
foreach ($options_array as $key => $items) {
$form[$key] = array(
'#type' => 'item',
'#title' => $key,
);
foreach ($items as $path => $file_name) {
$form[$key][$path] = array(
'#title' => $file_name,
'#type' => 'checkbox',
'#return_value' => $path,
'#default_value' => isset($values[$key][$path]) ? $values[$key][$path] : '',
);
}
}
if (count($form) < 2) {
$link_options['query'] = drupal_get_destination();
$form['help'] = array(
'#type' => 'item',
'#title' => t('No Assets Found'),
'#description' => l('May you need to expand your search?', _context_addassets_admin_path(), $link_options),
);
}
return $form;
}
/**
* Filters deselected files from the listing.
*
* Reduces unnecessary conflicts when exporting to Features.
*/
function options_form_submit($values) {
foreach (array_keys($values) as $key) {
$values[$key] = array_filter($values[$key]);
}
return $values;
}
/**
* Implementation of the built-in context plugin class execution
*/
function execute() {
$contexts = context_active_contexts();
$classes = array();
//dpm($contexts);
foreach ($contexts as $key => $value) {
if (!empty($value->reactions[$this->plugin])) {
foreach ($value->reactions[$this->plugin] as $path_array) {
if (is_array($path_array)) {
foreach ($path_array as $path) {
if ($path) {
$ext = explode('.', $path);
$ext = drupal_strtolower($ext[count($ext) - 1]);
switch ($ext) {
case 'js':
drupal_add_js($path, array(
'group' => JS_DEFAULT,
));
break;
case 'css':
case 'less':
case 'sass':
case 'scss':
drupal_add_css($path, array(
'group' => CSS_THEME,
));
break;
}
}
}
}
}
}
}
}
/**
* Scan active themes for js files.
*
* @return Array
* An array indexed by file paths containing strings describing each path "Theme Key - File Name"
*/
function _context_addassets_search() {
$found_files = _context_addassets_scandir($this->search_type, $this->search_scope);
return $found_files;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
context_reaction:: |
property | |||
context_reaction:: |
property | |||
context_reaction:: |
property | |||
context_reaction:: |
function | Retrieve options from the context provided. | 1 | |
context_reaction:: |
function | Retrieve active contexts that have values for this reaction. | ||
context_reaction:: |
function | Settings form. Provide variable settings for your reaction. | 2 | |
context_reaction:: |
function | Clone our references when we're being cloned. | ||
context_reaction_addassets_base:: |
property | 3 | ||
context_reaction_addassets_base:: |
function | Editor form. | ||
context_reaction_addassets_base:: |
function | Submit handler for editor form. | ||
context_reaction_addassets_base:: |
function | Implementation of the built-in context plugin class execution | ||
context_reaction_addassets_base:: |
function |
Prepare formatted form array showing grouped assets
grouped by location and show as checkboxes Overrides context_reaction:: |
||
context_reaction_addassets_base:: |
function |
Filters deselected files from the listing. Overrides context_reaction:: |
||
context_reaction_addassets_base:: |
function | * Scan active themes for js files. * * | ||
context_reaction_addassets_base:: |
function |
Constructor. Do not override. Overrides context_reaction:: |
3 |