more module updates
This commit is contained in:
@@ -17,4 +17,4 @@
|
||||
.cck-phone-settings .cck-phone-default-country {
|
||||
background: #eee;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Implements Feeds mapping API
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_feeds_processor_targets_alter().
|
||||
*/
|
||||
function cck_phone_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
|
||||
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
|
||||
$info = field_info_field($name);
|
||||
if ($info['type'] == 'phone_number') {
|
||||
$targets[$name .':country_codes'] = array(
|
||||
'name' => t('!label - country code', array('!label' => check_plain($instance['label']))),
|
||||
'callback' => 'cck_phone_feeds_set_target',
|
||||
'description' => t('The @label field.', array('@label' => $instance['label'])),
|
||||
);
|
||||
$targets[$name .':number'] = array(
|
||||
'name' => t('!label - phone number', array('!label' => check_plain($instance['label']))),
|
||||
'callback' => 'cck_phone_feeds_set_target',
|
||||
'description' => t('The @label field.', array('@label' => $instance['label'])),
|
||||
);
|
||||
$targets[$name .':extension'] = array(
|
||||
'name' => t('!label - extension', array('!label' => check_plain($instance['label']))),
|
||||
'callback' => 'cck_phone_feeds_set_target',
|
||||
'description' => t('The @label field.', array('@label' => $instance['label'])),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for feed mapping.
|
||||
*/
|
||||
function cck_phone_feeds_set_target($source, $entity, $target, $value) {
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle non-multiple value fields.
|
||||
if (!is_array($value)) {
|
||||
$value = array($value);
|
||||
}
|
||||
|
||||
// Iterate over all values.
|
||||
$i = 0;
|
||||
$info = field_info_field($target);
|
||||
list($field_name, $sub_field) = explode(':', $target);
|
||||
|
||||
// We will call this multiple times, preserve existing values.
|
||||
$field = empty($entity->{$field_name}) ? array() : $entity->{$field_name};
|
||||
|
||||
foreach ($value as $v) {
|
||||
if ($sub_field == 'country_codes') {
|
||||
$v = strtolower($v);
|
||||
}
|
||||
if (!is_array($v) && !is_object($v)) {
|
||||
$field['und'][$i][$sub_field] = $v;
|
||||
}
|
||||
if ($info['cardinality'] == 1) {
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$entity->{$field_name} = $field;
|
||||
}
|
@@ -15,9 +15,9 @@ files[] = includes/phone.my.inc
|
||||
files[] = includes/phone.pl.inc
|
||||
files[] = includes/phone.us.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-03-02
|
||||
; Information added by packaging script on 2013-11-05
|
||||
version = "7.x-1.x-dev"
|
||||
core = "7.x"
|
||||
project = "cck_phone"
|
||||
datestamp = "1330689918"
|
||||
datestamp = "1383621212"
|
||||
|
||||
|
@@ -97,4 +97,4 @@
|
||||
$('a.cck-phone-check').bind('click', Drupal.PhoneNumber.checkall);
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
||||
})(jQuery);
|
||||
|
@@ -34,7 +34,7 @@ function cck_phone_theme() {
|
||||
'render element' => 'element',
|
||||
),
|
||||
'phone_number_extension' => array(
|
||||
'render element' => 'element',
|
||||
'variables' => array('extension' => NULL),
|
||||
),
|
||||
'cck_phone_formatter_global_phone_number' => array(
|
||||
'variables' => array('element' => NULL),
|
||||
@@ -65,10 +65,68 @@ function cck_phone_field_info() {
|
||||
),
|
||||
'default_widget' => 'phone_number',
|
||||
'default_formatter' => 'global_phone_number',
|
||||
// Support hook_entity_property_info() from contrib "Entity API".
|
||||
'property_type' => 'field_item_phone_number',
|
||||
'property_callbacks' => array('cck_phone_field_property_info_callback'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional callback to adapt the property info of phone number fields.
|
||||
* @see entity_metadata_field_entity_property_info().
|
||||
*/
|
||||
function cck_phone_field_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) {
|
||||
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];
|
||||
|
||||
// Define a data structure so it's possible constituent parts of field.
|
||||
$property['getter callback'] = 'entity_metadata_field_verbatim_get';
|
||||
$property['setter callback'] = 'entity_metadata_field_verbatim_set';
|
||||
|
||||
// Auto-create the field item as soon as a property is set.
|
||||
$property['auto creation'] = 'cck_phone_field_item_create';
|
||||
|
||||
$property['property info'] = cck_phone_field_item_property_info();
|
||||
$property['property info']['country_codes']['required'] = !$instance['settings']['enable_default_country'];
|
||||
if (!$instance['settings']['enable_extension']) {
|
||||
unset($property['property info']['extension']);
|
||||
}
|
||||
|
||||
unset($property['query callback']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for creating a new, empty phone number field item.
|
||||
*
|
||||
* @see cck_phone_field_property_info_callback()
|
||||
*/
|
||||
function cck_phone_field_item_create() {
|
||||
return array('number' => NULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines info for the properties of the phone number field item data structure.
|
||||
*/
|
||||
function cck_phone_field_item_property_info() {
|
||||
$properties['number'] = array(
|
||||
'type' => 'text',
|
||||
'label' => t('The phone number.'),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
);
|
||||
$properties['country_codes'] = array(
|
||||
'type' => 'text',
|
||||
'label' => t('The country code for a given phone number.'),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
);
|
||||
$properties['extension'] = array(
|
||||
'type' => 'text',
|
||||
'label' => t('The extension for a given phone number.'),
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
);
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_instance_settings_form().
|
||||
*/
|
||||
@@ -255,8 +313,8 @@ function cck_phone_field_is_empty($item, $field) {
|
||||
/**
|
||||
* Theme function for phone extension.
|
||||
*/
|
||||
function theme_phone_number_extension($element = '') {
|
||||
return t('<em> ext.</em> %extension', array('%extension' => $element['element']));
|
||||
function theme_phone_number_extension($variables) {
|
||||
return '<em>' . t('ext.') . '</em> ' . check_plain($variables['extension']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,7 +325,7 @@ function theme_cck_phone_formatter_global_phone_number($element) {
|
||||
|
||||
// Display a global phone number with country code.
|
||||
if (!empty($element['number']) && !empty($element['country_codes'])) {
|
||||
// Call country default formatter if exist
|
||||
// Call country default formatter if exists.
|
||||
$custom_cc = _cck_phone_custom_cc();
|
||||
if (isset($custom_cc[$element['country_codes']])) {
|
||||
$function = $element['country_codes'] . '_formatter_default';
|
||||
@@ -276,15 +334,16 @@ function theme_cck_phone_formatter_global_phone_number($element) {
|
||||
}
|
||||
}
|
||||
|
||||
// Output a raw value if no custom formatter or formatter return empty
|
||||
// Output a raw value if no custom formatter or formatter returns empty
|
||||
// value.
|
||||
if (empty($phone)) {
|
||||
$cc = cck_phone_countrycodes($element['country_codes']);
|
||||
$phone = $cc['code'] . '-' . $element['number'];
|
||||
}
|
||||
|
||||
// Extension
|
||||
// Extension.
|
||||
if (!empty($element['extension'])) {
|
||||
$phone = $phone . theme('phone_number_extension', $element['extension']);
|
||||
$phone = $phone . theme('phone_number_extension', $element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +358,7 @@ function theme_cck_phone_formatter_local_phone_number($element) {
|
||||
|
||||
// Display a local phone number without country code.
|
||||
if (!empty($element['number'])) {
|
||||
// Call country local formatter if exist
|
||||
// Call country local formatter if exists.
|
||||
$custom_cc = _cck_phone_custom_cc();
|
||||
if (isset($custom_cc[$element['country_codes']])) {
|
||||
$function = $element['country_codes'] . '_formatter_local';
|
||||
@@ -308,14 +367,14 @@ function theme_cck_phone_formatter_local_phone_number($element) {
|
||||
}
|
||||
}
|
||||
|
||||
// Output a raw value if no custom formatter or formatter return empty
|
||||
// Output a raw value if no custom formatter or formatter return empty.
|
||||
if (empty($phone)) {
|
||||
$phone = $element['number'];
|
||||
}
|
||||
|
||||
// Extension
|
||||
// Extension.
|
||||
if (!empty($element['extension'])) {
|
||||
$phone = $phone . theme('phone_number_extension', $element['extension']);
|
||||
$phone = $phone . theme('phone_number_extension', $element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,6 +411,7 @@ function _cck_phone_cc_options($show_custom = FALSE, $country_selection = array(
|
||||
$options[$cc] = check_plain($cc_name);
|
||||
}
|
||||
|
||||
asort($options);
|
||||
return $options;
|
||||
}
|
||||
|
||||
@@ -632,6 +692,9 @@ function cck_phone_field_widget_process($element, &$form_state, $form) {
|
||||
'#required' => FALSE,
|
||||
'#default_value' => isset($item['extension']) ? $item['extension'] : NULL,
|
||||
'#weight' => 2,
|
||||
'#attributes' => array(
|
||||
'class' => array('extension'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -688,6 +751,9 @@ function cck_phone_phone_number_process($element, &$form_state, $form) {
|
||||
)
|
||||
),
|
||||
'#weight' => 0,
|
||||
'#attributes' => array(
|
||||
'class' => array('phone-number'),
|
||||
),
|
||||
);
|
||||
|
||||
// If only one country code, make it as hidden form item
|
||||
@@ -705,6 +771,9 @@ function cck_phone_phone_number_process($element, &$form_state, $form) {
|
||||
'#type' => 'item',
|
||||
'#markup' => $value = $cc['country'] . ' (' . $cc['code'] . ')',
|
||||
'#weight' => ($settings['country_code_position'] == 'after' ? 1 : -1),
|
||||
'#attributes' => array(
|
||||
'class' => array('country-code'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -716,6 +785,9 @@ function cck_phone_phone_number_process($element, &$form_state, $form) {
|
||||
// '#title' => 'Country code',
|
||||
'#options' => _cck_phone_cc_options(),
|
||||
'#weight' => ($settings['country_code_position'] == 'after' ? 1 : -1),
|
||||
'#attributes' => array(
|
||||
'class' => array('country-code'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -266,4 +266,4 @@ function cck_phone_countrycodes($cc = NULL) {
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user