first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View File

@@ -0,0 +1,29 @@
<?php
/**
* @file
* API documentation for Addressfield.
*/
/**
* Format generation callback.
*
* @param $format
* The address format being generated.
* @param $address
* The address this format is generated for.
* @param $context
* An array of context arguments:
* - 'mode': can be either 'form' or 'render'
* - (optional) 'field': when generated for a field, the field
* - (optional) 'instance': when generated for a field, the field instance
* - (optional) 'langcode': when generated for a field, the langcode
* this field is being rendered in.
* - (optional) 'delta': when generated for a field, the delta of the
* currently handled address.
*
* @ingroup addressfield_format
*/
function CALLBACK_addressfield_format_callback(&$format, $address, $context = array()) {
}

View File

@@ -0,0 +1,26 @@
.addressfield-container-inline > div.form-item {
float: left;
margin-right: 1em;
}
.addressfield-container-inline.country-GB > div.form-item {
float: none;
margin-right: auto;
}
/* Clear-fix markup for the inline container */
.addressfield-container-inline:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
/* IE6 */
* html .addressfield-container-inline {
height: 1%;
}
/* IE7 */
*:first-child + html .addressfield-container-inline {
min-height: 1%;
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* @file
* Integration with the Feeds module.
*/
/**
* Implements hook_feeds_node_processor_targets_alter().
*/
function addressfield_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'] == 'addressfield') {
foreach ($info['columns'] as $sub_field => $schema_info) {
$name_label = $instance['label'] . ': ' . drupal_ucfirst(str_replace('_', ' ', $sub_field));
$targets[$name . ':' . $sub_field] = array(
'name' => $name_label,
'callback' => 'addressfield_set_target',
'real_target' => $info['field_name'],
'description' => $schema_info['description'],
);
}
}
}
}
/**
* Callback for hook_feeds_processor_targets_alter().
*
* @param $source
* Field mapper source settings.
* @param $entity
* An entity object, for instance a node object.
* @param $target
* A string identifying the target on the node.
* @param $value
* The value to populate the target with.
*/
function addressfield_set_target($source, $entity, $target, $value) {
list($field_name, $sub_field) = explode(':', $target, 2);
// Handle non-multiple value fields.
if (!is_array($value)) {
$value = array($value);
}
$field = isset($entity->$field_name) ? $entity->$field_name : array();
foreach ($value as $i => $v) {
$field['und'][$i][$sub_field] = $v;
}
$entity->$field_name = $field;
}

View File

@@ -0,0 +1,15 @@
name = Address Field
description = Manage a flexible address field, implementing the xNAL standard.
core = 7.x
package = Fields
dependencies[] = ctools
files[] = views/addressfield_views_handler_filter_country.inc
; Information added by drupal.org packaging script on 2012-05-29
version = "7.x-1.0-beta3"
core = "7.x"
project = "addressfield"
datestamp = "1338304248"

View File

@@ -0,0 +1,186 @@
<?php
/**
* Implements hook_field_schema()
*/
function addressfield_field_schema() {
$columns = array(
'country' => array(
'description' => 'Two letter ISO country code of this address.',
'type' => 'varchar',
'length' => 2,
'not null' => FALSE,
'default' => '',
),
'administrative_area' => array(
'description' => 'The administrative area of this address. (i.e. State/Province)',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'sub_administrative_area' => array(
'description' => 'The sub administrative area of this address.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'locality' => array(
'description' => 'The locality of this address. (i.e. City)',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'dependent_locality' => array(
'description' => 'The dependent locality of this address.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'postal_code' => array(
'description' => 'The postal code of this address.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'thoroughfare' => array(
'description' => 'The thoroughfare of this address. (i.e. Street address)',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'premise' => array(
'description' => 'The premise of this address. (i.e. Apartment / Suite number)',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'sub_premise' => array(
'description' => 'The sub_premise of this address.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'organisation_name' => array(
'description' => 'Contents of a primary OrganisationName element in the xNL XML.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'name_line' => array(
'description' => 'Contents of a primary NameLine element in the xNL XML.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'first_name' => array(
'description' => 'Contents of the FirstName element of a primary PersonName element in the xNL XML.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'last_name' => array(
'description' => 'Contents of the LastName element of a primary PersonName element in the xNL XML.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'data' => array(
'description' => 'Additional data for this address.',
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'serialize' => TRUE,
),
);
return array(
'columns' => $columns,
// TODO Add indexes.
);
}
/**
* Update the field configuration to the new plugin structure.
*/
function addressfield_update_7000() {
// Enable ctools.
if (!module_enable(array('ctools'))) {
throw new Exception('This version of addressfield requires ctools, but it could not be enabled.');
}
// Get the list of fields of type 'addressfield'.
$address_fields = array();
foreach (field_info_fields() as $field_name => $field_info) {
if ($field_info['type'] == 'addressfield') {
$address_fields[$field_name] = $field_name;
}
}
foreach (field_info_instances() as $entity_type => $bundles) {
foreach ($bundles as $bundle_name => $instances) {
foreach (array_intersect_key($instances, $address_fields) as $field_name => $instance) {
$widget_settings = &$instance['widget']['settings'];
if ($instance['widget']['type'] == 'addressfield_standard') {
// Default to use the country-based address widget.
$format_handlers = array('address');
// Map the old 'name_format' setting to the name and organization widgets.
if (in_array($widget_settings['name_format'], array('name_line_organisation', 'first_last_organisation'))) {
$format_handlers[] = 'organisation';
}
if (in_array($widget_settings['name_format'], array('name_line', 'name_line_organisation'))) {
$format_handlers[] = 'name-oneline';
}
else {
$format_handlers[] = 'name-full';
}
unset($widget_settings['name_format']);
$widget_settings['format_handlers'] = $format_handlers;
}
// Update displays.
foreach ($instance['display'] as $view_mode => &$view_mode_info) {
$display_settings = &$view_mode_info['settings'];
if ($view_mode_info['type'] == 'addressfield_default') {
if (isset($widget_settings['format_handlers'])) {
$display_settings['use_widget_handlers'] = 1;
}
else {
// If the widget is non-standard, just use a sane default.
$display_settings['use_widget_handlers'] = 0;
$display_settings['format_handlers'] = array('address', 'name-oneline');
}
}
else if ($view_mode_info['type'] == 'addressfield_name') {
// Migrate the 'addressfield_name' formatter to the new framework.
$view_mode_info['type'] = 'addressfield_default';
// Start from the widget configuration.
$display_settings['use_widget_handlers'] = 0;
$display_settings['format_handlers'] = isset($widget_settings['format_handlers']) ? $widget_settings['format_handlers'] : array('address', 'name-oneline');
if (empty($display_settings['organisation'])) {
$display_settings['format_handlers'] = array_diff( $display_settings['format_handlers'], array('organisation'));
}
unset($display_settings['organisation']);
}
}
field_update_instance($instance);
}
}
}
}

View File

@@ -0,0 +1,747 @@
<?php
/**
* @file
* Defines a field for attaching country-specific addresses to entities.
*/
/**
* Implements hook_ctools_plugin_directory().
*/
function addressfield_ctools_plugin_directory($module, $plugin) {
if ($module == 'addressfield') {
return 'plugins/' . $plugin;
}
}
/**
* Implements hook_ctools_plugin_type().
*/
function addressfield_ctools_plugin_type() {
$plugins['format'] = array(
'load themes' => TRUE,
);
return $plugins;
}
/**
* Implements hook_views_api().
*/
function addressfield_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'addressfield') . '/views',
);
}
/**
* Get the list of format plugins.
*/
function addressfield_format_plugins() {
ctools_include('plugins');
$plugins = ctools_get_plugins('addressfield', 'format');
uasort($plugins, 'ctools_plugin_sort');
return $plugins;
}
/**
* Get the list of format plugins in a format suitable for #options.
*/
function addressfield_format_plugins_options() {
$options = array();
foreach (addressfield_format_plugins() as $widget => $info) {
$options[$widget] = check_plain($info['title']);
}
return $options;
}
/**
* @defgroup addressfield_format Address format API
* @{
* API for generating address forms and display formats.
*
* Addresses forms and display formats are collaboratively generated by one or
* more format handler plugins. An address with a name and a company, for example,
* will be generated by three handlers:
* - 'address' that will generate the country, locality, street blocks
* - 'organisation' that will add the organisation block to the address
* - 'name-full' that will add a first name and last name block to the address
*
* A format handler is a CTools plugin of type 'addressfield' / 'format'. Each
* handler is passed the format in turn, and can add to or modify the format.
*
* The format itself is a renderable array stub. This stub will be transformed
* into either a Form API array suitable for use as part of a form or into a
* renderable array suitable for use with drupal_render(). The following
* modifications are done:
* - when rendering as a form, every element which name (its key in the array)
* is a valid addressfield column (see addressfield_field_schema()), will
* be transformed into a form element, either using a type explicitly
* defined in '#widget_type' or using 'select' if '#options' is set or
* 'textfield' if it is not. In addition, the '#default_value' of every
* field will be populated from the address being edited.
* - when rendering as a formatter, every element which name (its key in the array)
* is a valid addressfield column (see addressfield_field_schema()), will
* be transformed into a renderable element, either using a type explicitly
* defined in '#render_type' or else using 'addressfield_container'. When
* the type is 'addressfield_container' the element will be rendered as
* an HTML element set by '#tag' (default: span).
*/
/**
* Generate a format for a given address.
*
* @param $address
* The address format being generated.
* @param $handlers
* The format handlers to use to generate the format.
* @param $context
* An array of context arguments:
* - 'mode': can be either 'form' or 'render'
* - (optional) 'field': when generated for a field, the field
* - (optional) 'instance': when generated for a field, the field instance
* - (optional) 'langcode': when generated for a field, the langcode
* this field is being rendered in.
* - (optional) 'delta': when generated for a field, the delta of the
* currently handled address.
*
* @return
* A rendered array suitable for use as part of a form (if 'mode' is 'form'),
* or suitable to pass to drupal_render().
*/
function addressfield_generate($address, array $handlers, array $context = array()) {
ctools_include('plugins');
$format = array();
$format['#handlers'] = $handlers;
foreach ($format['#handlers'] as $handler) {
if ($callback = ctools_plugin_load_function('addressfield', 'format', $handler, 'format callback')) {
$callback($format, $address, $context);
}
}
// Store the address in the format, for processing.
$format['#address'] = $address;
// Post-process the format stub, depending on the rendering mode.
if ($context['mode'] == 'form') {
$format['#addressfield'] = TRUE;
$format['#process'][] = 'addressfield_process_format_form';
$format['#required'] = FALSE;
}
else {
$format['#pre_render'][] = 'addressfield_render_address';
}
return $format;
}
/**
* Generate a full-fledged form from a format snippet, as returned by addressfield_formats().
*/
function addressfield_process_format_form($format, &$form_state, $complete_form) {
// Make sure to load all the plugins that participated in this format.
ctools_include('plugins');
foreach ($format['#handlers'] as $handler) {
ctools_plugin_load_function('addressfield', 'format', $handler, 'format callback');
}
_addressfield_process_format_form($format, $format['#address'], $format['#required']);
return $format;
}
function _addressfield_process_format_form(&$format, $address, $required) {
foreach (element_children($format) as $key) {
$child = &$format[$key];
// Automatically expand elements that matches one of the field of the
// address structure.
if (in_array($key, array('name_line', 'first_name', 'last_name', 'organisation_name', 'country', 'administrative_area', 'sub_administrative_area', 'locality', 'dependent_locality', 'postal_code', 'thoroughfare', 'premise', 'sub_premise'))) {
// Set the type.
if (isset($child['#widget_type'])) {
$child['#type'] = $child['#widget_type'];
}
else {
if (isset($child['#options'])) {
$child['#type'] = 'select';
$child['#size'] = 0;
}
else {
$child['#type'] = 'textfield';
}
}
if (!$required) {
unset($child['#required']);
}
$child['#default_value'] = $address[$key];
}
// Recurse through the child.
_addressfield_process_format_form($child, $address, $required);
}
}
/**
* Render an address in a given format.
*/
function addressfield_render_address($format) {
_addressfield_render_address($format, $format['#address']);
return $format;
}
function _addressfield_render_address(&$format, $address) {
foreach (element_children($format) as $key) {
$child = &$format[$key];
// Automatically expand elements that matches one of the field of the
// address structure.
if (in_array($key, array('name_line', 'first_name', 'last_name', 'organisation_name', 'country', 'administrative_area', 'sub_administrative_area', 'locality', 'dependent_locality', 'postal_code', 'thoroughfare', 'premise', 'sub_premise'))) {
if (isset($child['#render_type'])) {
$child['#type'] = $child['#render_type'];
}
else {
$child['#type'] = 'addressfield_container';
if (!isset($child['#tag'])) {
$child['#tag'] = 'span';
}
}
if (isset($child['#options'])) {
// Expand options if necessary.
$child['#children'] = isset($child['#options'][$address[$key]]) ? check_plain($child['#options'][$address[$key]]) : '';
}
else {
$child['#children'] = check_plain($address[$key]);
}
// Skip empty elements.
if ((string) $child['#children'] === '') {
$child['#access'] = FALSE;
}
// Add #prefix and #field_suffix to the prefixes and suffixes.
if (isset($child['#prefix'])) {
$child['#prefix'] = (isset($child['#prefix']) ? $child['#prefix'] : '') . $child['#prefix'];
}
if (isset($child['#field_suffix'])) {
$child['#suffix'] = (isset($child['#suffix']) ? $child['#suffix'] : '') . $child['#field_suffix'];
}
}
// Recurse through the child.
_addressfield_render_address($child, $address);
}
}
/**
* @} End of "ingroup addressfield_format"
*/
/**
* Implementation of hook_theme().
*/
function addressfield_theme() {
$hooks['addressfield_container'] = array(
'render element' => 'element',
);
return $hooks;
}
/**
* Render a container for a set of address fields.
*/
function theme_addressfield_container($variables) {
$element = $variables['element'];
$element['#children'] = trim($element['#children']);
if (strlen($element['#children']) > 0) {
$output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>';
$output .= $element['#children'];
$output .= '</' . $element['#tag'] . ">";
return $output;
}
else {
return '';
}
}
/**
* Implementation of hook_element_info().
*/
function addressfield_element_info() {
$types['addressfield_container'] = array(
'#theme_wrappers' => array('addressfield_container'),
'#process' => array('addressfield_widget_process'),
'#attributes' => array(),
'#tag' => 'div',
);
return $types;
}
/**
* Form API process function: set the #parents of the children of this element so they appear at the same level as the parent.
*/
function addressfield_widget_process($element) {
foreach (element_children($element) as $key) {
$element[$key]['#parents'] = $element['#parents'];
$element[$key]['#parents'][count($element[$key]['#parents']) - 1] = $key;
}
return $element;
}
/**
* Implements hook_field_info()
*/
function addressfield_field_info() {
$fields = array();
$fields['addressfield'] = array(
'label' => t('Postal address'),
'description' => t('A field type used for storing postal addresses according the xNAL standard.'),
'settings' => array(),
'instance_settings' => array(),
'default_widget' => 'addressfield_standard',
'default_formatter' => 'addressfield_default',
'property_type' => 'addressfield',
'property_callbacks' => array('addressfield_property_info_callback'),
);
return $fields;
}
/**
* Returns an array of default values for the addressfield form elements.
*/
function addressfield_default_values($available_countries = NULL) {
if (!isset($available_countries)) {
$available_countries = _addressfield_country_options_list();
}
// Use the default country of the site if possible.
$default_country = variable_get('site_default_country', NULL);
// If the default country is undefined or not in the list of available countries,
// just fallback to the first country in the list.
if (!$default_country || !isset($available_countries[$default_country])) {
$default_country = key($available_countries);
}
return array(
'country' => $default_country,
'name_line' => '',
'first_name' => '',
'last_name' => '',
'organisation_name' => '',
'administrative_area' => '',
'sub_administrative_area' => '',
'locality' => '',
'dependent_locality' => '',
'postal_code' => '',
'thoroughfare' => '',
'premise' => '',
'sub_premise' => '',
'data' => '',
);
}
/**
* Implements hook_field_is_empty().
*/
function addressfield_field_is_empty($item, $field) {
// Every address field must have at least a country value or it is considered
// empty, even if it has name information.
return empty($item['country']);
}
/**
* Implements hook_field_widget_info()
*/
function addressfield_field_widget_info() {
$widgets = array();
$widgets['addressfield_standard'] = array(
'label' => t('Dynamic address form'),
'field types' => array('addressfield'),
'settings' => array(
'available_countries' => array(),
'format_handlers' => array('address'),
),
);
return $widgets;
}
/**
* Implements hook_field_widget_settings_form()
*/
function addressfield_field_widget_settings_form($field, $instance) {
$widget = $instance['widget'];
$defaults = field_info_widget_settings($widget['type']);
$settings = array_merge($defaults, $widget['settings']);
if ($widget['type'] == 'addressfield_standard') {
$form['available_countries'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Available countries'),
'#description' => t('If no countries are selected, all countries will be available.'),
'#options' => _addressfield_country_options_list(),
'#default_value' => $settings['available_countries'],
);
$form['format_handlers'] = array(
'#type' => 'checkboxes',
'#title' => t('Format handlers'),
'#options' => addressfield_format_plugins_options(),
'#default_value' => $settings['format_handlers'],
);
}
return $form;
}
/**
* Implements hook_field_widget_form()
*/
function addressfield_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$settings = $instance['widget']['settings'];
// Generate a specific key used to identify this element to restore a default
// value upon AJAX submission regardless of where this element is in the
// $form array.
$element_key = implode('|', array($element['#entity_type'], $element['#bundle'], $element['#field_name'], $element['#language'], $element['#delta']));
// Store the key in the element array as a value so it can be easily retrieved
// in context in the $form_state['values'] array in the element validator.
$element['element_key'] = array(
'#type' => 'value',
'#value' => $element_key,
);
// Get the default address used to build the widget form elements, looking
// first in the form state, then in the stored value for the field, and then
// in the default values of the instance.
$address = array();
if (!empty($form_state['addressfield'][$element_key])) {
// Use the value from the form_state if available.
$address = $form_state['addressfield'][$element_key];
}
elseif (!empty($items[$delta]['country'])) {
// Else use the saved value for the field.
$address = $items[$delta];
}
else {
// Otherwise use the instance default.
$address = (array) $instance['default_value'][0];
}
// Merge in default values to provide a value for every expected array key.
$countries = _addressfield_country_options_list($field, $instance);
$address += addressfield_default_values($countries);
// Add the form elements for the standard widget, which includes a country
// select list at the top that reloads the available address elements when the
// country is changed.
if ($instance['widget']['type'] == 'addressfield_standard') {
// Wrap everything in a fieldset. This is not the best looking element,
// but it's the only wrapper available in Drupal we can properly use
// in that context, and it is overridable if necessary.
$element['#type'] = 'fieldset';
// Generate the address form.
$context = array(
'mode' => 'form',
'field' => $field,
'instance' => $instance,
'langcode' => $langcode,
'delta' => $delta,
);
$element += addressfield_generate($address, $settings['format_handlers'], $context);
// Mark the form element as required if necessary.
$element['#required'] = $delta == 0 && $instance['required'];
}
return $element;
}
/**
* Element validate callback: rebuilds the form on country change and stores the current address value in the $form_state for retrieval on rebuild.
*/
function addressfield_standard_country_validate($element, &$form_state) {
// If the country was changed, rebuild the form.
if ($element['#default_value'] != $element['#value']) {
$form_state['rebuild'] = TRUE;
}
$parents = $element['#parents'];
array_pop($parents);
// Search through the form values to find the current address.
$address = drupal_array_get_nested_value($form_state['values'], $parents);
// Store the present address values in the form state for retrieval by the
// widget form regardless of where the widget sits in the $form array.
$form_state['addressfield'][$address['element_key']] = array_diff_key($address, array('element_key' => ''));
}
/**
* Ajax callback in response to a change of country in an address field.
*
* The only thing we have to do is to find the proper element to render.
*/
function addressfield_standard_widget_refresh($form, $form_state) {
// The target element is one element below the triggering country selector.
$array_parents = $form_state['triggering_element']['#array_parents'];
array_pop($array_parents);
// Iterate over the form parents to find the element.
$element = $form;
foreach ($array_parents as $name) {
$element = &$element[$name];
if (!empty($element['#addressfield'])) {
break;
}
}
// Return the address block, but remove the '_weight' element inserted
// by the field API.
unset($element['_weight']);
return $element;
}
/**
* Implements hook_field_formatter_info().
*/
function addressfield_field_formatter_info() {
return array(
'addressfield_default' => array(
'label' => t('Default'),
'field types' => array('addressfield'),
'settings' => array(
'use_widget_handlers' => 1,
'format_handlers' => array('address'),
),
),
);
}
/**
* Implements hook_field_formatter_settings_form().
*/
function addressfield_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element['use_widget_handlers'] = array(
'#type' => 'checkbox',
'#title' => t('Use the same configuration as the widget'),
'#default_value' => !empty($settings['use_widget_handlers']),
);
$element['format_handlers'] = array(
'#type' => 'checkboxes',
'#title' => t('Format handlers'),
'#options' => addressfield_format_plugins_options(),
'#default_value' => $settings['format_handlers'],
'#process' => array('form_process_checkboxes', '_addressfield_field_formatter_settings_form_process_add_state'),
'#element_validate' => array('_addressfield_field_formatter_settings_form_validate')
);
return $element;
}
/**
* Helper function: set the proper #states to the use widget handlers checkbox.
*/
function _addressfield_field_formatter_settings_form_process_add_state($element, $form_state) {
// Build a #parents based on the current checkbox.
$target_parents = array_slice($element['#parents'], 0, -1);
$target_parents[] = 'use_widget_handlers';
$target_parents = array_shift($target_parents) . ($target_parents ? '[' . implode('][', $target_parents) . ']' : '');
$element['#states']['visible'] = array(
':input[name="' . $target_parents . '"]' => array('checked' => FALSE),
);
return $element;
}
/**
* Helper function: filter the results of the checkboxes form element.
*/
function _addressfield_field_formatter_settings_form_validate($element, &$element_state) {
form_set_value($element, array_filter($element['#value']), $element_state);
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function addressfield_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = '';
if ($settings['use_widget_handlers']) {
return t('Use widget configuration');
}
else {
$summary = array();
$plugins = addressfield_format_plugins();
foreach ($settings['format_handlers'] as $handler) {
$summary[] = $plugins[$handler]['title'];
}
return $summary ? implode(', ', $summary) : t('No handler');
}
}
/**
* Implements hook_field_formatter_view().
*/
function addressfield_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$settings = $display['settings'];
$element = array();
switch ($display['type']) {
case 'addressfield_default':
if (!empty($settings['use_widget_handlers'])) {
$handlers = $instance['widget']['settings']['format_handlers'];
}
else {
$handlers = $settings['format_handlers'];
}
foreach ($items as $delta => $address) {
// Generate the address format.
$context = array(
'mode' => 'render',
'field' => $field,
'instance' => $instance,
'langcode' => $langcode,
'delta' => $delta,
);
$element[$delta] = addressfield_generate($address, $handlers, $context);
}
break;
}
return $element;
}
/**
* Callback to alter the property info of address fields.
*
* @see addressfield_field_info().
*/
function addressfield_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) {
$name = $field['field_name'];
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name];
$property['type'] = ($field['cardinality'] != 1) ? 'list<addressfield>' : 'addressfield';
$property['getter callback'] = 'entity_metadata_field_verbatim_get';
$property['setter callback'] = 'entity_metadata_field_verbatim_set';
$property['auto creation'] = 'addressfield_default_values';
$property['property info'] = addressfield_data_property_info();
unset($property['query callback']);
}
/**
* Defines info for the properties of the address field data structure.
*/
function addressfield_data_property_info($name = NULL) {
// Build an array of basic property information for the address field.
$properties = array(
'country' => array(
'label' => t('Country'),
'options list' => '_addressfield_country_options_list',
),
'name_line' => array(
'label' => t('Full name'),
),
'first_name' => array(
'label' => t('First name'),
),
'last_name' => array(
'label' => t('Last name'),
),
'organisation_name' => array(
'label' => t('Company'),
),
'administrative_area' => array(
'label' => t('Administrative area (i.e. State / Province)'),
),
'sub_administrative_area' => array(
'label' => t('Sub administrative area'),
),
'locality' => array(
'label' => t('Locality (i.e. City)'),
),
'dependent_locality' => array(
'label' => t('Dependent locality'),
),
'postal_code' => array(
'label' => t('Postal code'),
),
'thoroughfare' => array(
'label' => t('Thoroughfare (i.e. Street address)'),
),
'premise' => array(
'label' => t('Premise (i.e. Apartment / Suite number)'),
),
'name_line' => array(
'label' => t('Sub premise'),
),
);
// Add the default values for each of the address field properties.
foreach ($properties as $key => &$value) {
$value += array(
'description' => !empty($name) ? t('!label of field %name', array('!label' => $value['label'], '%name' => $name)) : '',
'type' => 'text',
'getter callback' => 'entity_property_verbatim_get',
'setter callback' => 'entity_property_verbatim_set',
);
}
return $properties;
}
/**
* Wraps country_get_list() for use as an Entity API options list.
*/
function _addressfield_country_options_list($field = NULL, $instance = NULL) {
// Necessary for country_get_list().
require_once DRUPAL_ROOT . '/includes/locale.inc';
$countries = country_get_list();
if (isset($field)) {
// If the instance is not specified, loop against all the instances of the field.
if (!isset($instance)) {
$instances = array();
foreach ($field['bundles'] as $entity_type => $bundles) {
foreach ($bundles as $bundle_name) {
$instances[] = field_info_instance($entity_type, $field['field_name'], $bundle_name);
}
}
}
else {
$instances = array($instance);
}
foreach ($instances as $instance) {
if (!empty($instance['widget']['settings']['available_countries'])) {
$countries = array_intersect_key($countries, $instance['widget']['settings']['available_countries']);
}
else {
// This instance allow all the countries.
$countries = country_get_list();
break;
}
}
}
return $countries;
}

View File

@@ -0,0 +1,15 @@
name = Address Field Example
description = Example module for how to implement an addressfield format handler.
core = 7.x
package = Fields
hidden = TRUE
dependencies[] = ctools
dependencies[] = addressfield
; Information added by drupal.org packaging script on 2012-05-29
version = "7.x-1.0-beta3"
core = "7.x"
project = "addressfield"
datestamp = "1338304248"

View File

@@ -0,0 +1,10 @@
<?php
/**
* Implements hook_ctools_plugin_directory().
*/
function addressfield_example_ctools_plugin_directory($module, $plugin) {
if ($module == 'addressfield') {
return 'plugins/' . $plugin;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
<?php
/**
* @file
* Hide then country when only one country is available.
*/
$plugin = array(
'title' => t('Hide the country when only one is available'),
'format callback' => 'addressfield_format_address_hide_country',
'type' => 'address',
'weight' => -80,
);
/**
* Format callback.
*
* @see CALLBACK_addressfield_format_callback()
*/
function addressfield_format_address_hide_country(&$format, $address, $context = array()) {
$format['country']['#access'] = (count($format['country']['#options']) > 1);
}

View File

@@ -0,0 +1,429 @@
<?php
/**
* @file
* The default format for adresses.
*/
$plugin = array(
'title' => t('Address form (country-specific)'),
'format callback' => 'addressfield_format_address_generate',
'type' => 'address',
'weight' => -100,
);
/**
* Format callback.
*
* @see CALLBACK_addressfield_format_callback()
*/
function addressfield_format_address_generate(&$format, $address, $context = array()) {
// We start with a reasonable default: a simple block format suitable
// for international shipping. We extend it with country-specific heuristics
// below.
// The street block.
$format['street_block'] = array(
'#type' => 'addressfield_container',
'#attributes' => array('class' => array('street-block')),
'#weight' => 0,
);
$format['street_block']['thoroughfare'] = array(
'#title' => t('Address 1'),
'#tag' => 'div',
'#attributes' => array('class' => array('thoroughfare')),
'#size' => 30,
// The #required will be automatically set to FALSE when processing.
'#required' => TRUE,
);
$format['street_block']['premise'] = array(
'#title' => t('Address 2'),
'#tag' => 'div',
'#attributes' => array('class' => array('premise')),
'#size' => 30,
);
$format['locality_block'] = array(
'#type' => 'addressfield_container',
'#attributes' => array('class' => array('addressfield-container-inline', 'locality-block', 'country-' . $address['country'])),
'#weight' => 50,
);
$format['locality_block']['#attached']['css'][] = drupal_get_path('module', 'addressfield') . '/addressfield.css';
$format['locality_block']['postal_code'] = array(
'#title' => t('Postal Code'),
'#size' => 10,
'#required' => TRUE,
'#attributes' => array('class' => array('postal-code')),
);
$format['locality_block']['locality'] = array(
'#title' => t('City'),
'#size' => 30,
'#required' => TRUE,
'#prefix' => ' ',
'#attributes' => array('class' => array('locality')),
);
$format['country'] = array(
'#title' => t('Country'),
'#options' => _addressfield_country_options_list(),
'#required' => TRUE,
'#attributes' => array('class' => array('country')),
'#weight' => 100,
);
// Those countries do not seem to have a relevant postal code.
if (in_array($address['country'], array('AF', 'AG', 'AL', 'AO', 'BB', 'BI', 'BJ', 'BO', 'BS', 'BW', 'BZ', 'CF', 'CG', 'CM', 'CO', 'DJ', 'DM', 'EG', 'ER', 'FJ', 'GD', 'GH', 'GM', 'GQ', 'GY', 'IE', 'KI', 'KM', 'KP', 'KY', 'LC', 'LY', 'ML', 'MR', 'NA', 'NR', 'RW', 'SB', 'SC', 'SL', 'SR', 'ST', 'TD', 'TG', 'TL', 'TO', 'TT', 'TV', 'TZ', 'UG', 'VC', 'VU', 'WS', 'ZW'))) {
unset($format['locality_block']['postal_code']);
// Remove the prefix from the first widget of the block.
$element_children = element_children($format['locality_block']);
$first_child = reset($element_children);
unset($format['locality_block'][$first_child]['#prefix']);
}
// Those countries generally use their administrative division in postal addresses.
if (in_array($address['country'], array('AR', 'AU', 'BR', 'BS', 'BY', 'BZ', 'CA', 'CN', 'DO', 'EG', 'ES', 'FJ', 'FM', 'GB', 'HN', 'ID', 'IE', 'IN', 'IT', 'JO', 'JP', 'KI', 'KN', 'KR', 'KW', 'KY', 'KZ', 'MX', 'MY', 'MZ', 'NG', 'NI', 'NR', 'NZ', 'OM', 'PA', 'PF', 'PG', 'PH', 'PR', 'PW', 'RU', 'SM', 'SO', 'SR', 'SV', 'TH', 'TW', 'UA', 'US', 'UY', 'VE', 'VI', 'VN', 'YU', 'ZA'))) {
$format['locality_block']['administrative_area'] = array(
'#title' => t('State'),
'#size' => 10,
'#required' => TRUE,
'#prefix' => ' ',
'#attributes' => array('class' => array('state')),
);
}
// A few contries have a well-known list of administrative divisions.
if ($address['country'] == 'US') {
$format['locality_block']['administrative_area']['#options'] = array(
'' => t('--'),
'AL' => t('Alabama'),
'AK' => t('Alaska'),
'AZ' => t('Arizona'),
'AR' => t('Arkansas'),
'CA' => t('California'),
'CO' => t('Colorado'),
'CT' => t('Connecticut'),
'DE' => t('Delaware'),
'DC' => t('District Of Columbia'),
'FL' => t('Florida'),
'GA' => t('Georgia'),
'HI' => t('Hawaii'),
'ID' => t('Idaho'),
'IL' => t('Illinois'),
'IN' => t('Indiana'),
'IA' => t('Iowa'),
'KS' => t('Kansas'),
'KY' => t('Kentucky'),
'LA' => t('Louisiana'),
'ME' => t('Maine'),
'MD' => t('Maryland'),
'MA' => t('Massachusetts'),
'MI' => t('Michigan'),
'MN' => t('Minnesota'),
'MS' => t('Mississippi'),
'MO' => t('Missouri'),
'MT' => t('Montana'),
'NE' => t('Nebraska'),
'NV' => t('Nevada'),
'NH' => t('New Hampshire'),
'NJ' => t('New Jersey'),
'NM' => t('New Mexico'),
'NY' => t('New York'),
'NC' => t('North Carolina'),
'ND' => t('North Dakota'),
'OH' => t('Ohio'),
'OK' => t('Oklahoma'),
'OR' => t('Oregon'),
'PA' => t('Pennsylvania'),
'RI' => t('Rhode Island'),
'SC' => t('South Carolina'),
'SD' => t('South Dakota'),
'TN' => t('Tennessee'),
'TX' => t('Texas'),
'UT' => t('Utah'),
'VT' => t('Vermont'),
'VA' => t('Virginia'),
'WA' => t('Washington'),
'WV' => t('West Virginia'),
'WI' => t('Wisconsin'),
'WY' => t('Wyoming'),
' ' => t('--'),
'AS' => t('American Samoa'),
'FM' => t('Federated States of Micronesia'),
'GU' => t('Guam'),
'MH' => t('Marshall Islands'),
'MP' => t('Northern Mariana Islands'),
'PW' => t('Palau'),
'PR' => t('Puerto Rico'),
'VI' => t('Virgin Islands'),
);
$format['locality_block']['postal_code']['#title'] = t('ZIP Code');
}
else if ($address['country'] == 'IT') {
$format['locality_block']['administrative_area']['#options'] = array(
'' => t('--'),
'AG' => 'Agrigento',
'AL' => 'Alessandria',
'AN' => 'Ancona',
'AO' => 'Valle d\'Aosta/Vallée d\'Aoste',
'AP' => 'Ascoli Piceno',
'AQ' => 'L\'Aquila',
'AR' => 'Arezzo',
'AT' => 'Asti',
'AV' => 'Avellino',
'BA' => 'Bari',
'BG' => 'Bergamo',
'BI' => 'Biella',
'BL' => 'Belluno',
'BN' => 'Benevento',
'BO' => 'Bologna',
'BR' => 'Brindisi',
'BS' => 'Brescia',
'BT' => 'Barletta-Andria-Trani',
'BZ' => 'Bolzano/Bozen',
'CA' => 'Cagliari',
'CB' => 'Campobasso',
'CE' => 'Caserta',
'CH' => 'Chieti',
'CI' => 'Carbonia-Iglesias',
'CL' => 'Caltanissetta',
'CN' => 'Cuneo',
'CO' => 'Como',
'CR' => 'Cremona',
'CS' => 'Cosenza',
'CT' => 'Catania',
'CZ' => 'Catanzaro',
'EN' => 'Enna',
'FC' => 'Forlì-Cesena',
'FE' => 'Ferrara',
'FG' => 'Foggia',
'FI' => 'Firenze',
'FM' => 'Fermo',
'FR' => 'Frosinone',
'GE' => 'Genova',
'GO' => 'Gorizia',
'GR' => 'Grosseto',
'IM' => 'Imperia',
'IS' => 'Isernia',
'KR' => 'Crotone',
'LC' => 'Lecco',
'LE' => 'Lecce',
'LI' => 'Livorno',
'LO' => 'Lodi',
'LT' => 'Latina',
'LU' => 'Lucca',
'MB' => 'Monza e Brianza',
'MC' => 'Macerata',
'ME' => 'Messina',
'MI' => 'Milano',
'MN' => 'Mantova',
'MO' => 'Modena',
'MS' => 'Massa-Carrara',
'MT' => 'Matera',
'NA' => 'Napoli',
'NO' => 'Novara',
'NU' => 'Nuoro',
'OG' => 'Ogliastra',
'OR' => 'Oristano',
'OT' => 'Olbia-Tempio',
'PA' => 'Palermo',
'PC' => 'Piacenza',
'PD' => 'Padova',
'PE' => 'Pescara',
'PG' => 'Perugia',
'PI' => 'Pisa',
'PN' => 'Pordenone',
'PO' => 'Prato',
'PR' => 'Parma',
'PT' => 'Pistoia',
'PU' => 'Pesaro e Urbino',
'PV' => 'Pavia',
'PZ' => 'Potenza',
'RA' => 'Ravenna',
'RC' => 'Reggio di Calabria',
'RE' => 'Reggio nell\'Emilia',
'RG' => 'Ragusa',
'RI' => 'Rieti',
'RM' => 'Roma',
'RN' => 'Rimini',
'RO' => 'Rovigo',
'SA' => 'Salerno',
'SI' => 'Siena',
'SO' => 'Sondrio',
'SP' => 'La Spezia',
'SR' => 'Siracusa',
'SS' => 'Sassari',
'SV' => 'Savona',
'TA' => 'Taranto',
'TE' => 'Teramo',
'TN' => 'Trento',
'TO' => 'Torino',
'TP' => 'Trapani',
'TR' => 'Terni',
'TS' => 'Trieste',
'TV' => 'Treviso',
'UD' => 'Udine',
'VA' => 'Varese',
'VB' => 'Verbano-Cusio-Ossola',
'VC' => 'Vercelli',
'VE' => 'Venezia',
'VI' => 'Vicenza',
'VR' => 'Verona',
'VS' => 'Medio Campidano',
'VT' => 'Viterbo',
'VV' => 'Vibo Valentia',
);
$format['locality_block']['administrative_area']['#title'] = t('Province');
}
else if ($address['country'] == 'BR') {
$format['locality_block']['administrative_area']['#options'] = array(
'' => t('--'),
'AC' => t('Acre'),
'AL' => t('Alagoas'),
'AM' => t('Amazonas'),
'AP' => t('Amapa'),
'BA' => t('Bahia'),
'CE' => t('Ceara'),
'DF' => t('Distrito Federal'),
'ES' => t('Espirito Santo'),
'GO' => t('Goias'),
'MA' => t('Maranhao'),
'MG' => t('Minas Gerais'),
'MS' => t('Mato Grosso do Sul'),
'MT' => t('Mato Grosso'),
'PA' => t('Para'),
'PB' => t('Paraiba'),
'PE' => t('Pernambuco'),
'PI' => t('Piaui'),
'PR' => t('Parana'),
'RJ' => t('Rio de Janeiro'),
'RN' => t('Rio Grande do Norte'),
'RO' => t('Rondonia'),
'RR' => t('Roraima'),
'RS' => t('Rio Grande do Sul'),
'SC' => t('Santa Catarina'),
'SE' => t('Sergipe'),
'SP' => t('Sao Paulo'),
'TO' => t('Tocantins'),
);
}
else if ($address['country'] == 'CA') {
$format['locality_block']['administrative_area']['#options'] = array(
'' => t('--'),
'AB' => t('Alberta'),
'BC' => t('British Columbia'),
'MB' => t('Manitoba'),
'NB' => t('New Brunswick'),
'NL' => t('Newfoundland'),
'NT' => t('Northwest Territories'),
'NS' => t('Nova Scotia'),
'NU' => t('Nunavut'),
'ON' => t('Ontario'),
'PE' => t('Prince Edward Island'),
'QC' => t('Quebec'),
'SK' => t('Saskatchewan'),
'YT' => t('Yukon Territory'),
);
$format['locality_block']['administrative_area']['#title'] = t('Province');
}
else if ($address['country'] == 'AU') {
$format['locality_block']['administrative_area']['#options'] = array(
'' => t('--'),
'ACT' => t('Australian Capital Territory'),
'NSW' => t('New South Wales'),
'NT' => t('Northern Territory'),
'QLD' => t('Queensland'),
'SA' => t('South Australia'),
'TAS' => t('Tasmania'),
'VIC' => t('Victoria'),
'WA' => t('Western Australia'),
);
}
// Those countries tend to put the postal code after the locality.
if (in_array($address['country'], array('AU', 'BD', 'BF', 'BH', 'BM', 'BN', 'BT', 'CA', 'FM', 'GB', 'ID', 'IN', 'JM', 'JO', 'KH', 'LB', 'LS', 'LV', 'MM', 'MN', 'MV', 'MW', 'NG', 'NP', 'NZ', 'PE', 'PK', 'PR', 'PW', 'SA', 'SG', 'SO', 'TH', 'US', 'VI', 'VG', 'VN'))) {
// Take the widget out of the array.
$postal_code_widget = $format['locality_block']['postal_code'];
$postal_code_widget['#prefix'] = ' ';
unset($format['locality_block']['postal_code']);
// Add it back.
$format['locality_block']['postal_code'] = $postal_code_widget;
// Remove the prefix from the first widget of the block.
$element_children = element_children($format['locality_block']);
$first_child = reset($element_children);
unset($format['locality_block'][$first_child]['#prefix']);
}
// GB-specific tweaks
if ($address['country'] == 'GB') {
// Locality
$format['locality_block']['locality'] = array_merge(
$format['locality_block']['locality'],
array(
'#title' => t('Town/City'),
'#weight' => 40,
'#prefix' => '',
'#tag' => 'div',
)
);
// Administrative
$format['locality_block']['administrative_area'] = array_merge(
$format['locality_block']['administrative_area'],
array(
'#title' => t('County'),
'#required' => FALSE,
'#weight' => 50,
'#size' => 30,
'#prefix' => '',
'#tag' => 'div',
)
);
// Postal code
$format['locality_block']['postal_code'] = array_merge(
$format['locality_block']['postal_code'],
array(
'#title' => t('Postcode'),
'#weight' => 60,
'#prefix' => '',
'#tag' => 'div',
)
);
}
if ($context['mode'] == 'form') {
// Provide a wrapper ID for AJAX replacement based on country selection.
if (!isset($format['#wrapper_id'])) {
$format['#wrapper_id'] = drupal_html_id('addressfield-wrapper');
$format['#prefix'] = '<div id="' . $format['#wrapper_id'] . '">';
$format['#suffix'] = '</div>';
}
// Form mode, move the country selector to the top of the form.
$format['country']['#weight'] = -10;
// Limit it to the countries supported by the widget.
if (isset($context['field'])) {
$format['country']['#options'] = _addressfield_country_options_list($context['field'], $context['instance']);
}
// AJAX enable it.
$format['country']['#ajax'] = array(
'callback' => 'addressfield_standard_widget_refresh',
'wrapper' => $format['#wrapper_id'],
'method' => 'replace',
);
$format['country']['#element_validate'] = array('addressfield_standard_country_validate');
// Don't validate any element when the country is changed.
$format['country']['#limit_validation_errors'] = array();
if (isset($context['delta']) && $context['delta'] > 0) {
// On subsequent elements of a field, we make the country field non
// required and add a ' - None - ' option to it, so as to allow the
// user to remove the address by clearing the country field.
$format['country']['#required'] = FALSE;
$format['country']['#empty_value'] = '';
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* @file
* Generates a first name + last name format.
*/
$plugin = array(
'title' => t('Name (First name, Last name)'),
'format callback' => 'addressfield_format_name_full_generate',
'type' => 'name',
'weight' => 0,
);
/**
* Format callback.
*
* @see CALLBACK_addressfield_format_callback()
*/
function addressfield_format_name_full_generate(&$format, $address) {
$format['name_block'] = array(
'#type' => 'addressfield_container',
'#attributes' => array('class' => array('addressfield-container-inline', 'name-block')),
'#weight' => -100,
);
$format['name_block']['first_name'] = array(
'#title' => t('First name'),
'#size' => 30,
'#required' => TRUE,
'#attributes' => array('class' => array('first-name')),
);
$format['name_block']['last_name'] = array(
'#title' => t('Last name'),
'#size' => 30,
'#required' => TRUE,
'#prefix' => ' ',
'#attributes' => array('class' => array('last-name')),
);
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* @file
* Generates a first name + last name format.
*/
$plugin = array(
'title' => t('Name (single line)'),
'format callback' => 'addressfield_format_name_oneline_generate',
'type' => 'name',
'weight' => 0,
);
/**
* Format callback.
*
* @see CALLBACK_addressfield_format_callback()
*/
function addressfield_format_name_oneline_generate(&$format, $address) {
$format['name_block'] = array(
'#type' => 'addressfield_container',
'#attributes' => array('class' => array('addressfield-container-inline', 'name-block')),
'#weight' => -100,
);
$format['name_block']['name_line'] = array(
'#title' => t('Full name'),
'#tag' => 'div',
'#attributes' => array('class' => array('name-block')),
'#size' => 30,
'#required' => TRUE,
);
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* @file
* Generates a first name + last name format.
*/
$plugin = array(
'title' => t('Organisation (single line)'),
'format callback' => 'addressfield_format_organisation_generate',
'type' => 'organisation',
'weight' => -10,
);
/**
* Format callback.
*
* @see CALLBACK_addressfield_format_callback()
*/
function addressfield_format_organisation_generate(&$format, $address) {
$format['organisation_block'] = array(
'#type' => 'addressfield_container',
'#attributes' => array('class' => array('addressfield-container-inline', 'name-block')),
'#weight' => -50,
);
$format['organisation_block']['organisation_name'] = array(
'#title' => t('Company'),
'#size' => 30,
'#attributes' => array('class' => array('organisation-name')),
);
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Implements hook_field_views_data().
*/
function addressfield_field_views_data($field) {
$data = field_views_field_default_views_data($field);
// Add a handler for countries.
foreach ($field['storage']['details']['sql'] as $type => $tables) {
foreach ($tables as $table_name => $columns) {
if (!isset($columns['country'])) {
continue;
}
$column_real_name = $columns['country'];
if (!isset($data[$table_name][$column_real_name]['filter'])) {
continue;
}
$data[$table_name][$column_real_name]['filter']['handler'] = 'addressfield_views_handler_filter_country';
}
}
return $data;
}

View File

@@ -0,0 +1,9 @@
<?php
class addressfield_views_handler_filter_country extends views_handler_filter_in_operator {
function get_value_options() {
$this->value_title = t('Country');
$field = field_info_field($this->definition['field_name']);
$this->value_options = _addressfield_country_options_list($field);
}
}