updated ctools, panels, date, diff

This commit is contained in:
Bachir Soussi Chiadmi
2017-05-24 19:22:50 +02:00
parent 542ac42fca
commit 9acef9d37e
189 changed files with 2928 additions and 1797 deletions

View File

@@ -39,11 +39,14 @@ function diff_help($path, $arg) {
case 'admin/help#diff':
$output = '<p>' . t('The Diff module replaces the normal <em>Revisions</em> node tab. Diff enhances the listing of revisions with an option to view the differences between any two content revisions. Access to this feature is controlled with the <em>View revisions</em> permission. The feature can be disabled for an entire content type on the content type configuration page. Diff also provides an optional <em>View changes</em> button while editing a node.') . '</p>';
return $output;
case 'node/%/revisions/%/view':
// The translated strings should match node_help('node/%/revisions').
return '<p>' . t('Revisions allow you to track differences between multiple versions of your content, and revert back to older versions.') . '</p>';
case 'node/%/revisions/view/%/%':
return '<p>' . t('Comparing two revisions:') . '</p>';
}
}
@@ -104,8 +107,7 @@ function diff_menu() {
'page callback' => 'diff_latest',
'page arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'access callback' => 'diff_node_revision_access',
'access arguments' => array(1),
'access arguments' => array('access content'),
'tab_parent' => 'node/%/revisions/view',
'file' => 'diff.pages.inc',
);
@@ -152,10 +154,20 @@ function diff_menu() {
);
$items['admin/config/content/diff/entities/node'] = array(
'title' => 'Node',
'title' => 'Nodes',
'description' => 'Node comparison settings.',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/config/content/diff/entities/user'] = array(
'title' => 'Users',
'description' => 'User diff settings.',
'file' => 'diff.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('diff_admin_global_entity_settings', 'user'),
'access arguments' => array('administer site configuration'),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
@@ -197,6 +209,18 @@ function diff_node_revision_access($node, $op = 'view') {
return $may_revision_this_type && _node_revision_access($node, $op);
}
/**
* Implements hook_permission().
*/
function diff_permission() {
return array(
'diff view changes' => array(
'title' => t('Access %view button', array('%view' => t('View changes'))),
'description' => t('Controls access to the %view button when editing content.', array('%view' => t('View changes'))),
),
);
}
/**
* Implements hook_hook_info().
*/
@@ -238,6 +262,28 @@ function diff_entity_info_alter(&$entity_info) {
}
}
/**
* Returns a list of all the existing revision numbers.
*
* Clone of node_revision_list() with revision status included. This would be
* an additional join in Drupal 8.x to the {node_field_revision} table.
*
* @param object $node
* The node object.
*
* @return array
* An associative array keyed by node revision number.
*/
function diff_node_revision_list($node) {
$revisions = array();
$result = db_query('SELECT r.vid, r.title, r.log, r.uid, n.vid AS current_vid, r.status AS status, r.timestamp, u.name FROM {node_revision} r LEFT JOIN {node} n ON n.vid = r.vid INNER JOIN {users} u ON u.uid = r.uid WHERE r.nid = :nid ORDER BY r.vid DESC', array(':nid' => $node->nid));
foreach ($result as $revision) {
$revisions[$revision->vid] = $revision;
}
return $revisions;
}
/**
* Implements hook_block_info().
*/
@@ -287,7 +333,7 @@ function diff_block_view($delta) {
$enabled_types = variable_get('diff_show_diff_inline_node_bundles', array());
if (!empty($enabled_types[$node->type])) {
$block = array();
$revisions = node_revision_list($node);
$revisions = diff_node_revision_list($node);
if (count($revisions) > 1) {
$block['subject'] = t('Highlight changes');
$block['content'] = drupal_get_form('diff_inline_form', $node, $revisions);
@@ -302,7 +348,7 @@ function diff_block_view($delta) {
*/
function diff_node_view_alter(&$build) {
$node = $build['#node'];
if (user_access('view revisions') && in_array($node->type, variable_get('diff_show_diff_inline_node_bundles', array()))) {
if (user_access('view revisions') && in_array($node->type, variable_get('diff_show_diff_inline_node_bundles', array()), TRUE)) {
// Ugly but cheap way to check that we are viewing a node's revision page.
if (arg(2) === 'revisions' && arg(3) === $node->vid) {
module_load_include('inc', 'diff', 'diff.pages');
@@ -320,7 +366,9 @@ function diff_node_view_alter(&$build) {
function diff_form_node_form_alter(&$form, $form_state) {
// Add a 'View changes' button on the node edit form.
$node = $form['#node'];
if (variable_get('diff_show_preview_changes_node_' . $node->type, TRUE) && !empty($node->nid)) {
if (variable_get('diff_show_preview_changes_node_' . $node->type, TRUE)
&& user_access('diff view changes')
&& !empty($node->nid)) {
$form['actions']['preview_changes'] = array(
'#type' => 'submit',
'#value' => t('View changes'),
@@ -347,6 +395,9 @@ function diff_form_node_type_form_alter(&$form, $form_state) {
'#title' => t('Show <em>View changes</em> button on node edit form'),
'#weight' => 10,
'#default_value' => variable_get('diff_show_preview_changes_node_' . $type->type, TRUE),
'#description' => t('You can refine access using the "!perm" permission.', array(
'!perm' => t('Access %view button', array('%view' => t('View changes'))),
)),
);
$form['diff']['diff_enable_revisions_page_node'] = array(
'#type' => 'checkbox',
@@ -430,7 +481,7 @@ function diff_node_form_build_preview_changes($form, &$form_state) {
$changes = theme('table__diff__preview', array(
'header' => $header,
'rows' => $rows,
'attributes' => array('class' => 'diff'),
'attributes' => array('class' => array('diff')),
'colgroups' => _diff_default_cols(),
'sticky' => FALSE,
));
@@ -440,6 +491,24 @@ function diff_node_form_build_preview_changes($form, &$form_state) {
$form_state['rebuild'] = TRUE;
}
/**
* Implementation of hook_features_pipe_COMPONENT_alter().
*/
function diff_features_pipe_node_alter(&$pipe, $data, $export) {
if (!empty($data)) {
$variables = array(
'diff_show_preview_changes_node',
'diff_enable_revisions_page_node',
'diff_view_mode_preview_node',
);
foreach ($data as $node_type) {
foreach ($variables as $variable_name) {
$pipe['variable'][] = $variable_name . '_' . $node_type;
}
}
}
}
/**
* Implements hook_theme().
*/
@@ -483,7 +552,7 @@ function diff_theme() {
* The source string to compare from.
* @param string $b
* The target string to compare to.
* @param boolean $show_header
* @param bool $show_header
* Display diff context headers. For example, "Line x".
* @param array $line_stats
* This structure tracks line numbers across multiple calls to DiffFormatter.
@@ -621,3 +690,85 @@ function diff_build_attachments($jscript = FALSE) {
}
return $attachments;
}
/**
* Implements hook_entity_diff() on behalf of the Node module.
*/
function node_entity_diff($old_node, $new_node, $context) {
$result = array();
if ($context['entity_type'] == 'node') {
module_load_include('inc', 'diff', 'includes/node');
$options = variable_get('diff_additional_options_node', array('title' => 'title'));
foreach (node_entity_diff_options('node') as $key => $option_label) {
if (!empty($options[$key])) {
$func = '_node_entity_diff_additional_options_' . $key;
$result[$key] = $func($old_node, $new_node, $context);
}
}
}
return $result;
}
/**
* Implements hook_entity_diff_options() on behalf of the Node module.
*/
function node_entity_diff_options($entity_type) {
if ($entity_type == 'node') {
$options = array(
'title' => t('Title field'),
// Author field is either the owner or revision creator, neither capture
// a change in the author field.
'author' => t('Author'),
'revision_author' => t('Revision author'),
'type' => t('Node type'),
'publishing_flags' => t('Publishing options'),
// More fields that currently can not be tracked.
'created' => t('Created date'),
'changed' => t('Updated date'),
'revision_timestamp' => t('Revision timestamp'),
);
if (module_exists('comment')) {
$options['comment'] = t('Comment setting');
}
return $options;
}
}
/**
* Implements hook_entity_diff() on behalf of the User module.
*/
function user_entity_diff($old_user, $new_user, $context) {
$result = array();
if ($context['entity_type'] == 'user') {
module_load_include('inc', 'diff', 'includes/user');
$options = variable_get('diff_additional_options_user', array(
'name' => 'name',
'mail' => 'mail',
'status' => 'status',
));
foreach (user_entity_diff_options('user') as $key => $option_label) {
if (!empty($options[$key])) {
$func = '_user_entity_diff_additional_options_' . $key;
$result[$key] = $func($old_user, $new_user, $context);
}
}
}
return $result;
}
/**
* Implements hook_entity_diff_options() on behalf of the User module.
*/
function user_entity_diff_options($entity_type) {
if ($entity_type == 'user') {
$options = array(
'name' => t('Username'),
'mail' => t('E-mail address'),
'roles' => t('Roles'),
'status' => t('Status'),
'timezone' => t('Time zone'),
'password' => t('Password Hash'),
);
return $options;
}
}