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

@@ -67,7 +67,8 @@ function file_field_diff_view($items, $context) {
if ($settings['compare_display_field'] && !empty($field['settings']['display_field'])) {
$output['display'] = $item['display'] ? t('Displayed') : t('Hidden');
}
$diff_items[$delta] = implode('; ', $output);
$separator = $settings['property_separator'] == 'nl' ? "\n" : $settings['property_separator'];
$diff_items[$delta] = implode($separator, $output);
}
}
@@ -82,6 +83,7 @@ function file_field_diff_default_options($field_type) {
'show_id' => 0,
'compare_display_field' => 0,
'compare_description_field' => 0,
'property_separator' => '; ',
);
}
@@ -107,5 +109,21 @@ function file_field_diff_options_form($field_type, $settings) {
'#default_value' => $settings['compare_display_field'],
'#description' => t('This is only used if the "Enable <em>Display</em> field" is checked in the field settings.'),
);
$options_form['property_separator'] = array(
'#type' => 'select',
'#title' => t('Property separator'),
'#default_value' => $settings['property_separator'],
'#description' => t('Provides the ability to show properties inline or across multiple lines.'),
'#options' => array(
', ' => t('Comma (,)'),
'; ' => t('Semicolon (;)'),
' ' => t('Space'),
'nl' => t('New line'),
),
);
// Allow users to set their own separator using variable_set().
if (!isset($options_form['#options'][$settings['property_separator']])) {
$options_form['#options'][$settings['property_separator']] = $settings['property_separator'];
}
return $options_form;
}

View File

@@ -68,7 +68,8 @@ function image_field_diff_view($items, $context) {
if ($settings['show_id']) {
$output[] = t('File ID: !fid', $t_args);
}
$diff_items[$delta] = implode('; ', $output);
$separator = $settings['property_separator'] == 'nl' ? "\n" : $settings['property_separator'];
$diff_items[$delta] = implode($separator, $output);
}
}
@@ -83,6 +84,7 @@ function image_field_diff_default_options($field_type) {
'show_id' => 0,
'compare_alt_field' => 0,
'compare_title_field' => 0,
'property_separator' => '; ',
);
}
@@ -108,5 +110,21 @@ function image_field_diff_options_form($field_type, $settings) {
'#default_value' => $settings['compare_title_field'],
'#description' => t('This is only used if the "Enable <em>Title</em> field" is checked in the instance settings.'),
);
$options_form['property_separator'] = array(
'#type' => 'select',
'#title' => t('Property separator'),
'#default_value' => $settings['property_separator'],
'#description' => t('Provides the ability to show properties inline or across multiple lines.'),
'#options' => array(
', ' => t('Comma (,)'),
'; ' => t('Semicolon (;)'),
' ' => t('Space'),
'nl' => t('New line'),
),
);
// Allow users to set their own separator using variable_set().
if (!isset($options_form['#options'][$settings['property_separator']])) {
$options_form['#options'][$settings['property_separator']] = $settings['property_separator'];
}
return $options_form;
}

View File

@@ -6,102 +6,199 @@
*/
/**
* Implements hook_entity_diff().
*
* This function compares core node properties. This is currently limited to:
* - title: The title of the node.
*
* @param object $old_node
* The older node revision.
* @param object $new_node
* The newer node revision.
* @param array $context
* An associative array containing:
* - entity_type: The entity type; e.g., 'node' or 'user'.
* - old_entity: The older entity.
* - new_entity: The newer entity.
* - view_mode: The view mode to use. Defaults to FALSE. If no view mode is
* given, the recommended fallback view mode is 'default'.
* - states: An array of view states. These could be one of:
* - raw: The raw value of the diff, the classic 7.x-2.x view.
* - rendered: The rendered HTML as determined by the view mode. Only
* return markup for this state if the value is normally shown
* by this view mode. The user will most likely be able to see
* the raw or raw_plain state, so this is optional.
*
* The rendering state is a work in progress.
*
* Conditionally, you can get these states, but setting these will override
* the user selectable markdown method.
*
* - raw_plain: As raw, but text should be markdowned.
* - rendered_plain: As rendered, but text should be markdowned.
*
* @return array
* An associative array of values keyed by the entity property.
*
* This is effectively an unnested Form API-like structure.
*
* States are returned as follows:
*
* $results['line'] = array(
* '#name' => t('Line'),
* '#states' => array(
* 'raw' => array(
* '#old' => '<p class="line">This was the old line number [tag].</p>',
* '#new' => '<p class="line">This is the new line [tag].</p>',
* ),
* 'rendered' => array(
* '#old' => '<p class="line">This was the old line number <span class="line-number">57</span>.</p>',
* '#new' => '<p class="line">This is the new line <span class="line-number">57</span>.</p>',
* ),
* ),
* );
*
* For backwards compatability, no changes are required to support states,
* but it is recommended to provide a better UI for end users.
*
* For example, the following example is equivalent to returning the raw
* state from the example above.
*
* $results['line'] = array(
* '#name' => t('Line'),
* '#old' => '<p class="line">This was the old line number [tag].</p>',
* '#new' => '<p class="line">This is the new line [tag].</p>',
* );
* Private callback function to render the title field.
*/
function node_entity_diff($old_node, $new_node, $context) {
$result = array();
if ($context['entity_type'] == 'node') {
$type = node_type_get_type($new_node);
$result['title'] = array(
'#name' => $type->title_label,
'#states' => array(),
'#weight' => -5,
'#settings' => array(
// Global setting - 'diff_show_header_' . $entity_type
'show_header' => variable_get('diff_show_header_node', 1),
),
);
foreach ($context['states'] as $state) {
switch ($state) {
case 'rendered':
$result['title']['#states'][$state] = array(
'#old' => l($old_node->title, 'node/' . $old_node->title),
'#new' => l($new_node->title, 'node/' . $new_node->title),
);
break;
function _node_entity_diff_additional_options_title($old_node, $new_node, $context) {
$type = node_type_get_type($new_node);
$row = array(
'#name' => $type->title_label,
'#states' => array(),
'#weight' => -5,
'#settings' => array(
'show_header' => variable_get('diff_show_header_node', 1),
),
);
foreach ($context['states'] as $state) {
switch ($state) {
case 'rendered':
$row['#states'][$state] = array(
'#old' => l($old_node->title, 'node/' . $old_node->title),
'#new' => l($new_node->title, 'node/' . $new_node->title),
);
break;
// We specify a default so that the title is allows compared.
case 'raw':
default:
$result['title']['#states'][$state] = array(
'#old' => array($old_node->title),
'#new' => array($new_node->title),
);
break;
}
// We specify a default so that the title is allows compared.
case 'raw':
default:
$row['#states'][$state] = array(
'#old' => array($old_node->title),
'#new' => array($new_node->title),
);
break;
}
}
return $result;
return $row;
}
/**
* Private callback function to render the type field.
*/
function _node_entity_diff_additional_options_type($old_node, $new_node, $context) {
$row = array(
'#name' => t('Content type'),
'#states' => array(),
'#weight' => -4,
'#settings' => array(),
);
$old_type = node_type_get_type($old_node);
$new_type = node_type_get_type($new_node);
foreach ($context['states'] as $state) {
$row['#states'][$state] = array(
'#old' => array($old_type ? $old_type->name : t('Deleted type !type', array('!type' => $old_node->type))),
'#new' => array($new_type ? $new_type->name : t('Deleted type !type', array('!type' => $new_node->type))),
);
}
return $row;
}
/**
* Private callback function to render the author field.
*/
function _node_entity_diff_additional_options_author($old_node, $new_node, $context) {
$old_author = user_load($old_node->uid);
$new_author = user_load($new_node->uid);
return _node_entity_diff_additional_options_account(t('Author'), $old_author, $new_author, $context, -4);
}
/**
* Private callback function to render the revision_author field.
*/
function _node_entity_diff_additional_options_revision_author($old_node, $new_node, $context) {
$old_author = user_load($old_node->revision_uid);
$new_author = user_load($new_node->revision_uid);
return _node_entity_diff_additional_options_account(t('Revision author'), $old_author, $new_author, $context, -3.9);
}
/**
* Private callback function to render the author field.
*/
function _node_entity_diff_additional_options_account($label, $old_author, $new_author, $context, $weight = 0) {
$row = array(
'#name' => $label,
'#states' => array(),
'#weight' => $weight,
'#settings' => array(),
);
foreach ($context['states'] as $state) {
$row['#states'][$state] = array(
'#old' => array($old_author ? format_username($old_author) : t('Deleted user')),
'#new' => array($new_author ? format_username($new_author) : t('Deleted user')),
);
}
return $row;
}
/**
* Private callback function to render the status, sticky and published field.
*/
function _node_entity_diff_additional_options_publishing_flags($old_node, $new_node, $context) {
$row = array(
'#name' => t('Publishing options'),
'#states' => array(),
'#weight' => -3,
'#settings' => array(),
);
$old_options = array($old_node->status ? t('Published') : t('Unpublished'));
if ($old_node->promote) {
$old_options[] = t('Promoted to front page');
}
if ($old_node->sticky) {
$old_options[] = t('Sticky at top of lists');
}
$new_options = array($new_node->status ? t('Published') : t('Unpublished'));
if ($new_node->promote) {
$new_options[] = t('Promoted to front page');
}
if ($new_node->sticky) {
$new_options[] = t('Sticky at top of lists');
}
foreach ($context['states'] as $state) {
$row['#states'][$state] = array(
'#old' => $old_options,
'#new' => $new_options,
);
}
return $row;
}
/**
* Private callback function to render the created field.
*/
function _node_entity_diff_additional_options_created($old_node, $new_node, $context) {
return _node_entity_diff_additional_options_date_field(t('Created timestamp'), $old_node->created, $new_node->created, $context, -1);
}
/**
* Private callback function to render the changed field.
*/
function _node_entity_diff_additional_options_changed($old_node, $new_node, $context) {
return _node_entity_diff_additional_options_date_field(t('Changed timestamp'), $old_node->changed, $new_node->changed, $context, -1);
}
/**
* Private callback function to render the revision_timestamp field.
*/
function _node_entity_diff_additional_options_revision_timestamp($old_node, $new_node, $context) {
return _node_entity_diff_additional_options_date_field(t('Revision timestamp'), $old_node->revision_timestamp, $new_node->revision_timestamp, $context, -1);
}
/**
* Helper function to render the date flags.
*/
function _node_entity_diff_additional_options_date_field($label, $old_date, $new_date, $context, $weight = 0) {
$row = array(
'#name' => $label,
'#states' => array(),
'#weight' => $weight,
'#settings' => array(),
);
foreach ($context['states'] as $state) {
$row['#states'][$state] = array(
'#old' => array(format_date($old_date)),
'#new' => array(format_date($new_date)),
);
}
return $row;
}
/**
* Private callback function to render the comment field.
*/
function _node_entity_diff_additional_options_comment($old_node, $new_node, $context) {
if (!module_exists('comment')) {
return array();
}
$row = array(
'#name' => t('Comment setting'),
'#states' => array(),
'#weight' => -1,
'#settings' => array(),
);
$options = array(
COMMENT_NODE_OPEN => t('Open'),
COMMENT_NODE_CLOSED => t('Closed'),
COMMENT_NODE_HIDDEN => t('Hidden'),
);
foreach ($context['states'] as $state) {
$row['#states'][$state] = array(
'#old' => array($options[$old_node->comment]),
'#new' => array($options[$new_node->comment]),
);
}
return $row;
}

View File

@@ -0,0 +1,148 @@
<?php
/**
* @file
* Provide diff functions for the user module.
*
* Note as users do not have revisions enabled, most use cases for comparisons
* will be between two different users.
*/
/**
* Private callback function to render the name field.
*/
function _user_entity_diff_additional_options_name($old_user, $new_user, $context) {
$row = array(
'#name' => t('Username'),
'#states' => array(),
'#weight' => -5,
'#settings' => array(
'show_header' => variable_get('diff_show_header_user', 1),
),
);
foreach ($context['states'] as $state) {
switch ($state) {
case 'rendered':
$row['#states'][$state] = array(
'#old' => theme('username', array('account' => $old_user)),
'#new' => theme('username', array('account' => $old_user)),
);
break;
// We specify a default so that the name is always compared.
case 'raw':
default:
$row['#states'][$state] = array(
'#old' => array($old_user->name),
'#new' => array($new_user->name),
);
break;
}
}
return $row;
}
/**
* Private callback function to render the mail field.
*/
function _user_entity_diff_additional_options_mail($old_user, $new_user, $context) {
$row = array(
'#name' => t('E-mail address'),
'#states' => array(),
'#weight' => -4,
'#settings' => array(),
);
foreach ($context['states'] as $state) {
$row['#states'][$state] = array(
'#old' => array($old_user->mail),
'#new' => array($new_user->mail),
);
}
return $row;
}
/**
* Private callback function to render the status field.
*/
function _user_entity_diff_additional_options_status($old_user, $new_user, $context) {
$row = array(
'#name' => t('Status'),
'#states' => array(),
'#weight' => -3,
'#settings' => array(),
);
foreach ($context['states'] as $state) {
$row['#states'][$state] = array(
'#old' => array($old_user->status ? t('Active') : t('Blocked')),
'#new' => array($new_user->status ? t('Active') : t('Blocked')),
);
}
return $row;
}
/**
* Private callback function to render the timezone field.
*/
function _user_entity_diff_additional_options_timezone($old_user, $new_user, $context) {
$row = array(
'#name' => t('Time zone'),
'#states' => array(),
'#weight' => -1,
'#settings' => array(),
);
$system_time_zones = system_time_zones(TRUE);
$old_zone = isset($old_user->timezone) ? $old_user->timezone : '';
$new_zone = isset($new_user->timezone) ? $new_user->timezone : '';
foreach ($context['states'] as $state) {
$row['#states'][$state] = array(
'#old' => array(isset($system_time_zones[$old_zone]) ? $system_time_zones[$old_zone] : t('- None selected -')),
'#new' => array(isset($system_time_zones[$new_zone]) ? $system_time_zones[$new_zone] : t('- None selected -')),
);
}
return $row;
}
/**
* Private callback function to render the password field.
*/
function _user_entity_diff_additional_options_password($old_user, $new_user, $context) {
$row = array(
'#name' => t('Password Hash'),
'#states' => array(),
'#weight' => -1,
'#settings' => array(),
);
foreach ($context['states'] as $state) {
$row['#states'][$state] = array(
'#old' => array($old_user->pass),
'#new' => array($new_user->pass),
);
}
return $row;
}
/**
* Private callback function to render the roles field.
*/
function _user_entity_diff_additional_options_roles($old_user, $new_user, $context) {
$row = array(
'#name' => t('Roles'),
'#states' => array(),
'#weight' => -1,
'#settings' => array(),
);
$roles = user_roles(TRUE);
unset($roles[DRUPAL_AUTHENTICATED_RID]);
foreach ($context['states'] as $state) {
$row['#states'][$state] = array(
'#old' => array(implode("\n", array_intersect_key($roles, $old_user->roles))),
'#new' => array(implode("\n", array_intersect_key($roles, $new_user->roles))),
);
}
return $row;
}