first import
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Coder Review module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_alter_alter() on behalf of
|
||||
* coder_review.module.
|
||||
*/
|
||||
function coder_review_custom_formatters_form_alter_alter(&$form, &$form_state, $form_id) {
|
||||
if (in_array($form_id, array('ctools_export_ui_edit_item_form', 'ctools_export_ui_edit_item_wizard_form')) && isset($form['#formatters']) && 'php' == $form['info']['mode']['#default_value']) {
|
||||
drupal_add_css(drupal_get_path('module', 'coder_review') . '/coder_review.css');
|
||||
|
||||
$form['engine']['coder_review'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Coder Review'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
|
||||
$reviews = _coder_review_settings_form(_coder_review_get_default_settings('files'), $system = array(), $files = array());
|
||||
$form['engine']['coder_review']['reviews'] = array_merge($reviews['coder_reviews_group'], array(
|
||||
'#collapsed' => TRUE,
|
||||
));
|
||||
|
||||
$form['engine']['coder_review']['review'] = array(
|
||||
'#type' => 'container',
|
||||
'#prefix' => '<div id="coder-review-wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$form['engine']['coder_review']['button'] = array(
|
||||
'#type' => 'button',
|
||||
'#value' => t('Review'),
|
||||
'#ajax' => array(
|
||||
'callback' => 'custom_formatters_coder_review',
|
||||
'wrapper' => 'coder-review-wrapper',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax callback for Custom Formatters Coder Review integration.
|
||||
*/
|
||||
function custom_formatters_coder_review(&$form, $form_state) {
|
||||
$directory = 'public://custom_formatters/coder_review';
|
||||
if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY)) {
|
||||
global $base_url;
|
||||
|
||||
$md5 = md5($form_state['values']['code']);
|
||||
file_unmanaged_save_data("<?php\n/**\n * @file\n */\n\n{$form_state['values']['code']}", "{$directory}/{$md5}.php", FILE_EXISTS_REPLACE);
|
||||
$file = str_replace($base_url . base_path(), '', file_create_url("{$directory}/{$md5}.php"));
|
||||
|
||||
$form_state = array(
|
||||
'storage' => array(
|
||||
'coder_reviews' => $form_state['values']['coder_reviews'],
|
||||
'coder_severity' => $form_state['values']['coder_severity'],
|
||||
'coder_file_list' => $file,
|
||||
'coder_files' => 1,
|
||||
)
|
||||
);
|
||||
$review = coder_review_page_form(array(), $form_state, 'files');
|
||||
|
||||
$form['engine']['coder_review']['review'][$file] = $review[$file]['output'];
|
||||
foreach ($form['engine']['coder_review']['review'][$file]['#results'] as &$result) {
|
||||
// Adjust the line numbering.
|
||||
$result = preg_replace('/\/\>Line (\d+):(.*?<pre>)/e', '"/>Line " . ($1 - 5) . ":$2"', $result);
|
||||
}
|
||||
unset($form['engine']['coder_review']['review'][$file]['#filename']);
|
||||
|
||||
file_unmanaged_delete("{$directory}/{$md5}.php");
|
||||
}
|
||||
|
||||
drupal_get_messages(NULL, TRUE);
|
||||
return $form['engine']['coder_review']['review'];
|
||||
}
|
100
sites/all/modules/custom_formatters/includes/contextual.inc
Normal file
100
sites/all/modules/custom_formatters/includes/contextual.inc
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contextual links module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_alter_alter() on behalf of
|
||||
* contextual.module.
|
||||
*/
|
||||
function contextual_custom_formatters_form_alter_alter(&$form, $form_state, $form_id) {
|
||||
if ($form_id == 'custom_formatters_settings_form') {
|
||||
$settings = variable_get('custom_formatters_settings', array('contextual' => 1));
|
||||
|
||||
$form['settings']['contextual'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Contextual links integration'),
|
||||
'#default_value' => isset($settings['contextual']) ? $settings['contextual'] : 1,
|
||||
'#options' => array(
|
||||
0 => t('Disabled'),
|
||||
1 => t('Enabled on all Formatters except those listed'),
|
||||
2 => t('Enabled on only the listed Formatters'),
|
||||
),
|
||||
);
|
||||
|
||||
$form['settings']['contextual_list'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => isset($settings['contextual_list']) ? $settings['contextual_list'] : '',
|
||||
'#description' => t('Specify Formatters by using their machine names. Enter one machine name per line.'),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
'input[name="settings[contextual]"]' => array('checked' => FALSE),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_field_formatter_view_element_alter() on
|
||||
* behalf of contextual.module.
|
||||
*
|
||||
* Adds contextual links to Custom Formatter fields.
|
||||
*/
|
||||
function contextual_custom_formatters_field_formatter_view_element_alter(&$element, $formatter) {
|
||||
if (_custom_formatters_contextual_access($formatter->name, $element)) {
|
||||
foreach (element_children($element) as $delta) {
|
||||
$element[$delta] = array(
|
||||
'markup' => $element[$delta],
|
||||
'contextual_links' => array(
|
||||
'#type' => 'contextual_links',
|
||||
'#contextual_links' => array('custom_formatters' => array('admin/structure/formatters/list', array($formatter->name, 'edit'))),
|
||||
'#element' => $element[$delta],
|
||||
),
|
||||
'#prefix' => '<div class="contextual-links-region">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _custom_formatters_contextual_access($name, $element) {
|
||||
if (isset($element[0]['#cf_options']['#contextual_links']) && $element[0]['#cf_options']['#contextual_links'] == FALSE) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$user_access = user_access('access contextual links') && user_access('administer custom formatters');
|
||||
if (!$user_access) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$settings = variable_get('custom_formatters_settings', array('contextual' => 1));
|
||||
$contextual = isset($settings['contextual']) ? $settings['contextual'] : 1;
|
||||
$list = array_unique(explode("\r\n", isset($settings['contextual_list']) ? $settings['contextual_list'] : ''));
|
||||
|
||||
switch ($contextual) {
|
||||
case 0:
|
||||
return FALSE;
|
||||
|
||||
case 1:
|
||||
return !in_array($name, $list) ? TRUE : FALSE;
|
||||
|
||||
case 2:
|
||||
return in_array($name, $list) ? TRUE : FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu_contextual_links_alter().
|
||||
*/
|
||||
function custom_formatters_menu_contextual_links_alter(&$links, $router_item, $root_path) {
|
||||
if ($root_path == 'admin/structure/formatters/list/%/edit') {
|
||||
$links['custom_formatters-edit'] = array_merge(
|
||||
$router_item,
|
||||
array(
|
||||
'title' => 'Edit formatter',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
50
sites/all/modules/custom_formatters/includes/ctools.inc
Normal file
50
sites/all/modules/custom_formatters/includes/ctools.inc
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Chaos tool suite module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_init() on behalf of ctools.module.
|
||||
*/
|
||||
function ctools_custom_formatters_init() {
|
||||
if (strstr(request_uri(), 'system/ajax') && in_array($_POST['form_id'], array('ctools_export_ui_edit_item_form', 'custom_formatters_export_ui_export_form'))) {
|
||||
require_once drupal_get_path('module', 'custom_formatters') . '/plugins/export_ui/custom_formatters.inc';
|
||||
|
||||
/**
|
||||
* Temporary fix for CTools #AJAX issue.
|
||||
* @See http://drupal.org/node/1142812
|
||||
*/
|
||||
ctools_include('export');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ctools_plugin_api().
|
||||
*/
|
||||
function custom_formatters_ctools_plugin_api() {
|
||||
list($module, $api) = func_get_args();
|
||||
if ($module == 'custom_formatters' && $api == 'custom_formatters') {
|
||||
return array('version' => 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ctools_plugin_directory().
|
||||
*/
|
||||
function custom_formatters_ctools_plugin_directory($module, $plugin) {
|
||||
if ($module == 'ctools' && !empty($plugin)) {
|
||||
return "plugins/{$plugin}";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_theme_alter() on behalf of ctools.module.
|
||||
*/
|
||||
function ctools_custom_formatters_theme_alter(&$theme) {
|
||||
$theme['custom_formatters_export_ui_form_preview'] = array(
|
||||
'render element' => 'form',
|
||||
'file' => 'custom_formatters.inc',
|
||||
'path' => drupal_get_path('module', 'custom_formatters') . '/plugins/export_ui'
|
||||
);
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Custom Formatters Administration functionality.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_settings_form($form, $form_state) {
|
||||
$settings = variable_get('custom_formatters_settings', array('label_prefix' => TRUE, 'label_prefix_value' => t('Custom')));
|
||||
|
||||
$form['settings'] = array(
|
||||
'#type' => 'container',
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
|
||||
$form['settings']['label_prefix'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use Label prefix?'),
|
||||
'#description' => t('If checked, all Custom Formatters labels will be prefixed with a set value.'),
|
||||
'#default_value' => $settings['label_prefix'],
|
||||
);
|
||||
|
||||
$form['settings']['label_prefix_value'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label prefix'),
|
||||
'#default_value' => $settings['label_prefix_value'],
|
||||
'#states' => array(
|
||||
'invisible' => array(
|
||||
'input[name="settings[label_prefix]"]' => array('checked' => FALSE),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_settings_form_validate($form, $form_state) {
|
||||
if ($form_state['values']['settings']['label_prefix'] && empty($form_state['values']['settings']['label_prefix_value'])) {
|
||||
form_set_error('settings][label_prefix_value', t('A label prefix must be defined if you wish to use the prefix.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_settings_form_submit($form, $form_state) {
|
||||
drupal_set_message(t('Custom Formatters settings have been updated.'));
|
||||
variable_set('custom_formatters_settings', $form_state['values']['settings']);
|
||||
field_cache_clear();
|
||||
}
|
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Custom Formatters module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_engine().
|
||||
*/
|
||||
function custom_formatters_custom_formatters_engine_info() {
|
||||
$engines = array();
|
||||
|
||||
// PHP engine.
|
||||
$engines['php'] = array(
|
||||
'label' => t('PHP'),
|
||||
'callbacks' => array(
|
||||
'settings form' => 'custom_formatters_engine_php_settings_form',
|
||||
'render' => 'custom_formatters_engine_php_render',
|
||||
'export' => 'custom_formatters_engine_php_export',
|
||||
'help' => 'custom_formatters_engine_php_help',
|
||||
),
|
||||
'file' => drupal_get_path('module', 'custom_formatters') . '/engines/php.inc',
|
||||
);
|
||||
|
||||
// Token engine.
|
||||
$engines['token'] = array(
|
||||
'label' => t('HTML + Tokens'),
|
||||
'callbacks' => array(
|
||||
'settings form' => 'custom_formatters_engine_token_settings_form',
|
||||
'render' => 'custom_formatters_engine_token_render',
|
||||
'export' => 'custom_formatters_engine_token_export',
|
||||
'help' => 'custom_formatters_engine_token_help',
|
||||
),
|
||||
'file' => drupal_get_path('module', 'custom_formatters') . '/engines/token.inc',
|
||||
);
|
||||
|
||||
return $engines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_defaults().
|
||||
*/
|
||||
function custom_formatters_custom_formatters_defaults() {
|
||||
$formatters = array();
|
||||
|
||||
$formatter = new stdClass();
|
||||
$formatter->disabled = TRUE; /* Edit this to true to make a default formatter disabled initially */
|
||||
$formatter->api_version = 2;
|
||||
$formatter->name = 'example_php_image';
|
||||
$formatter->label = 'Example: Image (PHP)';
|
||||
$formatter->description = 'A PHP example formatter; Display a Thumbnail image linked to a Large image.';
|
||||
$formatter->mode = 'php';
|
||||
$formatter->field_types = 'image';
|
||||
$formatter->code = '// Formatter settings.
|
||||
$settings = $variables[\'#display\'][\'settings\'];
|
||||
|
||||
$element = array();
|
||||
foreach ($variables[\'#items\'] as $delta => $item) {
|
||||
$element[$delta] = array(
|
||||
\'#type\' => \'link\',
|
||||
\'#href\' => file_create_url(image_style_path($settings[\'destination_image_style\'], $item[\'uri\'])),
|
||||
\'#title\' => theme(\'image_style\', array(
|
||||
\'style_name\' => $settings[\'source_image_style\'],
|
||||
\'path\' => $item[\'uri\'],
|
||||
)),
|
||||
\'#options\' => array(
|
||||
\'html\' => TRUE,
|
||||
),
|
||||
);
|
||||
}
|
||||
return $element;';
|
||||
$formatter->fapi = '$form = array();
|
||||
$form[\'source_image_style\'] = array(
|
||||
\'#title\' => t(\'Source image styles\'),
|
||||
\'#multiple_toggle\' => \'1\',
|
||||
\'#required\' => \'0\',
|
||||
\'#type\' => \'custom_formatters_image_styles\',
|
||||
\'#weight\' => \'0\',
|
||||
);
|
||||
$form[\'destination_image_style\'] = array(
|
||||
\'#title\' => t(\'Destination image styles\'),
|
||||
\'#multiple_toggle\' => \'1\',
|
||||
\'#required\' => \'0\',
|
||||
\'#type\' => \'custom_formatters_image_styles\',
|
||||
\'#weight\' => \'1\',
|
||||
);
|
||||
';
|
||||
$formatters['example_php_image'] = $formatter;
|
||||
|
||||
$formatter = new stdClass();
|
||||
$formatter->disabled = TRUE; /* Edit this to true to make a default formatter disabled initially */
|
||||
$formatter->api_version = 2;
|
||||
$formatter->name = 'example_token_image';
|
||||
$formatter->label = 'Example: Image (HTML + Token)';
|
||||
$formatter->description = 'A HTML + Tokens example formatter; Display a Thumbnail image linked to a Large image.';
|
||||
$formatter->mode = 'token';
|
||||
$formatter->field_types = 'image';
|
||||
$formatter->code = '<a href="[image-field-value:styles:url:large]"><img src="[image-field-value:styles:url:thumbnail]" alt="[image-field-value:alt]" title="[image-field-value:title]" /></a>';
|
||||
$formatters['example_token_image'] = $formatter;
|
||||
|
||||
return $formatters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_theme_alter().
|
||||
*/
|
||||
function custom_formatters_custom_formatters_theme_alter(&$theme) {
|
||||
$engines = module_invoke_all('custom_formatters_engine_info');
|
||||
foreach (element_children($engines) as $engine) {
|
||||
if (isset($engines[$engine]['file']) && file_exists($engines[$engine]['file'])) {
|
||||
require_once $engines[$engine]['file'];
|
||||
}
|
||||
if (function_exists($function = "custom_formatters_engine_{$engine}_theme_alter")) {
|
||||
$function($theme);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Devel Generate module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_alter_alter on behalf of
|
||||
* devel_generate.module.
|
||||
*/
|
||||
function devel_generate_custom_formatters_form_alter_alter(&$form, &$form_state, $form_id) {
|
||||
if (in_array($form_id, array('ctools_export_ui_edit_item_form', 'ctools_export_ui_edit_item_wizard_form')) && isset($form['#formatters'])) {
|
||||
$item = !empty($form_state['values']) ? $form_state['values'] : (array) $form_state['item'];
|
||||
$entity_type = !empty($item['preview']['entity_type']) ? $item['preview']['entity_type'] : 'node';
|
||||
|
||||
$info = module_invoke_all('custom_formatters_devel_generate_info');
|
||||
if (in_array($entity_type, array_keys($info)) && count($form['engine']['preview']['field']['#options']) > 0) {
|
||||
$form['engine']['preview']['entity']['#options']['devel_generate'] = 'Devel generate';
|
||||
$form['engine']['preview']['entity']['#disabled'] = FALSE;
|
||||
$form['engine']['preview']['button']['#ajax']['callback'] = 'custom_formatters_export_ui_form_js_preview_devel_generate';
|
||||
$form['engine']['preview']['button']['#disabled'] = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit callback for Custom Formatters live preview via Devel Generate.
|
||||
*/
|
||||
function custom_formatters_export_ui_form_js_preview_devel_generate($form, $form_state) {
|
||||
$info = module_invoke_all('custom_formatters_devel_generate_info');
|
||||
if ($form_state['values']['preview']['entity'] !== 'devel_generate' || !function_exists($function = $info[$form_state['values']['preview']['entity_type']]['process callback'])) {
|
||||
return custom_formatters_export_ui_form_js_preview($form, $form_state);
|
||||
}
|
||||
$object = $function($form_state);
|
||||
return custom_formatters_export_ui_form_js_preview($form, $form_state, $object);
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Entity tokens module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_token_tree_types_alter() on behalf of
|
||||
* entity_tokens.module.
|
||||
*/
|
||||
function entity_token_custom_formatters_token_tree_types_alter(&$token_types, $field_type) {
|
||||
module_load_include('inc', 'entity_token', 'entity_token.tokens');
|
||||
$fields = array();
|
||||
foreach (field_info_fields() as $name => $field) {
|
||||
if ($field['type'] == $field_type) {
|
||||
$fields[] = str_replace('_', '-', $name);
|
||||
}
|
||||
}
|
||||
$info = module_exists('token') ? token_get_info() : token_info();
|
||||
foreach ($fields as $field) {
|
||||
foreach (element_children($info['tokens']) as $type) {
|
||||
if (isset($info['tokens'][$type][$field])) {
|
||||
$token_info = $info['tokens'][$type][$field];
|
||||
if (!empty($token_info['entity-token']) && isset($token_info['type']) && entity_token_types_chained($token_info['type'])) {
|
||||
$token_types[] = $token_info['type'];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_token_data_alter() on behalf of
|
||||
* entity_token.module.
|
||||
*/
|
||||
function entity_token_custom_formatters_token_data_alter(&$token_data, &$text, $field) {
|
||||
module_load_include('inc', 'entity_token', 'entity_token.tokens');
|
||||
$field_name = str_replace('_', '-', $field['field_name']);
|
||||
$info = module_exists('token') ? token_get_info() : token_info();
|
||||
foreach (element_children($info['tokens']) as $type) {
|
||||
if (isset($info['tokens'][$type][$field_name])) {
|
||||
$token_info = $info['tokens'][$type][$field_name];
|
||||
if (!empty($token_info['entity-token']) && isset($token_info['type']) && entity_token_types_chained($token_info['type'])) {
|
||||
$token_types = entity_token_types_chained();
|
||||
$item_token_type = entity_property_list_extract_type($token_info['type']);
|
||||
|
||||
// List tokens.
|
||||
if (isset($token_types[$item_token_type])) {
|
||||
$entity_info = entity_get_info($token_types[$item_token_type]);
|
||||
$entity = entity_load($token_types[$item_token_type], array($token_data['item'][$entity_info['entity keys']['id']]));
|
||||
$token_data[$token_info['type']] = array($entity[$token_data['item'][$entity_info['entity keys']['id']]]);
|
||||
$text = str_replace('[list:', "[{$token_info['type']}:", $text);
|
||||
}
|
||||
|
||||
// Structural tokens.
|
||||
elseif ('struct' == $token_info['type']) {
|
||||
$entity_info = entity_get_info($field['type']);
|
||||
if (isset($entity_info['entity keys'])) {
|
||||
$entity = entity_load($field['type'], array($token_data['item'][$entity_info['entity keys']['id']]));
|
||||
$token_data['struct'] = entity_metadata_wrapper($field['type'], $entity[$token_data['item'][$entity_info['entity keys']['id']]]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
sites/all/modules/custom_formatters/includes/features.inc
Normal file
23
sites/all/modules/custom_formatters/includes/features.inc
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Features module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_features_pipe_component_alter().
|
||||
*/
|
||||
function custom_formatters_features_pipe_field_alter(&$pipe, $data, $export) {
|
||||
foreach ($data as $id) {
|
||||
list($entity_type, $bundle_name, $field_name) = explode('-', $id);
|
||||
$field = field_info_instance($entity_type, $field_name, $bundle_name);
|
||||
foreach ($field['display'] as $display) {
|
||||
if (isset($display['module']) && $display['module'] == 'custom_formatters') {
|
||||
$formatter = custom_formatters_crud_load(drupal_substr($display['type'], 18));
|
||||
if ($formatter && isset($formatter->export_type) && $formatter->export_type == EXPORT_IN_DATABASE) {
|
||||
$pipe['formatters'][$formatter->name] = $formatter->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
127
sites/all/modules/custom_formatters/includes/field.inc
Normal file
127
sites/all/modules/custom_formatters/includes/field.inc
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Field module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_info().
|
||||
*/
|
||||
function custom_formatters_field_formatter_info() {
|
||||
$formatters = array();
|
||||
$settings = variable_get('custom_formatters_settings', array('label_prefix' => TRUE, 'label_prefix_value' => t('Custom')));
|
||||
|
||||
foreach (custom_formatters_crud_load_all(TRUE) as $key => $formatter) {
|
||||
$label = $settings['label_prefix'] ? "{$settings['label_prefix_value']}: {$formatter->label}" : $formatter->label;
|
||||
$formatters["custom_formatters_{$key}"] = array(
|
||||
'label' => $label,
|
||||
'field types' => drupal_explode_tags($formatter->field_types),
|
||||
);
|
||||
|
||||
if (isset($formatter->fapi)) {
|
||||
ob_start();
|
||||
eval($formatter->fapi);
|
||||
ob_get_clean();
|
||||
|
||||
if (isset($form)) {
|
||||
$formatters["custom_formatters_{$key}"]['settings'] = array();
|
||||
foreach ($form as $form_key => $element) {
|
||||
$formatters["custom_formatters_{$key}"]['settings'][$form_key] = isset($element['#default_value']) ? $element['#default_value'] : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $formatters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_settings_summary().
|
||||
*/
|
||||
function custom_formatters_field_formatter_settings_summary($field, $instance, $view_mode) {
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
$formatter = custom_formatters_crud_load(drupal_substr($display['type'], 18));
|
||||
|
||||
$summary = '';
|
||||
|
||||
if (isset($formatter->fapi)) {
|
||||
ob_start();
|
||||
eval($formatter->fapi);
|
||||
ob_get_clean();
|
||||
|
||||
if (isset($form)) {
|
||||
foreach ($form as $key => $element) {
|
||||
if (isset($element['#type']) && !in_array($element['#type'], array('fieldset'))) {
|
||||
$value = empty($settings[$key]) ? '<em>' . t('Empty') . '</em>' : $settings[$key];
|
||||
$value = is_array($value) ? implode(', ', array_filter($value)) : $value;
|
||||
$summary .= "{$element['#title']}: {$value}<br />";
|
||||
}
|
||||
}
|
||||
$summary = !empty($summary) ? $summary : ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_settings_form().
|
||||
*/
|
||||
function custom_formatters_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
$formatter = custom_formatters_crud_load(drupal_substr($display['type'], 18));
|
||||
|
||||
$element = array();
|
||||
|
||||
if (isset($formatter->fapi)) {
|
||||
ob_start();
|
||||
eval($formatter->fapi);
|
||||
ob_get_clean();
|
||||
|
||||
if (isset($form)) {
|
||||
$element = $form;
|
||||
foreach (array_keys($element) as $key) {
|
||||
$element[$key]['#default_value'] = $settings[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_view().
|
||||
*/
|
||||
function custom_formatters_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display, $formatter = NULL) {
|
||||
$element = array();
|
||||
|
||||
$formatter = empty($formatter) ? custom_formatters_crud_load(drupal_substr($display['type'], 18)) : $formatter;
|
||||
if (isset($formatter) && !empty($items)) {
|
||||
$engines = module_invoke_all('custom_formatters_engine_info');
|
||||
$engine = $formatter->mode;
|
||||
if (isset($engines[$engine]['file']) && file_exists($engines[$engine]['file'])) {
|
||||
require_once $engines[$engine]['file'];
|
||||
}
|
||||
|
||||
if (function_exists($function = $engines[$engine]['callbacks']['render'])) {
|
||||
$element = $function($formatter, $obj_type, $object, $field, $instance, $langcode, $items, $display);
|
||||
if (is_string($element)) {
|
||||
$element = array(
|
||||
array(
|
||||
'#markup' => $element,
|
||||
),
|
||||
);
|
||||
}
|
||||
foreach (element_children($element) as $delta) {
|
||||
$element[$delta]['#cf_options'] = isset($display['#cf_options']) ? $display['#cf_options'] : array();
|
||||
}
|
||||
}
|
||||
|
||||
// Allow other modules to modify the element.
|
||||
drupal_alter('custom_formatters_field_formatter_view_element', $element, $formatter);
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
208
sites/all/modules/custom_formatters/includes/form_builder.inc
Normal file
208
sites/all/modules/custom_formatters/includes/form_builder.inc
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Form Builder module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_alter_alter() on behalf of
|
||||
* form_builder.module.
|
||||
*/
|
||||
function form_builder_custom_formatters_form_alter_alter(&$form, &$form_state, $form_id) {
|
||||
if (in_array($form_id, array('ctools_export_ui_edit_item_form', 'ctools_export_ui_edit_item_wizard_form')) && isset($form['#formatters']) && isset($form['engine']['settings'])) {
|
||||
if ($form_state['op'] == 'add' || ($form_state['op'] == 'edit' && !custom_formatters_formatter_is_active($form_state['item']))) {
|
||||
drupal_add_css(drupal_get_path('module', 'custom_formatters') . '/styles/custom_formatters.form_builder.css');
|
||||
|
||||
$form['engine']['settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Formatter settings'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.admin');
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.api');
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.cache');
|
||||
|
||||
$form_type = 'custom_formatters';
|
||||
$form_id = drupal_substr($form['#build_id'], 0, 32);
|
||||
|
||||
// Set the current form type (used for display of the sidebar block).
|
||||
form_builder_active_form($form_type, $form_id);
|
||||
|
||||
// Load the current state of the form.
|
||||
$form_structure = _custom_formatters_form_builder_load_form($form['#item'], $form_id);
|
||||
|
||||
$form['engine']['settings']['preview'] = form_builder_preview($form, $form_state, $form_structure, $form_type, $form_id);
|
||||
$form['#submit'][] = 'custom_formatters_form_builder_submit';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_form_builder_submit($form, &$form_state) {
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.admin');
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.api');
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.cache');
|
||||
|
||||
// @TODO - Reproduce this functionality or require form_builder_examples.module.
|
||||
include drupal_get_path('module', 'form_builder') . '/examples/form_builder_examples.module';
|
||||
|
||||
$form_id = drupal_substr($form['form_build_id']['#value'], 0, 32);
|
||||
$form_cache = form_builder_cache_load('custom_formatters', $form_id);
|
||||
if (is_array($form_cache)) {
|
||||
$form_state['item']->fapi = form_builder_examples_export_recurse($form_cache);
|
||||
}
|
||||
|
||||
// Remove the cached form_builder form.
|
||||
form_builder_cache_delete('custom_formatters', $form_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Form Builder form.
|
||||
*/
|
||||
function _custom_formatters_form_builder_load_form($formatter, $form_id) {
|
||||
$form = array();
|
||||
|
||||
// Load form from cache during AJAX callback.
|
||||
if (strstr(request_uri(), 'system/ajax')) {
|
||||
$form = form_builder_cache_load('custom_formatters', $form_id);
|
||||
}
|
||||
|
||||
// Load form from formatter.
|
||||
elseif (!empty($formatter->name) && isset($formatter->fapi)) {
|
||||
ob_start();
|
||||
eval($formatter->fapi);
|
||||
ob_get_clean();
|
||||
|
||||
if (isset($form)) {
|
||||
foreach ($form as $key => &$element) {
|
||||
$element['#key'] = $key;
|
||||
$element['#form_builder'] = array(
|
||||
'element_id' => $key,
|
||||
'element_type' => $element['#type'],
|
||||
'configurable' => TRUE,
|
||||
'removable' => TRUE,
|
||||
);
|
||||
}
|
||||
}
|
||||
form_builder_cache_save('custom_formatters', $form_id, $form);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_builder_types().
|
||||
*/
|
||||
function custom_formatters_form_builder_types() {
|
||||
$fields = array();
|
||||
|
||||
$fields['select'] = array(
|
||||
'title' => t('Select list'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'default_value',
|
||||
'required',
|
||||
'options',
|
||||
'multiple', // Handled by options element.
|
||||
'key_type', // Handled by options element.
|
||||
'key_type_toggle', // Handled by options element.
|
||||
'key_type_toggled', // Handled by options element.
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New select list'),
|
||||
'#type' => 'select',
|
||||
'#options' => array('1' => 'one', '2' => 'two', '3' => 'three'),
|
||||
'#multiple_toggle' => TRUE,
|
||||
),
|
||||
);
|
||||
|
||||
$fields['checkboxes'] = array(
|
||||
'title' => t('Checkboxes'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'default_value',
|
||||
'required',
|
||||
'options',
|
||||
'multiple',
|
||||
'key_type', // Handled by options element.
|
||||
'key_type_toggle', // Handled by options element.
|
||||
'key_type_toggled', // Handled by options element.
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New checkboxes'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => array('one' => 'one', 'two' => 'two', 'three' => 'three'),
|
||||
),
|
||||
);
|
||||
|
||||
$fields['radios'] = array(
|
||||
'title' => t('Radios'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'default_value',
|
||||
'required',
|
||||
'options',
|
||||
'key_type', // Handled by options element.
|
||||
'key_type_toggle', // Handled by options element.
|
||||
'key_type_toggled', // Handled by options element.
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New radios'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array('one' => 'one', 'two' => 'two', 'three' => 'three'),
|
||||
),
|
||||
);
|
||||
|
||||
$fields['textfield'] = array(
|
||||
'title' => t('Textfield'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'field_prefix',
|
||||
'field_suffix',
|
||||
'default_value',
|
||||
'required',
|
||||
'size',
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New textfield'),
|
||||
'#type' => 'textfield',
|
||||
),
|
||||
);
|
||||
|
||||
$fields['textarea'] = array(
|
||||
'title' => t('Textarea'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'default_value',
|
||||
'required',
|
||||
'rows',
|
||||
'cols',
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New textarea'),
|
||||
'#type' => 'textarea',
|
||||
),
|
||||
);
|
||||
|
||||
// Allow other modules to modify the fields.
|
||||
drupal_alter('custom_formatters_form_builder_types', $fields);
|
||||
|
||||
return array(
|
||||
'custom_formatters' => $fields
|
||||
);
|
||||
}
|
109
sites/all/modules/custom_formatters/includes/help.inc
Normal file
109
sites/all/modules/custom_formatters/includes/help.inc
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Help module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function custom_formatters_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'admin/help#custom_formatters':
|
||||
$output = '<h3>' . t('Table of Contents') . "</h3>\n"
|
||||
. '<a href="#about">' . t('About') . '</a> | <a href="#create">' . t('Creating a Formatter') . '</a> | <a href="#test">' . t('Testing a Formatter') . '</a> | <a href="#use">' . t('Using a Formatter') . '</a> | <a href="#cfcom">' . t('CustomFormatters.com') . "</a>\n"
|
||||
. "<p> </p>\n"
|
||||
. '<h3><a name="about"></a>' . t('About') . "</h3>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('The Custom Formatters module is a utility to simplify the creation of Field Formatters, which can be used to theme the output of a Field via the Field UI, Views, Display Suite, Wysiwyg Fields and many other modules.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('Field Formatters created within the Custom Formatters interface can be used as is or exported as either a standard Drupal API Field Formatter or as a Custom Formatters CTools Exportable.')
|
||||
. "</p>\n"
|
||||
. "<p> </p>\n"
|
||||
. '<h3><a name="create"></a>' . t('Creating a Formatter') . "</h3>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('Formatters can be created via the Formatters interface (!cfui) by clicking the !add button.', array('!cfui' => l(t('Administration » Structure » Formatters'), 'admin/structure/formatters', array('html' => TRUE)), '!add' => l(t('Add'), 'admin/structure/formatters/add'))) . "<br />\n"
|
||||
. "</p>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('The Formatter add/edit form may vary based on the Format you choose, but in general all Formatters should consist of the following:') . "\n"
|
||||
. "</p>\n"
|
||||
. "<dl>\n"
|
||||
. ' <dt><strong>' . t('Formatter name / Machine name') . "</strong></dt>\n"
|
||||
. ' <dd>' . t('The Formatter name and the Machine name, in general generated via the same field, are the Human readable name and the unique identifier for the Formatter.') . "</dd>\n"
|
||||
. ' <dt><strong>' . t('Description') . "</strong></dt>\n"
|
||||
. ' <dd>' . t('Used purely for administration purposes, displays as a tooltip on the Formatters UI and in the Formatter add/edit form only.') . "</dd>\n"
|
||||
. ' <dt><strong>' . t('Format') . "</strong></dt>\n"
|
||||
. " <dd>\n"
|
||||
. ' ' . t('The format that the Formatter is to be created in, may change the Formatters add/edit form.') . "<br />\n"
|
||||
. ' ' . t('Two format engines are supplied out of the box, <strong>PHP</strong> and <strong>HTML + Tokens</strong>.') . "\n"
|
||||
. " </dd>\n"
|
||||
. ' <dt><strong>' . t('Field type(s)') . "</strong></dt>\n"
|
||||
. " <dd>\n"
|
||||
. ' ' . t('Which field type(s) the Formatter will apply to (file, image, text, etc).') . "<br />\n"
|
||||
. ' ' . t('The value of this field should be the machine name of the field type, not the name of a field you have created on a Content type, available values will be auto-completed as you type.') . "\n"
|
||||
. " </dd>\n"
|
||||
. ' <dt><strong>' . t('Formatter') . "</strong></dt>\n"
|
||||
. " <dd>\n"
|
||||
. ' ' . t('The actual value of the Formatter, style depending on the chosen Format:') . "<br /><br />\n";
|
||||
|
||||
$items = array();
|
||||
$engines = module_invoke_all('custom_formatters_engine_info');
|
||||
foreach ($engines as $engine) {
|
||||
if (isset($engine['file']) && file_exists($engine['file'])) {
|
||||
require_once $engine['file'];
|
||||
}
|
||||
if (isset($engine['callbacks']['help']) && function_exists($engine['callbacks']['help'])) {
|
||||
$items[] = ' <strong>' . $engine['label'] . "</strong><br />\n"
|
||||
. ' ' . $engine['callbacks']['help']()
|
||||
. "<br /><br />\n";
|
||||
}
|
||||
}
|
||||
if (count($items) > 0) {
|
||||
$output .= theme('item_list', array('items' => $items));
|
||||
}
|
||||
|
||||
$output .= " </dd>\n"
|
||||
. ' <dt><strong>' . t('Formatter Settings') . "</strong></dt>\n"
|
||||
. " <dd>\n"
|
||||
. " <p>\n"
|
||||
. ' ' . t('As of Custom Formatters 7.x-2.1, the PHP format now supports Formatter Settings, which allow you PHP formatters to be configured on each instance of use (Display settings per content type, etc).') . "\n"
|
||||
. " </p>\n"
|
||||
. " <p>\n"
|
||||
. ' ' . t('To enable the Formatter Settings functionality uou need to download and enable the <a href="http://drupal.org/project/form_builder">Form Builder</a> module, once enabled, you will be able to drag and drop fields to create your settings form, and then access the settings inside of your Formatter.') . "\n"
|
||||
. " </p>\n"
|
||||
. " <p>\n"
|
||||
. ' ' . t('The <a href="!url">Example: Image (PHP)</a> Formatter demonstrates how Formatter Settings can be used.', array('!url' => url('admin/structure/formatters/list/example_php_image/edit'))) . "\n"
|
||||
. " </p>\n"
|
||||
. " </dd>\n"
|
||||
. "</dl>\n"
|
||||
. "<p> </p>\n"
|
||||
. '<h3><a name="test"></a>' . t('Testing a Formatter') . "</h3>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('The Formatter add/edit form includes a Preview tool allowing quick testing of the Formatter on live content.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('To do so all you need to do is expand the Preview fieldset and select a populated Entity type (Node, Comment, etc), Bundle (Article, Basic page, etc) and Field (Image, Tags, etc) combination, select the desired Entity for testing and hit the <strong>Preview</strong> button.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('Enabling the <a href="http://drupal.org/project/devel">Devel</a> and Devel Generate module (packaged with the Devel module) adds additional debugging information into your Formatter preview.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p> </p>\n"
|
||||
. '<h3><a name="use"></a>' . t('Using a Formatter') . "</h3>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('Formatters can be used on a variety of different modules, including, but not limited to, Drupal Core Field UI, Views, Display Suite and Insert modules.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('Instructions on how to apply Formatters to Fields varies from module to module, but in general there will be a Format or Formatter field with the Field configuton within said module.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p> </p>\n"
|
||||
. '<h3><a name="cfcom"></a>' . t('<a href="http://customformatters.com">CustomFormatters.com</a>') . "</h3>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('<a href="http://customformatters.com">CustomFormatters.com</a> is a Custom Formatters repository, containing a every growing list of reusable Custom Formatters available as raw code snippets, exportables and as Drupal API field formatters, it\'s a useful resouce to see examples of how to create Formatters.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p> </p>\n"
|
||||
. "<p> </p>\n";
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
63
sites/all/modules/custom_formatters/includes/image.inc
Normal file
63
sites/all/modules/custom_formatters/includes/image.inc
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Image module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_theme_alter() on behalf of image.module.
|
||||
*/
|
||||
function image_custom_formatters_theme_alter(&$theme) {
|
||||
$theme['custom_formatters_image_styles'] = array(
|
||||
'render element' => 'element',
|
||||
'file' => 'includes/image.inc',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_element_info_alter() on behalf of
|
||||
* image.module.
|
||||
*/
|
||||
function image_custom_formatters_element_info_alter(&$types) {
|
||||
$types['custom_formatters_image_styles'] = array(
|
||||
'#input' => TRUE,
|
||||
'#multiple' => FALSE,
|
||||
'#process' => array('form_process_select', 'ajax_process_form'),
|
||||
'#theme' => 'custom_formatters_image_styles',
|
||||
'#theme_wrappers' => array('form_element'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_builder_types_alter() on behalf of
|
||||
* image.module.
|
||||
*/
|
||||
function image_custom_formatters_form_builder_types_alter(&$fields) {
|
||||
$fields['image_styles'] = array(
|
||||
'title' => t('Image styles'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'default_value',
|
||||
'required',
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New styles selector'),
|
||||
'#type' => 'custom_formatters_image_styles',
|
||||
'#multiple_toggle' => TRUE,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme callback for Custom Formatters Image Styles element.
|
||||
*/
|
||||
function theme_custom_formatters_image_styles($variables) {
|
||||
$element = $variables['element'];
|
||||
$element['#options'] = image_style_options();
|
||||
element_set_attributes($element, array('id', 'name', 'size'));
|
||||
_form_set_class($element, array('form-select'));
|
||||
|
||||
return '<select' . drupal_attributes($element['#attributes']) . '>' . form_select_options($element) . '</select>';
|
||||
}
|
53
sites/all/modules/custom_formatters/includes/insert.inc
Normal file
53
sites/all/modules/custom_formatters/includes/insert.inc
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Insert module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_insert_styles().
|
||||
*/
|
||||
function custom_formatters_insert_styles() {
|
||||
$insert_styles = array();
|
||||
$supported = array('image', 'file');
|
||||
$settings = variable_get('custom_formatters_settings', array('label_prefix' => TRUE, 'label_prefix_value' => t('Custom')));
|
||||
|
||||
foreach (custom_formatters_crud_load_all() as $formatter) {
|
||||
if (array_intersect($supported, drupal_explode_tags($formatter->field_types))) {
|
||||
$label = $settings['label_prefix'] ? "{$settings['label_prefix_value']}: {$formatter->label}" : $formatter->label;
|
||||
$insert_styles["custom_formatters_{$formatter->name}"] = array(
|
||||
'label' => $label,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $insert_styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_insert_content().
|
||||
*/
|
||||
function custom_formatters_insert_content($item, $style, $widget) {
|
||||
$menu_item = menu_get_item();
|
||||
$form_build_id = end($menu_item['page_arguments']);
|
||||
|
||||
if (is_string($form_build_id)) {
|
||||
$form = form_get_cache($form_build_id, $form_state = array());
|
||||
|
||||
$obj_type = $form['#entity_type'];
|
||||
$object = $form["#{$obj_type}"];
|
||||
$field = field_info_field($menu_item['page_arguments'][0]);
|
||||
$instance = field_info_instance($obj_type, $field['field_name'], $form['#bundle']);
|
||||
$langcode = field_language($obj_type, $object, $field['field_name']);
|
||||
$items = array((array) file_load($item['fid']));
|
||||
$display = $instance['display']['default'];
|
||||
$formatter = custom_formatters_crud_load(drupal_substr($style['name'], 18));
|
||||
|
||||
$display['cf_options'] = array(
|
||||
'#contextual_links' => FALSE,
|
||||
);
|
||||
|
||||
return render(custom_formatters_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display, $formatter));
|
||||
}
|
||||
return FALSE;
|
||||
}
|
20
sites/all/modules/custom_formatters/includes/libraries.inc
Normal file
20
sites/all/modules/custom_formatters/includes/libraries.inc
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Libraries API integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_alter_alter() on behalf of
|
||||
* libraries.module.
|
||||
*/
|
||||
function libraries_custom_formatters_form_alter_alter(&$form, $form_state, $form_id) {
|
||||
if (in_array($form_id, array('ctools_export_ui_edit_item_form', 'ctools_export_ui_edit_item_wizard_form')) && isset($form['#formatters'])) {
|
||||
// EditArea library support.
|
||||
if (in_array('editarea', array_keys(libraries_get_libraries()))) {
|
||||
$form['#attached']['js'][] = libraries_get_path('editarea') . '/edit_area/edit_area_full.js';
|
||||
|
||||
$form['engine']['code']['#resizable'] = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
43
sites/all/modules/custom_formatters/includes/node.inc
Normal file
43
sites/all/modules/custom_formatters/includes/node.inc
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Node module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_devel_generate_info() on behalf of
|
||||
* node.module.
|
||||
*/
|
||||
function node_custom_formatters_devel_generate_info() {
|
||||
return array(
|
||||
'node' => array(
|
||||
'process callback' => 'custom_formatters_node_devel_generate_process',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process callback for Node Devel Generate integration.
|
||||
*/
|
||||
function custom_formatters_node_devel_generate_process($form_state) {
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate');
|
||||
|
||||
$object = new stdClass();
|
||||
$object->nid = mt_rand(1, 100);
|
||||
$object->type = $form_state['values']['preview']['bundle'];
|
||||
$object->uid = $GLOBALS['user']->uid;
|
||||
$type = node_type_get_type($object);
|
||||
$object->title = $type->has_title ? devel_create_greeking(mt_rand(2, rand(4, 10)), TRUE) : '';
|
||||
$object->revision = mt_rand(0, 1);
|
||||
$object->promote = mt_rand(0, 1);
|
||||
|
||||
devel_generate_set_language(array(), $object);
|
||||
|
||||
$object->created = REQUEST_TIME;
|
||||
|
||||
// Populate all core fields on behalf of field.module
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate.fields');
|
||||
devel_generate_fields($object, $form_state['values']['preview']['entity_type'], $object->type);
|
||||
|
||||
return $object;
|
||||
}
|
38
sites/all/modules/custom_formatters/includes/system.inc
Normal file
38
sites/all/modules/custom_formatters/includes/system.inc
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* System module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*/
|
||||
function custom_formatters_init() {
|
||||
module_invoke_all('custom_formatters_init');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_element_info().
|
||||
*/
|
||||
function custom_formatters_element_info() {
|
||||
$types = array();
|
||||
drupal_alter('custom_formatters_element_info', $types);
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function custom_formatters_theme() {
|
||||
$theme = array();
|
||||
drupal_alter('custom_formatters_theme', $theme);
|
||||
return $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function custom_formatters_form_alter(&$form, &$form_state, $form_id) {
|
||||
drupal_alter('custom_formatters_form_alter', $form, $form_state, $form_id);
|
||||
drupal_alter("custom_formatters_form_{$form_id}_alter", $form, $form_state);
|
||||
}
|
42
sites/all/modules/custom_formatters/includes/taxonomy.inc
Normal file
42
sites/all/modules/custom_formatters/includes/taxonomy.inc
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Taxonomy module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_devel_generate_info() on behalf of
|
||||
* taxonomy.module.
|
||||
*/
|
||||
function taxonomy_custom_formatters_devel_generate_info() {
|
||||
return array(
|
||||
'taxonomy_term' => array(
|
||||
'process callback' => 'custom_formatters_taxonomy_term_devel_generate_process',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process callback for Taxonomy term Devel Generate integration.
|
||||
*/
|
||||
function custom_formatters_taxonomy_term_devel_generate_process($form_state) {
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate');
|
||||
|
||||
$vocab = taxonomy_vocabulary_machine_name_load($form_state['values']['preview']['bundle']);
|
||||
|
||||
$object = new stdClass();
|
||||
$object->tid = mt_rand(1, 100);
|
||||
$object->vid = $vocab->vid;
|
||||
$object->name = devel_generate_word(mt_rand(2, 12));
|
||||
$object->description = "description of {$object->name}";
|
||||
$object->format = filter_fallback_format();
|
||||
$object->weight = mt_rand(0, 10);
|
||||
$object->vocabulary_machine_name = $form_state['values']['preview']['bundle'];
|
||||
$object->language = LANGUAGE_NONE;
|
||||
|
||||
// Populate all core fields on behalf of field.module
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate.fields');
|
||||
devel_generate_fields($object, 'taxonomy_term', $object->vocabulary_machine_name);
|
||||
|
||||
return $object;
|
||||
}
|
55
sites/all/modules/custom_formatters/includes/token.inc
Normal file
55
sites/all/modules/custom_formatters/includes/token.inc
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Token module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_ctools_export_ui_edit_item_form_alter_alter()
|
||||
* on behalf of token.module.
|
||||
*/
|
||||
function token_custom_formatters_form_ctools_export_ui_edit_item_form_alter_alter(&$form, $form_state) {
|
||||
if (isset($form['#formatters']) && $form['#formatters'] && 'token' == $form['info']['mode']['#default_value']) {
|
||||
// Add token tree.
|
||||
$fieldable = array();
|
||||
$entity_types = entity_get_info();
|
||||
foreach ($entity_types as $entity_type => $entity) {
|
||||
if ($entity['fieldable']) {
|
||||
$fieldable[] = $entity['token type'];
|
||||
}
|
||||
}
|
||||
$token_types = $fieldable;
|
||||
$field_type = $form['engine']['field_types']['#default_value'];
|
||||
drupal_alter('custom_formatters_token_tree_types', $token_types, $field_type);
|
||||
$form['engine']['tokens'] = array(
|
||||
'#title' => t('Tokens'),
|
||||
'#type' => 'fieldset',
|
||||
'#description' => theme('token_tree', array('token_types' => $token_types)),
|
||||
'#weight' => 50,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_builder_types_alter() on behalf of
|
||||
* token.module.
|
||||
*/
|
||||
function token_custom_formatters_form_builder_types_alter(&$fields) {
|
||||
$fields['token_tree'] = array(
|
||||
'title' => t('Token tree'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'key'
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('Tokens'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#theme' => 'token_tree',
|
||||
'#token_types' => 'all',
|
||||
),
|
||||
);
|
||||
}
|
42
sites/all/modules/custom_formatters/includes/user.inc
Normal file
42
sites/all/modules/custom_formatters/includes/user.inc
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* User module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_devel_generate_info() on behalf of
|
||||
* user.module.
|
||||
*/
|
||||
function user_custom_formatters_devel_generate_info() {
|
||||
return array(
|
||||
'user' => array(
|
||||
'process callback' => 'custom_formatters_user_devel_generate_process',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process callback for User Devel Generate integration.
|
||||
*/
|
||||
function custom_formatters_user_devel_generate_process($form_state) {
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate');
|
||||
|
||||
$url = parse_url($GLOBALS['base_url']);
|
||||
|
||||
$object = new stdClass();
|
||||
$object->uid = mt_rand(3, 100);
|
||||
$object->name = devel_generate_word(mt_rand(6, 12));
|
||||
$object->pass = user_password();
|
||||
$object->mail = "{$object->name}@{$url['host']}";
|
||||
$object->status = 1;
|
||||
$object->created = 1;
|
||||
$object->roles = drupal_map_assoc(array(DRUPAL_AUTHENTICATED_RID));
|
||||
$object->language = LANGUAGE_NONE;
|
||||
|
||||
// Populate all core fields on behalf of field.module
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate.fields');
|
||||
devel_generate_fields($object, 'user', 'user');
|
||||
|
||||
return $object;
|
||||
}
|
Reference in New Issue
Block a user