Skip to content
Snippets Groups Projects
Commit b9614d95 authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

[gh-428] Add new ctools files missed in 01f13b23

parent 01f13b23
No related branches found
No related tags found
No related merge requests found
Showing
with 1812 additions and 0 deletions
/**
* @file
* CTools Bulk Export javascript functions.
*/
(function ($) {
Drupal.behaviors.CToolsBulkExport = {
attach: function (context) {
$('#bulk-export-export-form .vertical-tabs-pane', context).drupalSetSummary(function (context) {
// Check if any individual checkbox is checked.
if ($('.bulk-selection input:checked', context).length > 0) {
return Drupal.t('Exportables selected');
}
return '';
});
// Special bind click on the select-all checkbox.
$('.select-all').bind('click', function(context) {
$(this, '.vertical-tabs-pane').drupalSetSummary(context);
});
}
};
})(jQuery);
<?php
/**
* @file
* CTools Drush commands.
*/
/**
* Implements hook_drush_command().
*/
function ctools_drush_command() {
$items = array();
$items['ctools-export'] = array(
'aliases' => array('ctex'),
'description' => 'Export multiple CTools exportable objects directly to code.',
'arguments' => array(
'module' => 'Name of your module.',
),
'options' => array(
'subdir' => 'The name of the sub directory to create the module in. Defaults to ctools_export which will be placed into sites/all/modules.',
'remove' => 'Remove existing files before writing, except the .module file.',
),
'drupal dependencies' => array('bulk_export'),
'examples' => array(
'drush ctex export_module' => 'Export CTools exportables to a module called "export_module".',
'drush ctex export_module --subdir=exports' => 'Same as above, but into the sites/all/modules/exports directory.',
'drush ctex export_module --subdir=exports --remove' => 'Same as above, but automatically removing all files, except for the .module file.',
),
);
$items['ctools-export-info'] = array(
'aliases' => array('ctei'),
'description' => 'Show available CTools exportable objects.',
'arguments' => array(),
'options' => array(
'format' => 'Display exportables info in a different format such as print_r, json, export. The default is to show in a tabular format.',
'tables-only' => 'Only show list of exportable types/table names and not available objects.',
'enabled' => 'Only show exportables that are currently enabled.',
'disabled' => 'Only show exportables that are currently disabled.',
'overridden' => 'Only show exportables that have been overridden in the database.',
'database' => 'Only show exportables defined in the database (and not in code).',
),
'examples' => array(
'drush ctools-export-info' => 'View export info on all exportables.',
'drush ctools-export-info views_view variable' => 'View export info for views_view and variable exportable types only.',
),
);
$items['ctools-export-view'] = array(
'aliases' => array('ctev'),
'callback' => 'drush_ctools_export_op_command',
'description' => 'View CTools exportable object code output.',
'arguments' => array(
'table name' => 'Base table of the exportable you want to view.',
'machine names' => 'Space separated list of exportables you want to view.',
),
'options' => array(
'indent' => 'The string to use for indentation when dispalying the exportable export code. Defaults to \'\'.',
'no-colour' => 'Remove any colour formatting from export string output. Ideal if you are sending the output of this command to a file.',
),
'examples' => array(
'drush ctools-export-view views_view' => 'View all views exportable objects.',
'drush ctools-export-view views_view archive' => 'View default views archive view.',
),
);
$items['ctools-export-revert'] = array(
'aliases' => array('cter'),
'callback' => 'drush_ctools_export_op_command',
'description' => 'Revert CTools exportables from changes overridden in the database.',
'arguments' => array(
'table name' => 'Base table of the exportable you want to revert.',
'machine names' => 'Space separated list of exportables you want to revert.',
),
'options' => array(),
'examples' => array(
'drush ctools-export-revert views_view' => 'Revert all overridden views exportable objects.',
'drush ctools-export-revert views_view archive' => 'Revert overridden default views archive view.',
),
);
$items['ctools-export-enable'] = array(
'aliases' => array('ctee'),
'callback' => 'drush_ctools_export_op_command',
'description' => 'Enable CTools exportables.',
'arguments' => array(
'table name' => 'Base table of the exportable you want to enable.',
'machine names' => 'Space separated list of exportables you want to enable.',
),
'options' => array(),
'examples' => array(
'drush ctools-export-enable views_view' => 'Enable all overridden views exportable objects.',
'drush ctools-export-enable views_view archive' => 'Enable overridden default views archive view.',
),
);
$items['ctools-export-disable'] = array(
'aliases' => array('cted'),
'callback' => 'drush_ctools_export_op_command',
'description' => 'Disable CTools exportables.',
'arguments' => array(
'table name' => 'Base table of the exportable you want to disable.',
'machine names' => 'Space separated list of exportables you want to disable.',
),
'options' => array(),
'examples' => array(
'drush ctools-export-disable views_view' => 'Disable all overridden views exportable objects.',
'drush ctools-export-disable views_view archive' => 'Disable overridden default views archive view.',
),
);
return $items;
}
/**
* Implementation of hook_drush_help().
*/
function ctools_drush_help($section) {
switch ($section) {
case 'meta:ctools:title':
return dt('CTools commands');
case 'meta:entity:summary':
return dt('CTools drush commands.');
}
}
/**
* Drush callback: export
*/
function drush_ctools_export($module = 'foo') {
$error = FALSE;
if (preg_match('@[^a-z_]+@', $module)) {
$error = dt('The name of the module must contain only lowercase letters and underscores') . '.';
drush_log($error, 'error');
return;
}
// Selection.
$options = array('all' => dt('Export everything'), 'select' => dt('Make selection'));
$selection = drush_choice($options, dt('Select to proceed'));
if (!$selection) {
return;
}
// Present the selection screens.
if ($selection == 'select') {
$selections = _drush_ctools_selection_screen();
}
else {
$selections = _drush_ctools_export_info();
}
// Subdirectory.
$dest_exists = FALSE;
$subdir = drush_get_option('subdir', 'ctools_export');
$dest = 'sites/all/modules/' . $subdir . '/' . $module;
// Overwriting files can be set with 'remove' argument.
$remove = drush_get_option('remove', FALSE);
// Check if folder exists.
if (file_exists($dest)) {
$dest_exists = TRUE;
if ($remove) {
if (drush_confirm(dt('All files except for the .info and .module files in !module will be removed. You can choose later if you want to overwrite these files as well. Are you sure you want to proceed ?', array('!module' => $module)))) {
$remove = TRUE;
drush_log(dt('Files will be removed'), 'success');
}
else {
drush_log(dt('Export aborted.'), 'success');
return;
}
}
}
// Remove files (except for the .module file) if the destination folder exists.
if ($remove && $dest_exists) {
_drush_ctools_file_delete($dest);
}
// Create new dir if needed.
if (!$dest_exists) {
if (!file_exists('sites/all/modules/' . $subdir)) {
drush_mkdir('sites/all/modules/' . $subdir);
}
}
// Create destination directory.
drush_mkdir($dest);
// Create options and call Bulk export function.
// We create an array, because maybe in the future we can pass in more
// options to the export function (pre-selected modules and/or exportables).
$options = array(
'name' => $module,
'selections' => $selections,
);
$files = bulk_export_export(TRUE, $options);
// Start writing.
if (is_array($files)) {
foreach ($files as $base_file => $data) {
$filename = $dest . '/' . $base_file;
// Extra check for .module file.
if ($base_file == ($module . '.module' || $module . '.info') && file_exists($filename)) {
if (!drush_confirm(dt('Do you want to overwrite !module_file', array('!module_file' => $base_file)))) {
drush_log(dt('Writing of !filename skipped. This is the code that was supposed to be written:', array('!filename' => $filename)), 'success');
drush_print('---------');
drush_print(shellColours::getColouredOutput("\n$data", 'light_green'));
drush_print('---------');
continue;
}
}
if (file_put_contents($filename, $data)) {
drush_log(dt('Succesfully written !filename', array('!filename' => $filename)), 'success');
}
else {
drush_log(dt('Error writing !filename', array('!filename' => $filename)), 'error');
}
}
drush_log("\n" . dt('No penguins were harmed in the generation of this code.') . "\n", 'success');
}
else {
drush_log(dt('No files were found to be written.'), 'error');
}
}
/**
* Helper function to select the exportables. By default, all exportables
* will be selected, so it will be easier to deselect them.
*/
function _drush_ctools_selection_screen() {
$selections = $build = array();
$files = system_rebuild_module_data();
$selection_number = 0;
$exportables = _drush_ctools_export_info();
$export_tables = array();
foreach (array_keys($exportables) as $table) {
natcasesort($exportables[$table]);
$export_tables[$table] = $files[$schema['module']]->info['name'] . ' (' . $table . ')';
}
foreach ($export_tables as $table => $table_title) {
if (!empty($exportables[$table])) {
$table_count = count($exportables[$table]);
$selection_number += $table_count;
foreach ($exportables[$table] as $key => $title) {
$build[$table]['title'] = $table_title;
$build[$table]['items'][$key] = $title;
$build[$table]['count'] = $table_count;
$selections[$table][$key] = $key;
}
}
}
drush_print(dt('Number of exportables selected: !number', array('!number' => $selection_number)));
drush_print(dt('By default all exportables are selected. Select a table to deselect exportables. Select "cancel" to start writing the files.'));
// Let's go into a loop.
$return = FALSE;
while (!$return) {
// Present the tables choice.
$table_rows = array();
foreach ($build as $table => $info) {
$table_rows[$table] = $info['title'] . ' (' . dt($info['count']) . ')';
}
$table_choice = drush_choice($table_rows, dt('Select a table. Select cancel to start writing files.'));
// Bail out.
if (!$table_choice) {
drush_log(dt('Selection mode done, starting to write the files.'), 'notice');
$return = TRUE;
return $selections;
}
// Present the exportables choice, using the drush_choice_multiple.
$max = count($build[$table_choice]['items']);
$exportable_rows = array();
foreach ($build[$table_choice]['items'] as $key => $title) {
$exportable_rows[$key] = $title;
}
drush_print(dt('Exportables from !table', array('!table' => $build[$table_choice]['title'])));
$multi_select = drush_choice_multiple($exportable_rows, $selections[$table_choice], dt('Select exportables.'), '!value', '!value (selected)', 0, $max);
// Update selections.
if (is_array($multi_select)) {
$build[$table_choice]['count'] = count($multi_select);
$selections[$table_choice] = array();
foreach ($multi_select as $key) {
$selections[$table_choice][$key] = $key;
}
}
}
}
/**
* Delete files in a directory, keeping the .module and .info files.
*
* @param $path
* Path to directory in which to remove files.
*/
function _drush_ctools_file_delete($path) {
if (is_dir($path)) {
$files = new DirectoryIterator($path);
foreach ($files as $fileInfo) {
if (!$fileInfo->isDot() && !in_array($fileInfo->getExtension(), array('module', 'info'))) {
unlink($fileInfo->getPathname());
}
}
}
}
/**
* Drush callback: Export info.
*
* @params $table_names
* Each argument will be taken as a CTools exportable table name.
*/
function drush_ctools_export_info() {
// Collect array of table names from args.
$table_names = func_get_args();
// Get format option to allow for alternative output.
$format = drush_get_option('format', FALSE);
$tables_only = drush_get_option('tables-only', FALSE);
$show_overridden = drush_get_option('overridden', FALSE);
$show_enabled = drush_get_option('enabled', FALSE);
$show_disabled = drush_get_option('disabled', FALSE);
$show_database_only = drush_get_option('database', FALSE);
// Only load exportable objects for each type fully if we need to.
$load = ($show_overridden || $show_enabled || $show_disabled || $show_database_only) ? TRUE : FALSE;
// Get info on these tables, or all if none specified.
$exportables = _drush_ctools_export_info($table_names, $load);
if (empty($exportables)) {
drush_log(dt('There are no exportables available.'), 'warning');
return;
}
// The order of these conditionals set a hierarchy for options if there are mulitple.
// Show enabled exportables only.
if ($show_enabled) {
foreach ($exportables as $table => $objects) {
foreach ($objects as $key => $object) {
if (_ctools_drush_object_is_disabled($object)) {
unset($exportables[$table][$key]);
}
}
}
}
// Show disabled exportables only.
elseif ($show_disabled) {
foreach ($exportables as $table => $objects) {
foreach ($objects as $key => $object) {
if (!_ctools_drush_object_is_disabled($object)) {
unset($exportables[$table][$key]);
}
}
}
}
// Show overridden exportables only.
elseif ($show_overridden) {
foreach ($exportables as $table => $objects) {
foreach ($objects as $key => $object) {
if (!_ctools_drush_object_is_overridden($object)) {
unset($exportables[$table][$key]);
}
}
}
}
// Show database only exportables.
elseif ($show_database_only) {
foreach ($exportables as $table => $objects) {
foreach ($objects as $key => $object) {
if (!_ctools_drush_object_is_db_only($object)) {
unset($exportables[$table][$key]);
}
}
}
}
$exportables = array_filter($exportables);
// Only use array keys if --tables-only option is set.
if ($tables_only) {
$exportables = array_keys($exportables);
}
// Use format from --format option if it's present, and send to drush_format.
if ($format) {
drush_print(drush_format($exportables, NULL, $format));
}
// Build a tabular output as default.
else {
$header = $tables_only ? array() : array(dt('Base table'), dt('Exportables'));
$rows = array();
foreach ($exportables as $table => $info) {
if (is_array($info)) {
$row = array(
$table,
// Machine name is better for this?
shellColours::getColouredOutput(implode("\n", array_keys($info)), 'light_green') . "\n",
);
$rows[] = $row;
}
else {
$rows[] = array($info);
}
}
if (!empty($rows)) {
array_unshift($rows, $header);
drush_print_table($rows, TRUE);
}
else {
drush_log(dt('There are no exportables matching this criteria.'), 'notice');
}
}
}
/**
* Drush callback: Acts as the hub for all op commands to keep all arg handling etc in one place.
*/
function drush_ctools_export_op_command() {
// Get all info for the current drush command.
$command = drush_get_command();
$op = '';
switch ($command['command']) {
case 'ctools-export-view':
$op = 'view';
break;
case 'ctools-export-revert':
// Revert is same as deleting. As any objects in the db are deleted.
$op = 'delete';
break;
case 'ctools-export-enable':
$op = 'enable';
break;
case 'ctools-export-disable':
$op = 'disable';
break;
}
if (!$op) {
return;
}
$args = func_get_args();
// Table name should always be first arg...
$table_name = array_shift($args);
// Any additional args are assumed to be exportable names.
$object_names = $args;
// Return any exportables based on table name, object names, options.
$exportables = _drush_ctools_export_op_command_logic($op, $table_name, $object_names);
if ($exportables) {
drush_ctools_export_op($op, $table_name, $exportables);
}
}
/**
* Iterate through exportable object names, load them, and pass each
* object to the correct op function.
*
* @param $op
* @param $table_name
* @param $exportables
*
*/
function drush_ctools_export_op($op = '', $table_name = '', $exportables = NULL) {
$objects = ctools_export_crud_load_multiple($table_name, array_keys($exportables));
$function = '_drush_ctools_export_' . $op;
if (function_exists($function)) {
foreach ($objects as $object) {
$function($table_name, $object);
}
}
else {
drush_log(dt('CTools CRUD function !function doesn\'t exist.',
array('!function' => $function)), 'error');
}
}
/**
* Helper function to abstract logic for selecting exportable types/objects
* from individual commands as they will all share this same error
* handling/arguments for returning list of exportables.
*
* @param $table_name
* @param $object_names
*
* @return
* Array of exportable objects (filtered if necessary, by name etc..) or FALSE if not.
*/
function _drush_ctools_export_op_command_logic($op = '', $table_name = NULL, $object_names = array()) {
if (!$table_name) {
drush_log(dt('Exportable table name empty.'), 'error');
return FALSE;
}
// Get export info based on table name.
$info = _drush_ctools_export_info(array($table_name));
if (!isset($info[$table_name])) {
drush_log(dt('Exportable table name not found.'), 'error');
return FALSE;
}
$exportables = $info[$table_name];
if (empty($object_names)) {
$all = drush_confirm(dt('No object names entered. Would you like to try and !op all exportables of type !type',
array('!op' => _drush_ctools_export_op_aliases($op), '!type' => $table_name)));
if (!$all) {
drush_log(dt('Command cancelled'), 'success');
return FALSE;
}
}
else {
// Iterate through object names and check they exist in exportables array.
// Log error and unset them if they don't.
foreach ($object_names as $object_name) {
if (!isset($exportables[$object_name])) {
drush_log(dt('Invalid exportable: !exportable', array('!exportable' => $object_name)), 'error');
unset($object_names[$object_name]);
}
}
// Iterate through exportables to get just a list of selected ones.
foreach (array_keys($exportables) as $exportable) {
if (!in_array($exportable, $object_names)) {
unset($exportables[$exportable]);
}
}
}
return $exportables;
}
/**
* Return array of CTools exportable info based on available tables returned from
* ctools_export_get_schemas().
*
* @param $table_names
* Array of table names to return.
* @param $load
* (bool) should ctools exportable objects be loaded for each type.
* The default behaviour will load just a list of exportable names.
*
* @return
* Nested arrays of available exportables, keyed by table name.
*/
function _drush_ctools_export_info($table_names = array(), $load = FALSE) {
ctools_include('export');
// Get available schemas that declare exports.
$schemas = ctools_export_get_schemas(TRUE);
$exportables = array();
if (!empty($schemas)) {
// Remove types we don't want, if any.
if (!empty($table_names)) {
foreach (array_keys($schemas) as $table_name) {
if (!in_array($table_name, $table_names)) {
unset($schemas[$table_name]);
}
}
}
// Load array of available exportables for each schema.
foreach ($schemas as $table_name => $schema) {
// Load all objects.
if ($load) {
$exportables[$table_name] = ctools_export_crud_load_all($table_name);
}
// Get a list of exportable names.
else {
if (!empty($schema['export']['list callback']) && function_exists($schema['export']['list callback'])) {
$exportables[$table_name] = $schema['export']['list callback']();
}
else {
$exportables[$table_name] = ctools_export_default_list($table_name, $schema);
}
}
}
}
return $exportables;
}
/*
* View a single object.
*
* @param $table_name
* @param $object
*/
function _drush_ctools_export_view($table_name, $object) {
$indent = drush_get_option('indent', '');
$no_colour = drush_get_option('no-colour', FALSE);
$export = ctools_export_crud_export($table_name, $object, $indent);
if ($no_colour) {
drush_print($export);
}
else {
drush_print(shellColours::getColouredOutput("\n$export", 'light_green'));
}
}
/*
* Revert a single object.
*
* @param $table_name
* @param $object
*/
function _drush_ctools_export_delete($table_name, $object) {
if (_ctools_drush_object_is_overridden($object)) {
// Remove from db.
ctools_export_crud_delete($table_name, $object);
drush_log("Reverted object: $object->name", 'success');
}
else {
drush_log("Nothing to revert for: $object->name", 'notice');
}
}
/*
* Enable a single object.
*
* @param $table_name
* @param $object
*/
function _drush_ctools_export_enable($table_name, $object) {
if (_ctools_drush_object_is_disabled($object)) {
// Enable object.
ctools_export_crud_enable($table_name, $object);
drush_log("Enabled object: $object->name", 'success');
}
else {
drush_log("$object->name is already Enabled", 'notice');
}
}
/*
* Disable a single object.
*
* @param $table_name
* @param $object
*/
function _drush_ctools_export_disable($table_name, $object) {
if (!_ctools_drush_object_is_disabled($object)) {
// Disable object.
ctools_export_crud_disable($table_name, $object);
drush_log("Disabled object: $object->name", 'success');
}
else {
drush_log("$object->name is already disabled", 'notice');
}
}
/**
* Helper to determine if an object is disabled.
*
* @param $object
* Loaded CTools exportable object.
*
* @return TRUE or FALSE
*/
function _ctools_drush_object_is_disabled($object) {
return (isset($object->disabled) && ($object->disabled == TRUE)) ? TRUE : FALSE;
}
/**
* Helper to determine if an object is overridden.
*
* @param $object
* Loaded CTools exportable object.
*
* @return TRUE or FALSE
*/
function _ctools_drush_object_is_overridden($object) {
return ($object->export_type == 3) ? TRUE : FALSE;
}
/**
* Helper to determine if an object is only in the db.
*
* @param $object
* Loaded CTools exportable object.
*
* @return TRUE or FALSE
*/
function _ctools_drush_object_is_db_only($object) {
return ($object->export_type == 1) ? TRUE : FALSE;
}
/**
* Return any aliases for an op, that will be used to show as output.
* For now, this is mainly necessary for delete => revert alias.
*
* @param $op
* The op name. Such as 'enable', 'disable', or 'delete'.
*
* @return
* The matched alias value or the original $op passed in if not found.
*/
function _drush_ctools_export_op_aliases($op) {
$aliases = array(
'delete' => 'revert',
);
if (isset($aliases[$op])) {
return $aliases[$op];
}
return $op;
}
/**
* Class to deal with wrapping output strings with
* colour formatting for the shell.
*/
class shellColours {
private static $foreground_colours = array(
'black' => '0;30',
'dark_gray' => '1;30',
'blue' => '0;34',
'light_blue' => '1;34',
'green' => '0;32',
'light_green' => '1;32',
'cyan' => '0;36',
'light_cyan' => '1;36',
'red' => '0;31',
'light_red' => '1;31',
'purple' => '0;35',
'light_purple' => '1;35',
'brown' => '0;33',
'yellow' => '1;33',
'light_gray' => '0;37',
'white' => '1;37',
);
private static $background_colours = array(
'black' => '40',
'red' => '41',
'green' => '42',
'yellow' => '43',
'blue' => '44',
'magenta' => '45',
'cyan' => '46',
'light_gray' => '47',
);
private function __construct() {}
// Returns coloured string
public static function getColouredOutput($string, $foreground_colour = NULL, $background_colour = NULL) {
$coloured_string = "";
// Check if given foreground colour found
if ($foreground_colour) {
$coloured_string .= "\033[" . self::$foreground_colours[$foreground_colour] . "m";
}
// Check if given background colour found
if ($background_colour) {
$coloured_string .= "\033[" . self::$background_colours[$background_colour] . "m";
}
// Add string and end colouring
$coloured_string .= $string . "\033[0m";
return $coloured_string;
}
// Returns all foreground colour names
public static function getForegroundColours() {
return array_keys(self::$foreground_colours);
}
// Returns all background colour names
public static function getBackgroundColours() {
return array_keys(self::$background_colours);
}
} // shellColours
<p>To be written.</p>
<p>To be written.</p>
<p>To be written.</p>
<p>To be written.</p>
<p>To be written.</p>
<p>To be written.</p>
<?php
/**
* Returns array of language names.
*
* This is a one to one copy of locale_language_list because we can't rely on enabled locale module.
*
* @param $field
* 'name' => names in current language, localized
* 'native' => native names
* @param $all
* Boolean to return all languages or only enabled ones
*
* @see locale_language_list
*/
function ctools_language_list($field = 'name', $all = FALSE) {
if ($all) {
$languages = language_list();
}
else {
$languages = language_list('enabled');
$languages = $languages[1];
}
$list = array();
foreach ($languages as $language) {
$list[$language->language] = ($field == 'name') ? t($language->name) : $language->$field;
}
return $list;
}
/**
* Returns an array of language names similar to ctools_language_list() except
* that additional choices have been added for ease of use.
*/
function ctools_language_list_all() {
$languages = array(
'***CURRENT_LANGUAGE***' => t("Current user's language"),
'***DEFAULT_LANGUAGE***' => t("Default site language"),
LANGUAGE_NONE => t('Language neutral'),
);
$languages = array_merge($languages, ctools_language_list());
return $languages;
}
\ No newline at end of file
<?php
/**
* @file
* Overrides the user profile display at user/%user.
*
* Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
* more information.
*/
function page_manager_user_edit_page_manager_tasks() {
return array(
// This is a 'page' task and will fall under the page admin UI
'task type' => 'page',
'title' => t('User Edit Template'),
'admin title' => t('User edit template'),
'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying user edit form at <em>user/%user/edit</em>.'),
'admin path' => 'user/%user/edit',
// Callback to add items to the page managertask administration form:
'task admin' => 'page_manager_user_edit_task_admin',
'hook menu' => 'page_manager_user_edit_menu',
'hook menu alter' => 'page_manager_user_edit_menu_alter',
// This is task uses 'context' handlers and must implement these to give the
// handler data it needs.
'handler type' => 'context', // handler type -- misnamed
'get arguments' => 'page_manager_user_edit_get_arguments',
'get context placeholders' => 'page_manager_user_edit_get_contexts',
// Allow this to be enabled or disabled:
'disabled' => variable_get('page_manager_user_edit_disabled', TRUE),
'enable callback' => 'page_manager_user_edit_enable',
'access callback' => 'page_manager_user_edit_access_check',
);
}
/**
* Callback defined by page_manager_user_view_page_manager_tasks().
*
* Alter the user view input so that user view comes to us rather than the
* normal user view process.
*/
function page_manager_user_edit_menu_alter(&$items, $task) {
if (variable_get('page_manager_user_edit_disabled', TRUE)) {
return;
}
// Override the user view handler for our purpose.
if ($items['user/%user/edit']['page callback'] == 'drupal_get_form' || variable_get('page_manager_override_anyway', FALSE)) {
$items['user/%user/edit']['page callback'] = 'page_manager_user_edit_page';
$items['user/%user/edit']['page arguments'] = array(1);
$items['user/%user/edit']['file path'] = $task['path'];
$items['user/%user/edit']['file'] = $task['file'];
}
else {
// automatically disable this task if it cannot be enabled.
variable_set('page_manager_user_edit_disabled', TRUE);
if (!empty($GLOBALS['page_manager_enabling_user_edit'])) {
drupal_set_message(t('Page manager module is unable to enable user/%user/edit because some other module already has overridden with %callback.', array('%callback' => $items['user/%user']['page callback'])), 'error');
}
}
}
/**
* Entry point for our overridden user view.
*
* This function asks its assigned handlers who, if anyone, would like
* to run with it. If no one does, it passes through to Drupal core's
* user edit, which is drupal_get_form('user_profile_form',$account).
*/
function page_manager_user_edit_page($account) {
// Load my task plugin:
$task = page_manager_get_task('user_edit');
// Load the account into a context.
ctools_include('context');
ctools_include('context-task-handler');
$contexts = ctools_context_handler_get_task_contexts($task, '', array($account));
// Build content. @todo -- this may not be right.
user_build_content($account);
$output = ctools_context_handler_render($task, '', $contexts, array($account->uid));
if (is_array($output)) {
$output = drupal_render($output);
}
if ($output != FALSE) {
return $output;
}
$function = 'drupal_get_form';
foreach (module_implements('page_manager_override') as $module) {
$call = $module . '_page_manager_override';
if (($rc = $call('user_edit')) && function_exists($rc)) {
$function = $rc;
break;
}
}
// Otherwise, fall back.
if ($function == 'drupal_get_form') {
//In order to ajax fields to work we need to run form_load_include.
//Hence we eschew drupal_get_form and manually build the info and
//call drupal_build_form.
$form_state = array();
$form_id = 'user_profile_form';
$args = array($account);
$form_state['build_info']['args'] = $args;
form_load_include($form_state, 'inc', 'user', 'user.pages');
$output = drupal_build_form($form_id, $form_state);
return $output;
}
//fire off "view" op so that triggers still work
// @todo -- this doesn't work anymore, and the alternatives seem bad.
// will have to figure out how to fix this.
// user_module_invoke('view', $array = array(), $account);
return $function($account);
}
/**
* Callback to get arguments provided by this task handler.
*
* Since this is the node view and there is no UI on the arguments, we
* create dummy arguments that contain the needed data.
*/
function page_manager_user_edit_get_arguments($task, $subtask_id) {
return array(
array(
'keyword' => 'user',
'identifier' => t('User being edited'),
'id' => 1,
'name' => 'user_edit',
'settings' => array(),
),
);
}
/**
* Callback to get context placeholders provided by this handler.
*/
function page_manager_user_edit_get_contexts($task, $subtask_id) {
return ctools_context_get_placeholders_from_argument(page_manager_user_edit_get_arguments($task, $subtask_id));
}
/**
* Callback to enable/disable the page from the UI.
*/
function page_manager_user_edit_enable($cache, $status) {
variable_set('page_manager_user_edit_disabled', $status);
// Set a global flag so that the menu routine knows it needs
// to set a message if enabling cannot be done.
if (!$status) {
$GLOBALS['page_manager_enabling_user_edit'] = TRUE;
}
}
/**
* Callback to determine if a page is accessible.
*
* @param $task
* The task plugin.
* @param $subtask_id
* The subtask id
* @param $contexts
* The contexts loaded for the task.
* @return
* TRUE if the current user can access the page.
*/
function page_manager_user_edit_access_check($task, $subtask_id, $contexts) {
$context = reset($contexts);
return user_edit_access($context->data);
}
<?php
/**
* @file
* Plugin to provide access control based upon entity bundle.
*/
$plugin = array(
'title' => t("(Custom) Entity: Field Value"),
'description' => t('Control access by entity field value.'),
'callback' => 'ctools_entity_field_value_ctools_access_check',
'default' => array('type' => array()),
'settings form' => 'ctools_entity_field_value_ctools_access_settings',
'settings form submit' => 'ctools_entity_field_value_ctools_access_settings_submit',
'summary' => 'ctools_entity_field_value_ctools_access_summary',
'get child' => 'ctools_entity_field_value_ctools_access_get_child',
'get children' => 'ctools_entity_field_value_ctools_access_get_children',
);
function ctools_entity_field_value_ctools_access_get_child($plugin, $parent, $child) {
$plugins = &drupal_static(__FUNCTION__, array());
if (empty($plugins[$parent . ':' . $child])) {
list($entity_type, $bundle_type, $field_name) = explode(':', $child);
$plugins[$parent . ':' . $child] = _ctools_entity_field_value_ctools_access_get_child($plugin, $parent, $entity_type, $bundle_type, $field_name);
}
return $plugins[$parent . ':' . $child];
}
function ctools_entity_field_value_ctools_access_get_children($plugin, $parent) {
$plugins = &drupal_static(__FUNCTION__, array());
if (!empty($plugins)) {
return $plugins;
}
$entities = entity_get_info();
foreach ($entities as $entity_type => $entity) {
foreach ($entity['bundles'] as $bundle_type => $bundle) {
foreach (field_info_instances($entity_type, $bundle_type) as $field_name => $field) {
if (!isset($plugins[$parent . ':' . $entity_type . ':' . $bundle_type . ':' . $field_name])) {
$plugin = _ctools_entity_field_value_ctools_access_get_child($plugin, $parent, $entity_type, $bundle_type, $field_name, $entity, $bundle, $field);
$plugins[$parent . ':' . $entity_type . ':' . $bundle_type . ':' . $field_name] = $plugin;
}
}
}
}
return $plugins;
}
function _ctools_entity_field_value_ctools_access_get_child($plugin, $parent, $entity_type, $bundle_type, $field_name, $entity = NULL, $bundle = NULL, $field = NULL) {
// check that the entity, bundle and field arrays have a value.
// If not, load theme using machine names.
if (empty($entity)) {
$entity = entity_get_info($entity_type);
}
if (empty($bundle)) {
$bundle = $entity['bundles'][$bundle_type];
}
if (empty($field)) {
$field_instances = field_info_instances($entity_type, $bundle_type);
$field = $field_instances[$field_name];
}
$plugin['title'] = t('@entity @type: @field Field', array('@entity' => $entity['label'], '@type' => $bundle_type, '@field' => $field['label']));
$plugin['keyword'] = $entity_type;
$plugin['description'] = t('Control access by @entity entity bundle.', array('@entity' => $entity_type));
$plugin['name'] = $parent . ':' . $entity_type . ':' . $bundle_type . ':' . $field_name;
$plugin['required context'] = new ctools_context_required(t(ucfirst($entity_type)), $entity_type, array(
'type' => $bundle_type,
));
return $plugin;
}
/**
* Settings form for the 'by entity_bundle' access plugin
*/
function ctools_entity_field_value_ctools_access_settings($form, &$form_state, $conf) {
$plugin = $form_state['plugin'];
list($parent, $entity_type, $bundle_type, $field_name) = explode(':', $plugin['name']);
$entity_info = entity_get_info($entity_type);
$instances = field_info_instances($entity_type, $bundle_type);
$instance = $instances[$field_name];
$field = field_info_field_by_id($instance['field_id']);
foreach ($field['columns'] as $column => $attributes) {
$columns[] = _field_sql_storage_columnname($field_name, $column);
}
ctools_include('fields');
$entity = (object)array(
$entity_info['entity keys']['bundle'] => $bundle_type,
);
$langcode = field_valid_language(NULL);
$form['settings'] += (array) ctools_field_invoke_field($instance, 'form', $entity_type, $entity, $form, $form_state, array('default' => TRUE, 'language' => $langcode));
// weight is really not important once this is populated and will only interfere with the form layout.
foreach (element_children($form['settings']) as $element) {
unset($form['settings'][$element]['#weight']);
}
// Need more logic here to handle compound fields.
foreach ($columns as $column) {
if (isset($conf[$column]) && is_array($conf[$column])) {
foreach ($conf[$column] as $delta => $conf_value) {
if (is_numeric($delta) && is_array($conf_value)) {
$form['settings'][$field_name][LANGUAGE_NONE][$delta]['value']['#default_value'] = $conf_value['value'];
}
else {
$form['settings'][$field_name][LANGUAGE_NONE]['#default_value'] = $conf[$column];
}
}
}
}
return $form;
}
/**
* Compress the entity bundles allowed to the minimum.
*/
function ctools_entity_field_value_ctools_access_settings_submit($form, &$form_state) {
$plugin = $form_state['plugin'];
list($parent, $entity_type, $bundle_type, $field_name) = explode(':', $plugin['name']);
$langcode = field_valid_language(NULL);
$langcode = isset($form_state['input']['settings'][$field_name][$langcode]) ? $langcode : LANGUAGE_NONE;
$instances = field_info_instances($entity_type, $bundle_type);
$instance = $instances[$field_name];
$field = field_info_field_by_id($instance['field_id']);
foreach ($field['columns'] as $column => $attributes) {
$columns[] = _field_sql_storage_columnname($field_name, $column);
}
foreach ($columns as $column) {
$form_state['values']['settings'][$column] = $form_state['input']['settings'][$field_name][$langcode];
}
}
/**
* Check for access.
*/
function ctools_entity_field_value_ctools_access_check($conf, $context, $plugin) {
list($parent, $entity_type, $bundle_type, $field_name) = explode(':', $plugin['name']);
if ($field_items = field_get_items($entity_type, $context->data, $field_name)) {
$langcode = field_language($entity_type, $context->data, $field_name);
foreach ($conf as $potential_field => $values) {
if ($field_name === $potential_field) {
$conf_value_array = _ctools_entity_field_value_ctools_access_get_conf_field_values($values, $langcode);
if (empty($conf_value_array)) {
return FALSE;
}
// Check field value.
foreach ($field_items as $field_value) {
if (in_array($field_value['value'], $conf_value_array)) {
return TRUE;
}
}
}
}
}
return FALSE;
}
function _ctools_entity_field_value_ctools_access_get_conf_field_values($values, $langcode = LANGUAGE_NONE) {
if (!is_array($values) || !isset($values[$langcode])) {
return;
}
$conf_values = array();
foreach ($values[$langcode] as $value) {
$conf_values[] = $value['value'];
}
return $conf_values;
}
/**
* Provide a summary description based upon the checked entity_bundle.
*/
function ctools_entity_field_value_ctools_access_summary($conf, $context, $plugin) {
list($parent, $entity_type, $bundle_type, $field_name) = explode(':', $plugin['name']);
$instances = field_info_instances($entity_type, $bundle_type);
$instance = $instances[$field_name];
$field = field_info_field_by_id($instance['field_id']);
$entity_info = entity_get_info($entity_type);
$entity = (object)array(
$entity_info['entity keys']['bundle'] => $bundle_type,
);
$string = '';
$keys = array();
$values = array();
foreach ($field['columns'] as $column => $attributes) {
$conf_key = _field_sql_storage_columnname($field_name, $column);
if (count($field['columns']) > 1) {
// Add some sort of handling for compound fields
}
else {
if (isset($conf[$conf_key])) {
$entity->{$field_name}[LANGUAGE_NONE][] = array($column => $conf[$conf_key]);
}
}
$string .= " @{$column} equals @{$column}_value";
$keys['@' . $column] = $column;
$values["@{$column}_value"] = $conf[$conf_key];
}
$view_mode = 'full';
$null = NULL;
$options = array('language' => LANGUAGE_NONE);
ctools_include('fields');
$display = field_get_display($instance, $view_mode, $entity);
$display['type'] = 'list_default';
$function = $display['module'] . '_field_formatter_view';
$items = isset($entity->{$field_name}[LANGUAGE_NONE]) ? $entity->{$field_name}[LANGUAGE_NONE] : array();
if (function_exists($function)) {
$elements = $function($entity_type, $entity, $field, $instance, LANGUAGE_NONE, $items, $display);
}
$value_keys = array_keys($values);
foreach ($value_keys as $key => $value) {
$values[$value] = $elements[$key]['#markup'];
}
$values = array_merge($keys, $values);
return t($string, $values);
}
<?php
/**
* @file
* Plugin to provide access control based on drupal_is_front_page.
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => t('Front page'),
'description' => t('Is this the front page.'),
'callback' => 'ctools_front_ctools_access_check',
'default' => array('negate' => 0),
'settings form' => 'ctools_front_ctools_access_settings',
'summary' => 'ctools_front_ctools_access_summary',
);
/**
* Settings form for the 'by parent term' access plugin
*/
function ctools_front_ctools_access_settings($form, &$form_state, $conf) {
// No additional configuration necessary.
return $form;
}
/**
* Check for access.
*/
function ctools_front_ctools_access_check($conf, $context) {
if (drupal_is_front_page()) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* Provide a summary description based upon the checked terms.
*/
function ctools_front_ctools_access_summary($conf, $context) {
return t('The front page');
}
<?php
/**
* @file
* Plugin to provide access control based upon node (un)published status.
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => t("Node: (un)published"),
'description' => t('Control access by the nodes published status.'),
'callback' => 'ctools_node_status_ctools_access_check',
'summary' => 'ctools_node_status_ctools_access_summary',
'required context' => new ctools_context_required(t('Node'), 'node'),
);
/**
* Check for access.
*/
function ctools_node_status_ctools_access_check($conf, $context) {
return (!empty($context->data) && $context->data->status);
}
/**
* Provide a summary description based upon the checked node_statuss.
*/
function ctools_node_status_ctools_access_summary($conf, $context) {
return t('Returns true if the nodes status is "published".');
}
<?php
/**
* @file
*
* Plugin to provide an argument handler for a Taxonomy term
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => t("User edit form: User ID"),
// keyword to use for %substitution
'keyword' => 'user',
'description' => t('Creates a user edit form context from a user ID argument.'),
'context' => 'ctools_user_edit_context',
'placeholder form' => array(
'#type' => 'textfield',
'#description' => t('Enter the user ID for this argument.'),
),
);
/**
* Discover if this argument gives us the term we crave.
*/
function ctools_user_edit_context($arg = NULL, $conf = NULL, $empty = FALSE) {
// If unset it wants a generic, unfilled context.
if ($empty) {
return ctools_context_create_empty('user_edit_form');
}
if(is_object($arg)){
return ctools_context_create('user_edit_form', $arg);
}
if (!is_numeric($arg)) {
return FALSE;
}
$account= user_load($arg);
if (!$account) {
return NULL;
}
// This will perform a node_access check, so we don't have to.
return ctools_context_create('user_edit_form', $account);
return NULL;
}
\ No newline at end of file
<?php
$plugin = array(
'title' => t('Entity extra field'),
'defaults' => array('view_mode' => NULL),
'content type' => 'ctools_entity_field_extra_content_type_content_type',
);
/**
* Just one subtype.
*
* Ordinarily this function is meant to get just one subtype. However, we are
* using it to deal with the fact that we have changed the subtype names. This
* lets us translate the name properly.
*/
function ctools_entity_field_extra_content_type_content_type($subtype) {
$types = ctools_entity_field_extra_content_type_content_types();
if (isset($types[$subtype])) {
return $types[$subtype];
}
}
/**
* Return all extra field content types available.
*/
function ctools_entity_field_extra_content_type_content_types() {
// This will hold all the individual field content types.
$types = array();
$context_types = array();
$entities = entity_get_info();
foreach ($entities as $entity_type => $entity) {
foreach ($entity['bundles'] as $type => $bundle) {
foreach (field_info_extra_fields($entity_type, $type, 'display') as $field_name => $info) {
if (!isset($types[$entity_type . ':' . $field_name])) {
$types[$entity_type . ':' . $field_name] = array(
'category' => t(ucfirst($entity_type)),
'icon' => 'icon_field.png',
'title' => $info['label'],
'description' => isset($info['description']) ? $info['description'] : '',
);
}
$context_types[$entity_type . ':' . $field_name]['types'][$type] = $bundle['label'];
}
}
}
// Create the required context for each field related to the bundle types.
foreach ($types as $key => $field_content_type) {
list($entity_type, $field_name) = explode(':', $key, 2);
$types[$key]['required context'] = new ctools_context_required(t(ucfirst($entity_type)), $entity_type, array(
'type' => array_keys($context_types[$key]['types']),
));
unset($context_types[$key]['types']);
}
return $types;
}
/**
* Returns an edit form for an extra field.
*/
function ctools_entity_field_extra_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
$subtype = $form_state['subtype_name'];
list($entity_type, $field_name) = explode(':', $subtype, 2);
$info = entity_get_info($entity_type);
$view_mode_options = array();
foreach ($info['view modes'] as $mode => $option) {
$view_mode_options[$mode] = $option['label'];
}
$form['view_mode'] = array(
'#title' => t('View mode'),
'#type' => 'select',
'#description' => t('Select a view mode for this extra field.'),
'#options' => $view_mode_options,
'#default_value' => $conf['view_mode'],
);
return $form;
}
function ctools_entity_field_extra_content_type_edit_form_submit($form, &$form_state) {
$form_state['conf']['view_mode'] = $form_state['values']['view_mode'];
}
/**
* Render the extra field.
*/
function ctools_entity_field_extra_content_type_render($subtype, $conf, $panel_args, $context) {
if (empty($context) || empty($context->data)) {
return;
}
// Get a shortcut to the entity.
$entity = clone $context->data;
list($entity_type, $field_name) = explode(':', $subtype, 2);
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
// Invoke the view-hook to get the extra field.
$entity->content = array();
$langcode = $GLOBALS['language_content']->language;
module_invoke_all($entity_type . '_view', $entity, $conf['view_mode'], $langcode);
module_invoke_all('entity_view', $entity, $entity_type, $conf['view_mode'], $langcode);
if (isset($entity->content[$field_name])) {
// Build the content type block.
$block = new stdClass();
$block->module = 'entity_field_extra';
$block->content = $entity->content[$field_name];
$block->delta = $id;
return $block;
}
}
function ctools_entity_field_extra_content_type_admin_title($subtype, $conf, $context) {
$info = ctools_entity_field_extra_content_type_content_type($subtype);
return t('"@s" @field', array('@s' => $context->identifier, '@field' => $info['title']));
}
<?php
/**
* @file
* Plugin to handle the 'page_actions' content type which allows the local
* actions template variables to be embedded into a panel.
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => t('Actions'),
'single' => TRUE,
'icon' => 'icon_page.png',
'description' => t('Add the action links (local tasks) as content.'),
'category' => t('Page elements'),
'render last' => TRUE,
);
/**
* Output function for the 'page_actions' content type.
*
* Outputs the actions (local tasks) of the current page.
*/
function ctools_page_actions_content_type_render($subtype, $conf, $panel_args) {
$block = new stdClass();
$block->content = menu_local_actions();
return $block;
}
<?php
/**
* @file
*
* Plugin to provide a user_edit_form context
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => t('User edit form'),
'description' => t('A user edit form.'),
'context' => 'ctools_context_create_user_edit_form',
'edit form' => 'ctools_context_user_edit_form_settings_form',
'defaults' => array('uid' => ''),
'keyword' => 'user_edit',
'context name' => 'user_edit_form',
'convert list' => 'ctools_context_user_edit_convert_list',
'convert' => 'ctools_context_user_edit_convert',
'placeholder form' => array(
'#type' => 'textfield',
'#description' => t('Enter the user ID of a user for this argument:'),
),
);
/**
* It's important to remember that $conf is optional here, because contexts
* are not always created from the UI.
*/
function ctools_context_create_user_edit_form($empty, $user = NULL, $conf = FALSE) {
static $created;
$context = new ctools_context(array('form', 'user_edit', 'user_form', 'user_edit_form', 'user', 'entity:user'));
$context->plugin = 'user_edit_form';
if ($empty || (isset($created) && $created)) {
return $context;
}
$created = TRUE;
if ($conf) {
// In this case, $user is actually our $conf array.
$uid = is_array($user) && isset($user['uid']) ? $user['uid'] : (is_object($user) ? $user->uid : 0);
if (module_exists('translation')) {
if ($translation = module_invoke('translation', 'user_uid', $uid, $GLOBALS['language']->language)) {
$uid = $translation;
$reload = TRUE;
}
}
if (is_array($user) || !empty($reload)) {
$user = user_load($uid);
}
}
if (!empty($user)) {
$form_id = 'user_profile_form';
$form_state = array('want form' => TRUE, 'build_info' => array('args' => array($user)));
$file = drupal_get_path('module', 'user') . '/user.pages.inc';
require_once DRUPAL_ROOT . '/' . $file;
// This piece of information can let other modules know that more files
// need to be included if this form is loaded from cache:
$form_state['build_info']['files'] = array($file);
$form = drupal_build_form($form_id, $form_state);
// Fill in the 'node' portion of the context
$context->data = $user;
$context->title = isset($user->name) ? $user->name : '';
$context->argument = $user->uid;
$context->form = $form;
$context->form_state = &$form_state;
$context->form_id = $form_id;
$context->form_title = isset($user->name) ? $user->name : '';
$context->restrictions['form'] = array('form');
return $context;
}
}
function ctools_context_user_edit_form_settings_form($form, &$form_state) {
$conf = &$form_state['conf'];
$form['user'] = array(
'#title' => t('Enter the name or UID of a node'),
'#type' => 'textfield',
'#maxlength' => 512,
'#autocomplete_path' => 'ctools/autocomplete/user',
'#weight' => -10,
);
if (!empty($conf['uid'])) {
$info = db_query('SELECT * FROM {user} WHERE uid = :uid', array(':uid' => $conf['uid']))->fetchObject();
if ($info) {
$link = l(t("'%name' [user id %uid]", array('%name' => $info->name, '%uid' => $info->uid)), "user/$info->uid", array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE));
$form['user']['#description'] = t('Currently set to !link', array('!link' => $link));
}
}
$form['uid'] = array(
'#type' => 'value',
'#value' => $conf['uid'],
);
$form['set_identifier'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
'#title' => t('Reset identifier to user name'),
'#description' => t('If checked, the identifier will be reset to the user name of the selected user.'),
);
return $form;
}
/**
* Validate a node.
*/
function ctools_context_user_edit_form_settings_form_validate($form, &$form_state) {
// Validate the autocomplete
if (empty($form_state['values']['uid']) && empty($form_state['values']['user'])) {
form_error($form['user'], t('You must select a user.'));
return;
}
if (empty($form_state['values']['user'])) {
return;
}
$uid = $form_state['values']['user'];
$preg_matches = array();
$match = preg_match('/\[id: (\d+)\]/', $uid, $preg_matches);
if (!$match) {
$match = preg_match('/^id: (\d+)/', $uid, $preg_matches);
}
if ($match) {
$uid = $preg_matches[1];
}
if (is_numeric($uid)) {
$user = db_query('SELECT uid FROM {user} WHEREuid = :uid', array(':uid' => $uid))->fetchObject();
}
else {
$user = db_query('SELECT uid FROM {user} WHERE LOWER(name) = LOWER(:name)', array(':name' => $uid))->fetchObject();
}
form_set_value($form['uid'], $user->uid, $form_state);
}
function ctools_context_user_edit_form_settings_form_submit($form, &$form_state) {
if ($form_state['values']['set_identifier']) {
$user = user_load($form_state['values']['uid']);
$form_state['values']['identifier'] = $user->name;
}
// This will either be the value set previously or a value set by the
// validator.
$form_state['conf']['uid'] = $form_state['values']['uid'];
}
/**
* Provide a list of ways that this context can be converted to a string.
*/
function ctools_context_user_edit_convert_list() {
// Pass through to the "node" context convert list.
$plugin = ctools_get_context('user');
return ctools_context_user_convert_list();
}
/**
* Convert a context into a string.
*/
function ctools_context_user_edit_convert($context, $type) {
// Pass through to the "node" context convert list.
$plugin = ctools_get_context('user');
return ctools_context_user_convert($context, $type);
}
#!/bin/bash
# Run this from the terminal inside a drupal root folder
# i.e. DRUPAL_ROOT_DIR/sites/all/modules/contrib/ctools/tests/ctools.drush.sh
function stamp {
echo ==============
echo timestamp : `date`
echo ==============
}
DRUPAL_ROOT=`drush dd`
MODULE_DIR="$DRUPAL_ROOT/sites/all/modules"
MODULE_NAME="ctools_drush_test"
stamp
echo 'Enabling views module.'
drush en views ctools --yes
stamp
echo 'Reading all export info'
drush ctools-export-info
stamp
echo 'Reading all export info with format'
drush ctools-export-info --format=json
stamp
echo 'Reading tables only from export info'
drush ctools-export-info --tables-only
stamp
echo 'Reading tables only from export info with format'
drush ctools-export-info --tables-only --format=json
stamp
echo 'Reading all disabled exportables'
drush ctools-export-info --disabled
stamp
echo 'Enabling all default views'
drush ctools-export-enable views_view --yes
stamp
echo 'View all default views export data'
drush ctools-export-view views_view --yes
stamp
echo 'View default "archive" view export data'
drush ctools-export-view views_view archive
stamp
echo 'Disable default "archive" view'
drush ctools-export-disable views_view archive
stamp
echo 'Enable default "archive" view'
drush ctools-export-enable views_view archive
stamp
echo 'Reading all enabled exportables (archive disabled)'
drush ctools-export-info
stamp
echo 'Disabling all default views'
drush ctools-export-disable views_view --yes
stamp
echo 'Revert all default views'
drush ctools-export-revert views_view --yes
stamp
echo 'Bulk export all objects'
drush ctools-export $MODULE_NAME --subdir='tests' --choice=1
stamp
echo 'Show all files in created folder'
ls -lAR "$MODULE_DIR/tests/$MODULE_NAME"
stamp
echo 'Removing exported object files'
rm -Rf $MODULE_DIR/tests
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment