Skip to content

Commit

Permalink
Updated token: 7.x-1.4 → 7.x-1.5. Updated twitter_username: 7.x-1.2 →…
Browse files Browse the repository at this point in the history
… 7.x-1.3
  • Loading branch information
carwin committed Mar 7, 2013
1 parent 66f7b56 commit 6956109
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 40 deletions.
6 changes: 3 additions & 3 deletions docroot/sites/all/modules/contrib/token/tests/token_test.info
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ core = 7.x
files[] = token_test.module
hidden = TRUE

; Information added by drupal.org packaging script on 2012-09-24
version = "7.x-1.4"
; Information added by drupal.org packaging script on 2013-02-24
version = "7.x-1.5"
core = "7.x"
project = "token"
datestamp = "1348497279"
datestamp = "1361665026"

22 changes: 22 additions & 0 deletions docroot/sites/all/modules/contrib/token/token.drush.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* @file
* Drush integration for the Token module.
*/

/**
* Implements hook_drush_cache_clear().
*/
function token_drush_cache_clear(&$types) {
if (function_exists('module_exists') && module_exists('token')) {
$types['token'] = 'drush_token_cache_clear_token_info';
}
}

/**
* Clear caches internal to Token module.
*/
function drush_token_cache_clear_token_info() {
token_clear_cache();
}
10 changes: 3 additions & 7 deletions docroot/sites/all/modules/contrib/token/token.info
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
name = Token
description = Provides a user interface for the Token API and some missing core tokens.
core = 7.x
files[] = token.module
files[] = token.install
files[] = token.tokens.inc
files[] = token.pages.inc
files[] = token.test

; Information added by drupal.org packaging script on 2012-09-24
version = "7.x-1.4"
; Information added by drupal.org packaging script on 2013-02-24
version = "7.x-1.5"
core = "7.x"
project = "token"
datestamp = "1348497279"
datestamp = "1361665026"

8 changes: 7 additions & 1 deletion docroot/sites/all/modules/contrib/token/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Drupal.behaviors.tokenDialog = {
$('a.token-dialog', context).once('token-dialog').click(function() {
var url = $(this).attr('href');
var dialog = $('<div style="display: none" class="loading">' + Drupal.t('Loading token browser...') + '</div>').appendTo('body');

// Emulate the AJAX data sent normally so that we get the same theme.
var data = {};
data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme;
data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token;

dialog.dialog({
title: $(this).attr('title') || Drupal.t('Available tokens'),
width: 700,
Expand All @@ -24,7 +30,7 @@ Drupal.behaviors.tokenDialog = {
// Load the token tree using AJAX.
dialog.load(
url,
{},
data,
function (responseText, textStatus, XMLHttpRequest) {
dialog.removeClass('loading');
}
Expand Down
36 changes: 23 additions & 13 deletions docroot/sites/all/modules/contrib/token/token.module
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function token_menu() {
'access callback' => TRUE,
'type' => MENU_CALLBACK,
'file' => 'token.pages.inc',
'theme callback' => 'ajax_base_page_theme',
);

// Devel token pages.
Expand Down Expand Up @@ -265,7 +266,7 @@ function token_form_block_admin_configure_alter(&$form, $form_state) {
$form['settings']['title']['#description'] .= ' ' . t('This field supports tokens.');
// @todo Figure out why this token validation does not seem to be working here.
$form['settings']['title']['#element_validate'][] = 'token_element_validate';
$form['settings']['title']['#token_types'] = array();
$form['settings']['title'] += array('#token_types' => array());
}

/**
Expand Down Expand Up @@ -377,23 +378,26 @@ function token_clear_cache() {
* @see token_entity_info_alter()
* @see http://drupal.org/node/737726
*/
function token_get_entity_mapping($value_type = 'token', $value = NULL) {
function token_get_entity_mapping($value_type = 'token', $value = NULL, $fallback = FALSE) {
$mapping = &drupal_static(__FUNCTION__, array());

if (empty($mapping)) {
foreach (entity_get_info() as $entity_type => $info) {
$mapping[$entity_type] = !empty($info['token type']) ? $info['token type'] : $entity_type;
}
// Allow modules to alter the mapping array.
drupal_alter('token_entity_mapping', $mapping);
}

if (!isset($value)) {
return $mapping;
return $value_type == 'token' ? array_flip($mapping) : $mapping;
}
elseif ($value_type == 'token') {
return array_search($value, $mapping);
$return = array_search($value, $mapping);
return $return !== FALSE ? $return : ($fallback ? $value : FALSE);
}
elseif ($value_type == 'entity') {
return isset($mapping[$value]) ? $mapping[$value] : FALSE;
return isset($mapping[$value]) ? $mapping[$value] : ($fallback ? $value : FALSE);
}
}

Expand Down Expand Up @@ -739,24 +743,28 @@ function token_element_validate_token_context(&$element, &$form_state) {
* Implements hook_form_FORM_ID_alter().
*/
function token_form_field_ui_field_edit_form_alter(&$form, $form_state) {
if (!isset($form['instance'])) {
if (!isset($form['instance']) || !empty($form['#field']['locked'])) {
return;
}

if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !module_exists('filefield_paths')) {
// GAH! We can only support global tokens in the upload file directory path.
$form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate';
$form['instance']['settings']['file_directory']['#token_types'] = array();
$form['instance']['settings']['token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => array(),
'#weight' => $form['instance']['settings']['file_directory']['#weight'] + 0.5,
);
$form['instance']['settings']['file_directory'] += array('#token_types' => array());
$form['instance']['settings']['file_directory']['#description'] .= ' ' . t('This field supports tokens.');
}

// Note that the description is tokenized via token_field_widget_form_alter().
$form['instance']['description']['#description'] .= '<br />' . t('This field supports tokens.');
$form['instance']['description']['#element_validate'][] = 'token_element_validate';
$form['instance']['description'] += array('#token_types' => array());

$form['instance']['settings']['token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => array(),
'#dialog' => TRUE,
'#weight' => $form['instance']['description']['#weight'] + 0.5,
);
}

/**
Expand All @@ -775,6 +783,7 @@ function token_form_system_actions_configure_alter(&$form, $form_state) {
$form['token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => 'all',
'#dialog' => TRUE,
'#weight' => 100,
);
// @todo Add token validation to the action fields that can use tokens.
Expand Down Expand Up @@ -836,10 +845,11 @@ function token_form_user_admin_settings_alter(&$form, &$form_state) {
}

// Add the token tree UI.
$form['token_tree'] = array(
$form['email']['token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => array('user'),
'#show_restricted' => TRUE,
'#dialog' => TRUE,
'#weight' => 90,
);
}
Expand Down
9 changes: 6 additions & 3 deletions docroot/sites/all/modules/contrib/token/token.pages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function token_page_output_tree() {
$options['dialog'] = FALSE;

$output = theme('token_tree', $options);
print '<html><head><title></title>' . drupal_get_css() . drupal_get_js() . '</head>';
print '<html><head>' . drupal_get_css() . drupal_get_js() . '</head>';
print '<body class="token-tree">' . $output . '</body></html>';
drupal_exit();
}
Expand Down Expand Up @@ -231,7 +231,7 @@ function _token_clean_css_identifier($id) {
/**
* Menu callback; prints the available tokens and values for an object.
*/
function token_devel_token_object($entity_type, $entity) {
function token_devel_token_object($entity_type, $entity, $token_type = NULL) {
$header = array(
t('Token'),
t('Value'),
Expand All @@ -243,7 +243,10 @@ function token_devel_token_object($entity_type, $entity) {
'values' => TRUE,
'data' => array($entity_type => $entity),
);
$tree = token_build_tree($entity_type, $options);
if (!isset($token_type)) {
$token_type = $entity_type;
}
$tree = token_build_tree($token_type, $options);
foreach ($tree as $token => $token_info) {
if (!empty($token_info['restricted'])) {
continue;
Expand Down
2 changes: 2 additions & 0 deletions docroot/sites/all/modules/contrib/token/token.test
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,12 @@ class TokenEntityTestCase extends TokenTestHelper {
$this->assertIdentical(token_get_entity_mapping('token', 'term'), 'taxonomy_term');
$this->assertIdentical(token_get_entity_mapping('token', 'vocabulary'), 'taxonomy_vocabulary');
$this->assertIdentical(token_get_entity_mapping('token', 'invalid'), FALSE);
$this->assertIdentical(token_get_entity_mapping('token', 'invalid', TRUE), 'invalid');
$this->assertIdentical(token_get_entity_mapping('entity', 'node'), 'node');
$this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_term'), 'term');
$this->assertIdentical(token_get_entity_mapping('entity', 'taxonomy_vocabulary'), 'vocabulary');
$this->assertIdentical(token_get_entity_mapping('entity', 'invalid'), FALSE);
$this->assertIdentical(token_get_entity_mapping('entity', 'invalid', TRUE), 'invalid');

// Test that when we send the mis-matched entity type into token_replace()
// that we still get the tokens replaced.
Expand Down
2 changes: 1 addition & 1 deletion docroot/sites/all/modules/contrib/token/token.tokens.inc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function token_token_info_alter(&$info) {
foreach ($date_format_types as $date_format_type => $date_format_type_info) {
if (!isset($info['tokens']['date'][$date_format_type])) {
$info['tokens']['date'][$date_format_type] = array(
'name' => $date_format_type_info['title'],
'name' => check_plain($date_format_type_info['title']),
'description' => t("A date in '@type' format. (%date)", array('@type' => $date_format_type, '%date' => format_date(REQUEST_TIME, $date_format_type))),
'module' => 'token',
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ description = Defines simple field for handling twitter username (ex: user profi
core = 7.x
package = Fields

; Information added by drupal.org packaging script on 2012-10-13
version = "7.x-1.2"
; Information added by drupal.org packaging script on 2013-03-02
version = "7.x-1.3"
core = "7.x"
project = "twitter_username"
datestamp = "1350126411"
datestamp = "1362226514"

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,40 @@ function twitter_username_field_schema($field) {
),
);
}


/**
* Update formatter machine_name to avoid conflict
*/
function twitter_username_update_7001() {
// Get twitter_username fields
$twitter_username_fields = array();
foreach (field_info_fields() as $field_name => $field) {
if ($field['type'] == 'twitter_username') {
$twitter_username_fields[$field_name] = $field;
}
}

// Loop throught instances / bundles / fields
foreach (field_info_instances() as $entity_type => $bundles) {
foreach ($bundles as $bundle_name => $fields) {
foreach($fields as $field_name => $field_instance) {
// If the field type is twitter_username
if (isset($twitter_username_fields[$field_name])) {
// Loop through view_mode
$need_update = FALSE;
foreach($field_instance['display'] as $view_mode => $display) {
// If formatter is defined by twitter_username, update instance
if ($display['type'] == 'default' || $display['type'] == 'link') {
$need_update = TRUE;
$field_instance['display'][$view_mode]['type'] = 'twitter_username_' . $display['type'];
}
}
if ($need_update) {
field_update_instance($field_instance);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ function twitter_username_field_validate($entity_type, $entity, $field, $instanc
}
// Ensure the username is actually registered.
elseif ($instance['settings']['validate_existance']) {
// Query the Twitter API.
$url = url('http://api.twitter.com/1/users/show.xml', array('external' => TRUE, 'query' => array('screen_name' => $item['twitter_username'])));
$response = drupal_http_request($url);
// Query the Twitter User page.
// Since v1.1, we could not request the API with OAuth token.
$url = url(
'https://twitter.com/' .$item['twitter_username'],
array('external' => TRUE)
);
$response = drupal_http_request($url, array('method'=>'HEAD'));

// HTTP status code 404 means the username doesn't exist.
if ($response->code == 404) {
Expand Down Expand Up @@ -150,11 +154,11 @@ function twitter_username_field_instance_settings_form($field, $instance) {
*/
function twitter_username_field_formatter_info() {
return array(
'default' => array(
'twitter_username_default' => array(
'label' => t("Twitter username, as plain text"),
'field types' => array('twitter_username'),
),
'link' => array(
'twitter_username_link' => array(
'label' => t("Twitter username, as link"),
'field types' => array('twitter_username'),
),
Expand All @@ -178,21 +182,21 @@ function twitter_username_field_formatter_view($entity_type, $entity, $field, $i
*/
function twitter_username_theme() {
return array(
'twitter_username_formatter_default' => array(
'twitter_username_formatter_twitter_username_default' => array(
'variables' => array('element' => NULL),
),
'twitter_username_formatter_link' => array(
'twitter_username_formatter_twitter_username_link' => array(
'variables' => array('element' => NULL),
),
);
}

function theme_twitter_username_formatter_default($vars) {
function theme_twitter_username_formatter_twitter_username_default($vars) {
$twitter_username = check_plain($vars['element']['twitter_username']);
return "@" . $twitter_username;
}

function theme_twitter_username_formatter_link($vars) {
function theme_twitter_username_formatter_twitter_username_link($vars) {
$twitter_username = check_plain($vars['element']['twitter_username']);
return l("@" . $twitter_username, 'http://twitter.com/' . $twitter_username);
}
Expand Down

0 comments on commit 6956109

Please sign in to comment.