Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
drupal.org
email
Commits
31bb57a4
Commit
31bb57a4
authored
May 10, 2012
by
Matthias Hutterer
Browse files
Issue #718414 by johnv: Added feeds mapper for email field.
parent
523cd0de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
email.feeds.inc
email.feeds.inc
+55
-0
No files found.
email.feeds.inc
0 → 100644
View file @
31bb57a4
<?php
/**
* @file
* Integration with the Feeds module.
*/
/**
* Implements hook_feeds_processor_targets_alter().
*
* @see FeedsNodeProcessor::getMappingTargets().
*/
function
email_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
(
in_array
(
$info
[
'type'
],
array
(
'email'
)))
{
$targets
[
$name
]
=
array
(
'name'
=>
$instance
[
'label'
],
'callback'
=>
'email_feeds_set_target'
,
'description'
=>
t
(
'The @label field of the node.'
,
array
(
'@label'
=>
$instance
[
'label'
])),
);
}
}
}
/**
* Callback function for mapping email field.
*
* This function is invoked via hook_feeds_processor_targets_alter().
* Here is where the actual mapping happens.
*
* @param $target
* the name of the field the user has decided to map to.
* @param $value
* the value of the feed item element the user has picked as a source.
*/
function
email_feeds_set_target
(
$source
,
$entity
,
$target
,
$value
)
{
$value
=
is_array
(
$value
)
?
$value
:
array
(
$value
);
$info
=
field_info_field
(
$target
);
// Iterate over all values.
$i
=
0
;
$field
=
isset
(
$entity
->
$target
)
?
$entity
->
$target
:
array
();
foreach
(
$value
as
$v
)
{
if
(
!
is_array
(
$v
)
&&
!
is_object
(
$v
))
{
$field
[
LANGUAGE_NONE
][
$i
][
'email'
]
=
$v
;
}
if
(
$info
[
'cardinality'
]
==
1
)
{
break
;
}
$i
++
;
}
$entity
->
{
$target
}
=
$field
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment