FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
339
sites/all/modules/contrib/dev/addressfield_tokens/LICENSE.txt
Normal file
339
sites/all/modules/contrib/dev/addressfield_tokens/LICENSE.txt
Normal 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.
|
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// $Id$
|
||||
/*
|
||||
* Copyright © 2012 New Signature
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
* You can contact New Signature by electronic mail at labs@newsignature.com -or- by U.S. Postal Service at 1100 H St. NW, Suite 940, Washington, DC 20005.
|
||||
*/
|
||||
/**
|
||||
* @file Provides an Administrative UI for the addressfield_tokens module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a form for configuring regional options for addresses.
|
||||
*
|
||||
* @param array $form
|
||||
* @param array $form_state
|
||||
* @return array The form.
|
||||
*/
|
||||
function addressfield_tokens_admin_form($form, &$form_state) {
|
||||
$options = array('' => t('- None -')) + _addressfield_tokens_countries();
|
||||
|
||||
$form['addressfield_tokens_default_country'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Default country'),
|
||||
'#description' => t('In the city/state views, addresses in this country will not display the country.'),
|
||||
'#options' => $options,
|
||||
'#default_value' => addressfield_tokens_default_country(),
|
||||
);
|
||||
|
||||
$form['addressfield_tokens_property_names'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Custom address property names'),
|
||||
'#description' => t('Change the names of address fields when selecting tokens.'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
|
||||
$names = addressfield_tokens_property_names();
|
||||
$props = addressfield_data_property_info();
|
||||
foreach ($props as $name => $prop) {
|
||||
$form['addressfield_tokens_property_names'][$name] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => $prop['label'],
|
||||
'#description' => $name,
|
||||
'#default_value' => !empty($names[$name]) ? $names[$name] : $prop['label'],
|
||||
);
|
||||
}
|
||||
return system_settings_form($form);
|
||||
}
|
@@ -0,0 +1,398 @@
|
||||
<?php
|
||||
// $Id$
|
||||
/*
|
||||
* Copyright © 2012 New Signature
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
* You can contact New Signature by electronic mail at labs@newsignature.com -or- by U.S. Postal Service at 1100 H St. NW, Suite 940, Washington, DC 20005.
|
||||
*/
|
||||
/**
|
||||
* @file Webform Component information for an address field type
|
||||
*/
|
||||
|
||||
/**
|
||||
* Specify the default properties of a component.
|
||||
*
|
||||
* @return
|
||||
* An array defining the default structure of a component.
|
||||
*/
|
||||
function _webform_defaults_addressfield() {
|
||||
return array (
|
||||
'name' => '',
|
||||
'form_key' => NULL,
|
||||
'mandatory' => 0,
|
||||
'pid' => 0,
|
||||
'weight' => 0,
|
||||
'extra' => array (
|
||||
'title_display' => 0,
|
||||
'private' => FALSE,
|
||||
'attributes' => array (),
|
||||
'description' => '',
|
||||
'available_countries' => array(),
|
||||
'csv_separate' => 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the form for editing a component.
|
||||
* Create a set of form elements to be displayed on the form for editing this
|
||||
* component. Use care naming the form items, as this correlates directly to the
|
||||
* database schema. The component "Name" and "Description" fields are added to
|
||||
* every component type and are not necessary to specify here (although they
|
||||
* may be overridden if desired).
|
||||
*
|
||||
* @param $component
|
||||
* A Webform component array.
|
||||
*
|
||||
* @return
|
||||
* An array of form items to be displayed on the edit component page
|
||||
*/
|
||||
function _webform_edit_addressfield($component) {
|
||||
$form = array ();
|
||||
|
||||
$form['extra']['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' => $component['extra']['available_countries'],
|
||||
);
|
||||
$form['extra']['csv_separate'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('CSV download'),
|
||||
'#description' => t('How would you like addresses presented in CSV downloads?'),
|
||||
'#options' => array(
|
||||
0 => t('Display entire address in a single column'),
|
||||
1 => t('Display each address component in a separate column'),
|
||||
),
|
||||
'#default_value' => $component['extra']['csv_separate'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a Webform component to be part of a form.
|
||||
*
|
||||
* @param $component
|
||||
* A Webform component array.
|
||||
* @param $value
|
||||
* If editing an existing submission or resuming a draft, this will contain
|
||||
* an array of values to be shown instead of the default in the component
|
||||
* configuration. This value will always be an array, keyed numerically for
|
||||
* each value saved in this field.
|
||||
* @param $filter
|
||||
* Whether or not to filter the contents of descriptions and values when
|
||||
* rendering the component. Values need to be unfiltered to be editable by
|
||||
* Form Builder.
|
||||
*
|
||||
* @see _webform_client_form_add_component()
|
||||
*/
|
||||
function _webform_render_addressfield($component, $value = NULL, $filter = TRUE) {
|
||||
$element = array (
|
||||
'#type' => 'fieldset',
|
||||
'#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
|
||||
'#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
|
||||
'#attributes' => $component['extra']['attributes'],
|
||||
'#theme_wrappers' => array ( 'webform_element' ),
|
||||
'#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'],
|
||||
'#required' => $component['mandatory'],
|
||||
'#weight' => $component['weight'],
|
||||
'#translatable' => array (
|
||||
'title',
|
||||
'description',
|
||||
),
|
||||
);
|
||||
|
||||
$available = !empty($component['extra']['available_countries']) ? $component['extra']['available_countries'] : NULL;
|
||||
|
||||
// Get the current address
|
||||
if (!empty($value[0])) {
|
||||
if (is_string($value[0])) {
|
||||
$address = unserialize($value[0]);
|
||||
}
|
||||
else {
|
||||
$address = $value[0];
|
||||
}
|
||||
}
|
||||
elseif (!empty($component['value'])) {
|
||||
$address = $component['value'];
|
||||
}
|
||||
else {
|
||||
$address = _webform_addressfield($component['cid']);
|
||||
}
|
||||
if (empty($address)) {
|
||||
$address = addressfield_default_values($available);
|
||||
}
|
||||
|
||||
// Generate the address form.
|
||||
$context = array(
|
||||
'mode' => 'form',
|
||||
);
|
||||
$element += addressfield_generate($address, array('address'), $context);
|
||||
|
||||
if (!empty($available)) {
|
||||
$element['country']['#options'] = array_intersect_key($element['country']['#options'], $available);
|
||||
}
|
||||
$element['country']['#element_validate'] = array('_webform_addressfield_country_validate');
|
||||
$element['country']['#cid'] = $component['cid'];
|
||||
$element['country']['#limit_validation_errors'] = array();
|
||||
|
||||
$form_state = array();
|
||||
drupal_alter('field_widget_addressfield_standard_form', $element, $form_state, $context);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an addressfield submitted in a webform component. Ideally we should store
|
||||
* it in the $form_state instead, but there appears to be no way to get it to actually
|
||||
* pass through to _webform_render_addressfield().
|
||||
*
|
||||
* @param $cid integer The ID of the webform component.
|
||||
* @param $address array If set, this address will be stored with the given $cid.
|
||||
* @return array The address stored with the given $cid, if there is one; otherwise, NULL.
|
||||
*/
|
||||
function _webform_addressfield($cid, $address = NULL) {
|
||||
$out = &drupal_static(__FUNCTION__, array());
|
||||
if (isset($address)) {
|
||||
$out[$cid] = $address;
|
||||
}
|
||||
if (isset($out[$cid])) {
|
||||
return $out[$cid];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a country, and if it changes, rebuilds the form for the new country
|
||||
*/
|
||||
function _webform_addressfield_country_validate(&$element, &$form_state) {
|
||||
// If the country was changed, rebuild the form.
|
||||
if ($element['#default_value'] != $element['#value']) {
|
||||
$form_state['rebuild'] = TRUE;
|
||||
}
|
||||
|
||||
$cid = $element['#cid'];
|
||||
$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);
|
||||
|
||||
_webform_addressfield($cid, $address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the result of a submission for a component.
|
||||
* The output of this function will be displayed under the "Results" tab then
|
||||
* "Submissions". This should output the saved data in some reasonable manner.
|
||||
*
|
||||
* @param $component
|
||||
* A Webform component array.
|
||||
* @param $value
|
||||
* An array of information containing the submission result, directly
|
||||
* correlating to the webform_submitted_data database table schema.
|
||||
* @param $format
|
||||
* Either 'html' or 'text'. Defines the format that the content should be
|
||||
* returned as. Make sure that returned content is run through check_plain()
|
||||
* or other filtering functions when returning HTML.
|
||||
*
|
||||
* @return
|
||||
* A renderable element containing at the very least these properties:
|
||||
* - #title
|
||||
* - #weight
|
||||
* - #component
|
||||
* - #format
|
||||
* - #value
|
||||
* Webform also uses #theme_wrappers to output the end result to the user,
|
||||
* which will properly format the label and content for use within an e-mail
|
||||
* (such as wrapping the text) or as HTML (ensuring consistent output).
|
||||
*/
|
||||
function _webform_display_addressfield($component, $value, $format = 'html') {
|
||||
$address = NULL;
|
||||
if (isset($value[0])) {
|
||||
$address = $value[0];
|
||||
if (is_string($address)) {
|
||||
$address = unserialize($address);
|
||||
}
|
||||
}
|
||||
return array (
|
||||
'#title' => $component['name'],
|
||||
'#weight' => $component['weight'],
|
||||
'#theme' => $format == 'html' ? 'addressfield_formatter' : 'addressfield_formatter__linear',
|
||||
'#theme_wrappers' => $format == 'html' ? array ( 'webform_element' ) : array ( 'webform_element_text' ),
|
||||
'#post_render' => array ( 'webform_element_wrapper' ),
|
||||
'#component' => $component,
|
||||
'#format' => $format,
|
||||
'#address' => $address,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A hook for changing the input values before saving to the database.
|
||||
* Webform expects a component to consist of a single field, or a single array
|
||||
* of fields. If you have a component that requires a deeper form tree
|
||||
* you must flatten the data into a single array using this callback
|
||||
* or by setting #parents on each field to avoid data loss and/or unexpected
|
||||
* behavior.
|
||||
* Note that Webform will save the result of this function directly into the
|
||||
* database.
|
||||
*
|
||||
* @param $component
|
||||
* A Webform component array.
|
||||
* @param $value
|
||||
* The POST data associated with the user input.
|
||||
*
|
||||
* @return
|
||||
* An array of values to be saved into the database. Note that this should be
|
||||
* a numerically keyed array.
|
||||
*/
|
||||
function _webform_submit_addressfield($component, $value) {
|
||||
return serialize($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate and returns statistics about results for this component.
|
||||
* This takes into account all submissions to this webform. The output of this
|
||||
* function will be displayed under the "Results" tab then "Analysis".
|
||||
*
|
||||
* @param $component
|
||||
* An array of information describing the component, directly correlating to
|
||||
* the webform_component database schema.
|
||||
* @param $sids
|
||||
* An optional array of submission IDs (sid). If supplied, the analysis will
|
||||
* be limited to these sids.
|
||||
* @param $single
|
||||
* Boolean flag determining if the details about a single component are being
|
||||
* shown. May be used to provided detailed information about a single
|
||||
* component's analysis, such as showing "Other" options within a select list.
|
||||
*
|
||||
* @return
|
||||
* An array of data rows, each containing a statistic for this component's
|
||||
* submissions.
|
||||
*/
|
||||
function _webform_analysis_addressfield($component, $sids = array (), $single = FALSE) {
|
||||
// TODO Update this function
|
||||
|
||||
// Generate the list of options and questions.
|
||||
$query = db_select('webform_submitted_data', 'wsd')
|
||||
->fields('wsd', array ('data'))
|
||||
->condition('nid', $component['nid'])
|
||||
->condition('cid', $component['cid']);
|
||||
|
||||
if ( count($sids) ) {
|
||||
$query->condition('sid', $sids, 'IN');
|
||||
}
|
||||
$non_blanks = 0;
|
||||
$submissions = 0;
|
||||
$results = $query->execute();
|
||||
foreach ($results as $row) {
|
||||
if ( drupal_strlen(trim($row->data)) > 0 ) {
|
||||
$non_blanks++;
|
||||
}
|
||||
$submissions++;
|
||||
}
|
||||
$rows[0] = array (
|
||||
t('Left Blank'),
|
||||
( $submissions - $non_blanks )
|
||||
);
|
||||
$rows[1] = array (
|
||||
t('User entered value'),
|
||||
$non_blanks
|
||||
);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the result of a component value for display in a table.
|
||||
* The output of this function will be displayed under the "Results" tab then
|
||||
* "Table".
|
||||
*
|
||||
* @param $component
|
||||
* A Webform component array.
|
||||
* @param $value
|
||||
* An array of information containing the submission result, directly
|
||||
* correlating to the webform_submitted_data database schema.
|
||||
*
|
||||
* @return
|
||||
* Textual output formatted for human reading.
|
||||
*/
|
||||
function _webform_table_addressfield($component, $value) {
|
||||
if (!empty($value[0])) {
|
||||
return theme('addressfield_formatter', array( 'address' => $value[0] ));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the header for this component to be displayed in a CSV file.
|
||||
* The output of this function will be displayed under the "Results" tab then
|
||||
* "Download".
|
||||
*
|
||||
* @param $component
|
||||
* A Webform component array.
|
||||
* @param $export_options
|
||||
* An array of options that may configure export of this field.
|
||||
*
|
||||
* @return
|
||||
* An array of data to be displayed in the first three rows of a CSV file, not
|
||||
* including either prefixed or trailing commas.
|
||||
*/
|
||||
function _webform_csv_headers_addressfield($component, $export_options) {
|
||||
$header = array ();
|
||||
if (!empty($component['extra']['csv_separate']) && $component['extra']['csv_separate'] == 1) {
|
||||
$header[0] = array();
|
||||
$header[1] = array();
|
||||
$header[2] = array();
|
||||
|
||||
foreach (addressfield_tokens_property_names() as $key => $name) {
|
||||
$header[0][] = '';
|
||||
$header[1][] = (empty($header[1])) ? $component['name'] : '';
|
||||
$header[2][] = $name;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$header[0] = array('');
|
||||
$header[1] = array();
|
||||
$header[2] = array($component['name']);
|
||||
}
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the submitted data of a component for CSV downloading.
|
||||
* The output of this function will be displayed under the "Results" tab then
|
||||
* "Download".
|
||||
*
|
||||
* @param $component
|
||||
* A Webform component array.
|
||||
* @param $export_options
|
||||
* An array of options that may configure export of this field.
|
||||
* @param $value
|
||||
* An array of information containing the submission result, directly
|
||||
* correlating to the webform_submitted_data database schema.
|
||||
*
|
||||
* @return
|
||||
* An array of items to be added to the CSV file. Each value within the array
|
||||
* will be another column within the file. This function is called once for
|
||||
* every row of data.
|
||||
*/
|
||||
function _webform_csv_data_addressfield($component, $export_options, $value) {
|
||||
if (!empty($component['extra']['csv_separate']) && $component['extra']['csv_separate'] == 1) {
|
||||
$return = array();
|
||||
foreach (addressfield_tokens_property_names() as $key => $name) {
|
||||
$return[] = (isset($value[0][$key])) ? $value[0][$key] : '';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
else {
|
||||
if (!empty($value[0])) {
|
||||
return theme('addressfield_formatter__linear', array( 'address' => $value[0] ));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
; $Id$
|
||||
; Copyright © 2012 New Signature
|
||||
;
|
||||
; 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
; You can contact New Signature by electronic mail at labs@newsignature.com <20>or- by U.S. Postal Service at 1100 H St. NW, Suite 940, Washington, DC 20005.
|
||||
|
||||
name = Address Field Tokens
|
||||
description = Creates tokens for address fields, adds new addressfield renders, and adds webform integration.
|
||||
core = 7.x
|
||||
package = Fields
|
||||
version = 7.x-1.0-dev
|
||||
|
||||
dependencies[] = addressfield
|
||||
dependencies[] = entity_token
|
||||
dependencies[] = token
|
||||
|
||||
; Information added by Drupal.org packaging script on 2014-05-14
|
||||
version = "7.x-1.4"
|
||||
core = "7.x"
|
||||
project = "addressfield_tokens"
|
||||
datestamp = "1400081330"
|
||||
|
@@ -0,0 +1,439 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Copyright 2011 New Signature
|
||||
* http://www.newsignature.com
|
||||
*
|
||||
* @author Andrew Marcus
|
||||
* @since Oct 4, 2011
|
||||
*/
|
||||
|
||||
function addressfield_tokens_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['admin/config/regional/address'] = array(
|
||||
'title' => 'Addresses',
|
||||
'description' => 'Settings for address fields and tokens',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('addressfield_tokens_admin_form'),
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'file' => 'addressfield_tokens.admin.inc',
|
||||
'type' => MENU_NORMAL_ITEM,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function addressfield_tokens_theme($existing, $type, $theme, $path) {
|
||||
$theme = array(
|
||||
'addressfield_formatter' => array(
|
||||
'variables' => array('address' => NULL, 'handlers' => array('address')),
|
||||
'file' => 'addressfield_tokens.theme.inc',
|
||||
),
|
||||
'addressfield_formatter__citystate' => array(
|
||||
'variables' => array('address' => NULL),
|
||||
'file' => 'addressfield_tokens.theme.inc',
|
||||
),
|
||||
'addressfield_formatter__linear' => array(
|
||||
'variables' => array('address' => NULL, 'premise' => TRUE, 'organisation_name' => TRUE, 'name_line' => TRUE),
|
||||
'file' => 'addressfield_tokens.theme.inc',
|
||||
),
|
||||
'addressfield_formatter__components' => array(
|
||||
'variables' => array(
|
||||
'address' => NULL,
|
||||
'components' => array('thoroughfare', 'premise', 'locality', 'administrative_area', 'postal_code', 'country'),
|
||||
'separator' => ', ',
|
||||
),
|
||||
'file' => 'addressfield_tokens.theme.inc',
|
||||
),
|
||||
);
|
||||
|
||||
return $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_info().
|
||||
*/
|
||||
function addressfield_tokens_field_formatter_info() {
|
||||
return array(
|
||||
'addressfield_citystate' => array(
|
||||
'label' => t('City/State'),
|
||||
'field types' => array('addressfield'),
|
||||
),
|
||||
'addressfield_linear' => array(
|
||||
'label' => t('One line'),
|
||||
'field types' => array('addressfield'),
|
||||
),
|
||||
'addressfield_state' => array(
|
||||
'label' => t('State'),
|
||||
'field types' => array('addressfield'),
|
||||
),
|
||||
'addressfield_country' => array(
|
||||
'label' => t('Country'),
|
||||
'field types' => array('addressfield'),
|
||||
),
|
||||
'addressfield_components' => array(
|
||||
'label' => t('Address components'),
|
||||
'field types' => array('addressfield'),
|
||||
'settings' => array(
|
||||
'components' => array('thoroughfare', 'premise', 'locality', 'administrative_area', 'postal_code', 'country'),
|
||||
'separator' => ', ',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_settings_form().
|
||||
*/
|
||||
function addressfield_tokens_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
|
||||
$element = array();
|
||||
if ($display['type'] == 'addressfield_components') {
|
||||
$element['components'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Components to render'),
|
||||
'#multiple' => TRUE,
|
||||
'#rows' => 10,
|
||||
'#options' => addressfield_tokens_components(),
|
||||
'#default_value' => $settings['components'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$element['separator'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Separator'),
|
||||
'#description' => t('The separator to use between components. Use \n for a line break.'),
|
||||
'#default_value' => $settings['separator'],
|
||||
);
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_settings_summary().
|
||||
*/
|
||||
function addressfield_tokens_field_formatter_settings_summary($field, $instance, $view_mode) {
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
$summary = '';
|
||||
|
||||
if ($display['type'] == 'addressfield_components') {
|
||||
$comps = array_intersect_key(addressfield_tokens_components(), array_flip($settings['components']));
|
||||
$sep = str_replace('\n', '<br/>', $settings['separator']);
|
||||
$summary = implode($sep, $comps);
|
||||
}
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_view().
|
||||
*/
|
||||
function addressfield_tokens_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
|
||||
$element = array();
|
||||
|
||||
switch ($display['type']) {
|
||||
case 'addressfield_citystate':
|
||||
$theme = array('addressfield_formatter__citystate', 'addressfield_formatter');
|
||||
if (!empty($item['country'])) {
|
||||
array_unshift($theme, 'addressfield_formatter__citystate__' . $item['country']);
|
||||
}
|
||||
foreach ($items as $delta => $item) {
|
||||
$element[$delta] = array(
|
||||
'#theme' => $theme,
|
||||
'#address' => $item,
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'addressfield_linear':
|
||||
$theme = array('addressfield_formatter__linear', 'addressfield_formatter');
|
||||
if (!empty($item['country'])) {
|
||||
array_unshift($theme, 'addressfield_formatter__linear__' . $item['country']);
|
||||
}
|
||||
foreach ($items as $delta => $item) {
|
||||
$element[$delta] = array(
|
||||
'#theme' => $theme,
|
||||
'#address' => $item,
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'addressfield_country':
|
||||
foreach ($items as $delta => $item) {
|
||||
if (!empty($item['country'])) {
|
||||
$country = _addressfield_tokens_country($item['country']);
|
||||
$element[$delta] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => $country,
|
||||
'#prefix' => '<span class="addressfield-country">',
|
||||
'#suffix' => '</span>',
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'addressfield_state':
|
||||
foreach ($items as $delta => $item) {
|
||||
if (!empty($item['country']) && !empty($item['administrative_area'])) {
|
||||
$state = _addressfield_tokens_state($item['country'], $item['administrative_area']);
|
||||
$element[$delta] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => $state,
|
||||
'#prefix' => '<span class="addressfield-state">',
|
||||
'#suffix' => '</span>',
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'addressfield_components':
|
||||
$theme = array('addressfield_formatter__components', 'addressfield_formatter');
|
||||
if (!empty($item['country'])) {
|
||||
array_unshift($theme, 'addressfield_formatter__components__' . $item['country']);
|
||||
}
|
||||
|
||||
$settings = $display['settings'];
|
||||
foreach ($items as $delta => $item) {
|
||||
$element[$delta] = array(
|
||||
'#theme' => $theme,
|
||||
'#address' => $item,
|
||||
'#components' => $settings['components'],
|
||||
'#separator' => $settings['separator'],
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the country that has been configured as the default country.
|
||||
*/
|
||||
function addressfield_tokens_default_country() {
|
||||
return variable_get('addressfield_tokens_default_country', 'US');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the names that have been configured for each address field.
|
||||
*/
|
||||
function addressfield_tokens_property_names() {
|
||||
$names = variable_get('addressfield_tokens_property_names', array());
|
||||
if (empty($names)) {
|
||||
$props = addressfield_data_property_info();
|
||||
foreach($props as $name => $prop) {
|
||||
$names[$name] = $prop['label'];
|
||||
}
|
||||
}
|
||||
return $names;
|
||||
}
|
||||
|
||||
function addressfield_tokens_components() {
|
||||
$comps = &drupal_static(__FUNCTION__, array());
|
||||
if (empty($comps)) {
|
||||
$names = addressfield_tokens_property_names();
|
||||
foreach (array('first_name', 'last_name', 'name_line', 'organisation_name', 'thoroughfare', 'premise', 'locality', 'dependent_locality', 'administrative_area', 'sub_administrative_area', 'postal_code', 'country') as $key) {
|
||||
$comps[$key] = $names[$key];
|
||||
if (in_array($key, array('administrative_area', 'country'))) {
|
||||
$comps[$key . '_full'] = t('@name (full)', array(
|
||||
'@name' => $names[$key],
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $comps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of countries from the locale settings in Drupal.
|
||||
*
|
||||
* @return array An array of countries. The keys are the 2-letter
|
||||
* abbreviations and the values are the full country names.
|
||||
*/
|
||||
function _addressfield_tokens_countries() {
|
||||
$countries = &drupal_static(__FUNCTION__);
|
||||
if (empty($countries)) {
|
||||
include_once('includes/locale.inc');
|
||||
$countries = country_get_list();
|
||||
}
|
||||
return $countries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the country with the given abbreviation.
|
||||
*
|
||||
* @param string $country The 2-letter abbreviation of the country.
|
||||
* @return string The name of the country, or FALSE.
|
||||
*/
|
||||
function _addressfield_tokens_country($country) {
|
||||
$countries = _addressfield_tokens_countries();
|
||||
|
||||
// Country abbreviations will always be two uppercase letters.
|
||||
$country = drupal_strtoupper($country);
|
||||
if (!empty($country) && isset($countries[$country])) {
|
||||
return $countries[$country];
|
||||
}
|
||||
return $country;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the abbreviation of the country with the given name
|
||||
*
|
||||
* @param string The name of the country
|
||||
* @return string $country The 2-letter abbreviation of the country, or FALSE.
|
||||
*/
|
||||
function _addressfield_tokens_country_abbr($country) {
|
||||
$countries = array_flip(array_map('strtolower', _addressfield_tokens_countries()));
|
||||
|
||||
if (isset($countries[strtolower($country)])) {
|
||||
return $countries[strtolower($country)];
|
||||
}
|
||||
return $country;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of states in the given country.
|
||||
*
|
||||
* @param string $country The 2-letter abbreviation of the country.
|
||||
*
|
||||
* @return array An array of countries. The keys are the 2-letter
|
||||
* abbreviations and the values are the full country names.
|
||||
*/
|
||||
function _addressfield_tokens_states($country) {
|
||||
$states = &drupal_static(__FUNCTION__);
|
||||
$country = drupal_strtoupper($country);
|
||||
if (!isset($states[$country])) {
|
||||
$cache = cache_get('addressfield_tokens_states');
|
||||
if ($cache) {
|
||||
$states = $cache->data;
|
||||
}
|
||||
}
|
||||
if (!isset($states[$country])) {
|
||||
$format = addressfield_generate(array('country' => $country), array('address'), array('mode' => 'render'));
|
||||
|
||||
if (isset($format['locality_block']['administrative_area']['#options'])) {
|
||||
$states[$country] = $format['locality_block']['administrative_area']['#options'];
|
||||
}
|
||||
else {
|
||||
$states[$country] = array();
|
||||
}
|
||||
cache_set('addressfield_tokens_states', $states);
|
||||
}
|
||||
return $states[$country];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the state with the given abbreviation.
|
||||
*
|
||||
* @param string $country The 2-letter abbreviation of the country.
|
||||
* @param string $state The 2-letter abbreviation of the state.
|
||||
* @return string The name of the state, or FALSE.
|
||||
*/
|
||||
function _addressfield_tokens_state($country, $state) {
|
||||
$states = _addressfield_tokens_states($country);
|
||||
|
||||
// State abbreviations will usually be two uppercase letters.
|
||||
$state = drupal_strtoupper($state);
|
||||
if (!empty($state) && !empty($states[$state])) {
|
||||
return $states[$state];
|
||||
}
|
||||
return $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_webform_component_info().
|
||||
*/
|
||||
function addressfield_tokens_webform_component_info() {
|
||||
$components = array ();
|
||||
$components['addressfield'] = array (
|
||||
'label' => t('Address'),
|
||||
'description' => t('Address field.'),
|
||||
'features' => array (
|
||||
// Add content to CSV downloads. Defaults to TRUE.
|
||||
'csv' => TRUE,
|
||||
// Show this component in e-mailed submissions. Defaults to TRUE.
|
||||
'email' => TRUE,
|
||||
// Allow this component to be used as an e-mail FROM or TO address.
|
||||
// Defaults to FALSE.
|
||||
'email_address' => FALSE,
|
||||
// Allow this component to be used as an e-mail SUBJECT or FROM name.
|
||||
// Defaults to FALSE.
|
||||
'email_name' => FALSE,
|
||||
// This component may be toggled as required or not. Defaults to TRUE.
|
||||
'required' => TRUE,
|
||||
// This component has a title that can be toggled as displayed or not.
|
||||
'title_display' => TRUE,
|
||||
// This component has a title that can be displayed inline.
|
||||
'title_inline' => FALSE,
|
||||
// If this component can be used as a conditional SOURCE. All components
|
||||
// may always be displayed conditionally, regardless of this setting.
|
||||
// Defaults to TRUE.
|
||||
'conditional' => FALSE,
|
||||
// If this component allows other components to be grouped within it
|
||||
// (like a fieldset or tabs). Defaults to FALSE.
|
||||
'group' => FALSE,
|
||||
// If this component can be used for SPAM analysis, usually with Mollom.
|
||||
'spam_analysis' => FALSE,
|
||||
// If this component saves a file that can be used as an e-mail
|
||||
// attachment. Defaults to FALSE.
|
||||
'attachment' => FALSE,
|
||||
),
|
||||
'file' => 'addressfield_tokens.components.inc',
|
||||
);
|
||||
return $components;
|
||||
}
|
||||
|
||||
function _addressfield_tokens_webform_components($nid) {
|
||||
$components = &drupal_static(__FUNCTION__, array());
|
||||
if (!isset($components[$nid])) {
|
||||
$components[$nid] = db_select('webform_component')
|
||||
->fields('webform_component')
|
||||
->condition('type', 'addressfield')
|
||||
->condition('nid', $nid)
|
||||
->execute()
|
||||
->fetchAllAssoc('cid', PDO::FETCH_ASSOC);
|
||||
}
|
||||
return $components[$nid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_webform_submission_load().
|
||||
*/
|
||||
function addressfield_tokens_webform_submission_load(&$submissions) {
|
||||
$submissions_reset = reset($submissions);
|
||||
$nid = $submissions_reset->nid;
|
||||
|
||||
$components = _addressfield_tokens_webform_components($nid);
|
||||
|
||||
foreach ($submissions as $sid => $submission) {
|
||||
foreach ($components as $cid => $component) {
|
||||
if (!empty($submission->data[$cid])) {
|
||||
$parents = array($cid);
|
||||
if (!empty($submission->data[$cid]['value'])) {
|
||||
$parents[] = 'value';
|
||||
}
|
||||
$addresses = array();
|
||||
foreach (drupal_array_get_nested_value($submission->data, $parents) as $delta => $data) {
|
||||
$data = empty($data) ? array() : unserialize($data);
|
||||
$addresses[$delta] = $data;
|
||||
}
|
||||
drupal_array_set_nested_value($submission->data, $parents, $addresses);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_webform_validator_alter().
|
||||
*/
|
||||
function addressfield_tokens_webform_validator_alter(&$validators) {
|
||||
$validators['unique']['component_types'][] = 'addressfield';
|
||||
$validators['oneoftwo']['component_types'][] = 'addressfield';
|
||||
$validators['oneofseveral']['component_types'][] = 'addressfield';
|
||||
}
|
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Implements theme_field();
|
||||
*
|
||||
* Themes an address according to the default renderer.
|
||||
*/
|
||||
function theme_addressfield_formatter($vars) {
|
||||
$address = $vars['address'];
|
||||
$handlers = $vars['handlers'];
|
||||
|
||||
$out = addressfield_generate($address, $handlers, array('mode' => 'render'));
|
||||
return '<div class="addressfield">' . render($out) . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements theme_field();
|
||||
*
|
||||
* Themes an address field into "city state, country"
|
||||
*/
|
||||
function theme_addressfield_formatter__citystate($vars) {
|
||||
$loc = $vars['address'];
|
||||
|
||||
// Determine which location components to render
|
||||
$out = array();
|
||||
if (!empty($loc['locality'])) {
|
||||
$out[] = $loc['locality'];
|
||||
}
|
||||
if (!empty($loc['administrative_area'])) {
|
||||
$out[] = $loc['administrative_area'];
|
||||
}
|
||||
if ($loc['country'] != addressfield_tokens_default_country() && $country_name = _addressfield_tokens_country($loc['country'])) {
|
||||
$out[] = $country_name;
|
||||
}
|
||||
|
||||
// If there's no location, render an alternate
|
||||
if (empty($out)) {
|
||||
$out[] = 'Undefined';
|
||||
}
|
||||
|
||||
// Render the location components
|
||||
$output = '<span class="addressfield-citystate">' . implode(', ', $out) . '</span>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements theme_field();
|
||||
*
|
||||
* Themes an address field into "name, street1, street2, city state zip country"
|
||||
*/
|
||||
function theme_addressfield_formatter__linear($vars) {
|
||||
$loc = $vars['address'];
|
||||
|
||||
// Determine which location components to render
|
||||
$out = array();
|
||||
if (!empty($loc['name_line']) && $vars['name_line']) {
|
||||
$out[] = $loc['name_line'];
|
||||
}
|
||||
if (!empty($loc['organisation_name']) && $vars['organisation_name']) {
|
||||
$out[] = $loc['organisation_name'];
|
||||
}
|
||||
if (!empty($loc['thoroughfare'])) {
|
||||
$out[] = $loc['thoroughfare'];
|
||||
}
|
||||
if (!empty($loc['premise']) && $vars['premise']) {
|
||||
$out[] = $loc['premise'];
|
||||
}
|
||||
if (!empty($loc['locality'])) {
|
||||
$out[] = $loc['locality'];
|
||||
}
|
||||
if (!empty($loc['administrative_area'])) {
|
||||
$out[] = $loc['administrative_area'];
|
||||
}
|
||||
if (!empty($loc['postal_code'])) {
|
||||
$out[] = $loc['postal_code'];
|
||||
}
|
||||
if ($loc['country'] != addressfield_tokens_default_country() && $country_name = _addressfield_tokens_country($loc['country'])) {
|
||||
$out[] = $country_name;
|
||||
}
|
||||
|
||||
// Render the location components
|
||||
$output = implode(', ', $out);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function theme_addressfield_formatter__components($vars) {
|
||||
$loc = $vars['address'];
|
||||
$components = $vars['components'];
|
||||
$separator = $vars['separator'];
|
||||
|
||||
$out = array();
|
||||
foreach ($components as $key) {
|
||||
if (!empty($loc[$key])) {
|
||||
$out[$key] = $loc[$key];
|
||||
}
|
||||
elseif ($key == 'country_full' && !empty($loc['country'])) {
|
||||
$out[$key] = _addressfield_tokens_country($loc['country']);
|
||||
}
|
||||
elseif ($key == 'administrative_area_full' && !empty($loc['country']) && !empty($loc['administrative_area'])) {
|
||||
$out[$key] = _addressfield_tokens_state($loc['country'], $loc['administrative_area']);
|
||||
}
|
||||
}
|
||||
|
||||
return filter_xss(implode($separator, $out));
|
||||
}
|
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
// $Id$
|
||||
/*
|
||||
* Copyright © 2012 New Signature
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
* You can contact New Signature by electronic mail at labs@newsignature.com -or- by U.S. Postal Service at 1100 H St. NW, Suite 940, Washington, DC 20005.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file Provides token replacements for address fields.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_token_info_alter().
|
||||
*
|
||||
* Attaches tokens to all addressfield properties. The default names of each
|
||||
* addressfield component can be altered by administrators according to the site's locale.
|
||||
*
|
||||
* @param array $info The existing token info.
|
||||
*/
|
||||
function addressfield_tokens_token_info_alter(&$info) {
|
||||
// Define the address field token types
|
||||
$info['types']['addressfield'] = array(
|
||||
'name' => t('Address field'),
|
||||
'description' => t('An address associated with an entity.'),
|
||||
'needs-data' => 'addressfield',
|
||||
);
|
||||
|
||||
// Add tokens for each component of the address
|
||||
$info['tokens'] += array( 'addressfield' => array() );
|
||||
|
||||
$props = addressfield_data_property_info();
|
||||
$names = addressfield_tokens_property_names();
|
||||
$params = array(
|
||||
'@default_country' => addressfield_tokens_default_country(),
|
||||
);
|
||||
|
||||
foreach ($props as $field => $data) {
|
||||
$fieldtoken = str_replace('_', '-', $field);
|
||||
$name = '';
|
||||
$descr = '';
|
||||
|
||||
if (!empty($names[$field])) {
|
||||
$name = $names[$field];
|
||||
$descr = $data['label'];
|
||||
}
|
||||
else {
|
||||
$name = $data['label'];
|
||||
$descr = $name;
|
||||
|
||||
$matches = array();
|
||||
if (preg_match('/^(.*)\s+\(i\.e\.\s+(.*)\)$/', $name, $matches)) {
|
||||
$name = $matches[1];
|
||||
$descr = $matches[2];
|
||||
}
|
||||
}
|
||||
$info['tokens']['addressfield'][$fieldtoken] = array(
|
||||
'name' => $name,
|
||||
'description' => $descr,
|
||||
'type' => 'text',
|
||||
);
|
||||
$params['@' . $field] = $name;
|
||||
}
|
||||
$info['tokens']['addressfield']['administrative-area']['name'] .= ' (abbreviation)';
|
||||
$info['tokens']['addressfield']['country']['name'] .= ' (abbreviation)';
|
||||
|
||||
// Add tokens for the formatted address and text-only version.
|
||||
$info['tokens']['addressfield'] += array(
|
||||
'full' => array(
|
||||
'name' => t('Formatted address'),
|
||||
'description' => t('The full formatted address.'),
|
||||
'type' => 'text',
|
||||
),
|
||||
'text' => array(
|
||||
'name' => t('Text-only address'),
|
||||
'description' => t('The full address with line breaks but no formatting.'),
|
||||
'type' => 'text',
|
||||
),
|
||||
'city-state' => array(
|
||||
'name' => t('City, State'),
|
||||
'description' => t('@locality and @administrative_area separated by commas (and @country if outside @default_country)', $params),
|
||||
'type' => 'text',
|
||||
),
|
||||
'state-name' => array(
|
||||
'name' => t('@administrative_area (full name)', $params),
|
||||
'description' => t('The full name of the @administrative_area', $params),
|
||||
'type' => 'text',
|
||||
),
|
||||
'country-name' => array(
|
||||
'name' => t('@country (full name)', $params),
|
||||
'description' => t('The full name of the @country', $params),
|
||||
'type' => 'text',
|
||||
),
|
||||
);
|
||||
|
||||
// Add user tokens that are useful for MailChimp.
|
||||
if (module_exists('mailchimp')) {
|
||||
$info['tokens']['addressfield'] += array(
|
||||
'mc-address' => array(
|
||||
'name' => t('MailChimp Address'),
|
||||
'description' => t('A full address formatted for integration with MailChimp.'),
|
||||
'type' => 'text',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Attach tokens to all address fields
|
||||
$valid_types = entity_token_types();
|
||||
$entity_info = entity_get_info();
|
||||
|
||||
foreach ($valid_types as $token_type => $type) {
|
||||
foreach (entity_get_all_property_info($type) as $name => $property) {
|
||||
$name = str_replace('_', '-', $name);
|
||||
|
||||
if (!isset($info['tokens'][$token_type][$name]) && isset($property['type']) && $property['type'] == 'addressfield') {
|
||||
$info['tokens'][$token_type][$name] = array(
|
||||
'name' => $property['label'],
|
||||
'type' => 'addressfield',
|
||||
'description' => isset($property['description']) ? $property['description'] : t('Address field'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_tokens().
|
||||
*
|
||||
* @param string $type The type of tokens to replace. We are looking for 'addressfield', but can also chain
|
||||
* addressfields onto entities that have addressfields as properties.
|
||||
* @param array $tokens The tokens to replace.
|
||||
* @param array $data The data to use as replacements. We are looking for an 'addressfield' property.
|
||||
* @param array $options Additional options for the tokenizer.
|
||||
*
|
||||
* @return array The replaced values.
|
||||
*/
|
||||
function addressfield_tokens_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$url_options = array();
|
||||
if (isset($options['language'])) {
|
||||
$url_options['language'] = $options['language'];
|
||||
$language_code = $options['language']->language;
|
||||
}
|
||||
else {
|
||||
$language_code = LANGUAGE_NONE;
|
||||
}
|
||||
$sanitize = !empty($options['sanitize']);
|
||||
$replacements = array();
|
||||
|
||||
// Process address field tokens
|
||||
if ($type == 'addressfield' && !empty($data['addressfield'])) {
|
||||
foreach ($tokens as $name => $original) {
|
||||
$name = str_replace('-', '_', $name);
|
||||
$address = $data['addressfield'];
|
||||
|
||||
// If the address field exists, use it.
|
||||
if (isset($address[$name])) {
|
||||
$replacements[$original] = $address[$name];
|
||||
}
|
||||
else {
|
||||
// Otherwise, it's a special token
|
||||
switch ($name) {
|
||||
case 'full':
|
||||
$render = addressfield_generate($address, array('address'), array(
|
||||
'mode' => 'render',
|
||||
));
|
||||
$replacements[$original] = drupal_render($render);
|
||||
break;
|
||||
|
||||
case 'text':
|
||||
$out = array();
|
||||
if (!empty($address['thoroughfare'])) {
|
||||
$out[0] = $address['thoroughfare'];
|
||||
}
|
||||
$out[1] = array();
|
||||
if (!empty($address['locality'])) {
|
||||
$out[1][] = $address['locality'];
|
||||
}
|
||||
if (!empty($address['administrative_area'])) {
|
||||
$out[1][] = $address['administrative_area'];
|
||||
}
|
||||
$out[1] = implode(', ', $out[1]);
|
||||
if (!empty($address['postal_code'])) {
|
||||
$out[1] .= ' ' . $address['postal_code'];
|
||||
}
|
||||
if (!empty($address['country']) && $address['country'] != addressfield_tokens_default_country()) {
|
||||
$out[2] = _addressfield_tokens_country($address['country']);
|
||||
}
|
||||
$replacements[$original] = implode("\n", $out);
|
||||
break;
|
||||
|
||||
case 'city_state':
|
||||
$out = array();
|
||||
if (!empty($address['locality'])) {
|
||||
$out[] = $address['locality'];
|
||||
}
|
||||
if (!empty($address['administrative_area'])) {
|
||||
$out[] = $address['administrative_area'];
|
||||
}
|
||||
if (!empty($address['country']) && $address['country'] != addressfield_tokens_default_country()) {
|
||||
$out[] = _addressfield_tokens_country($address['country']);
|
||||
}
|
||||
$replacements[$original] = implode(", ", $out);
|
||||
break;
|
||||
|
||||
case 'state_name':
|
||||
if (!empty($address['administrative_area']) && !empty($address['country'])) {
|
||||
$replacements[$original] = _addressfield_tokens_state($address['country'], $address['administrative_area']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'country_name':
|
||||
if (!empty($address['country'])) {
|
||||
$replacements[$original] = _addressfield_tokens_country($address['country']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mc_address':
|
||||
$address_components = array('thoroughfare', 'premise', 'locality', 'administrative_area', 'postal_code', 'country');
|
||||
$mc_address = array();
|
||||
foreach ($address_components as $component) {
|
||||
if (!empty($address[$component])) {
|
||||
$mc_address[] = check_plain($address[$component]);
|
||||
}
|
||||
}
|
||||
// MailChimp requires the address to be a string of double-space
|
||||
// delimited address fields. (http://kb.mailchimp.com/article/how-do-i-set-up-the-address-field-type-for-import)
|
||||
$replacements[$original] = !empty($mc_address) ? implode(' ', $mc_address) : '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isset($replacements[$original])) {
|
||||
$replacements[$original] = '';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$token_types = entity_token_types();
|
||||
$info = token_info();
|
||||
if (isset($info['tokens'][$type])) {
|
||||
// Otherwise, chain address fields attached to other entities
|
||||
foreach ($info['tokens'][$type] as $name => $token_info) {
|
||||
if (isset($token_info['type']) && $token_info['type'] == 'addressfield') {
|
||||
if ($chained_tokens = token_find_with_prefix($tokens, $name)) {
|
||||
$wrapper = !isset($wrapper) ? _entity_token_wrap_data($type, $token_types[$type], $data[$type], $options) : $wrapper;
|
||||
$property_name = str_replace('-', '_', $name);
|
||||
try {
|
||||
$address = $wrapper->$property_name->value();
|
||||
$replacements += token_generate('addressfield', $chained_tokens, array('addressfield' => $address), $options);
|
||||
}
|
||||
catch (EntityMetadataWrapperException $e) {
|
||||
// The property doesn't exist, so skip it.
|
||||
$replacements[$original] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $replacements;
|
||||
}
|
Reference in New Issue
Block a user