Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
feeds
Commits
dc2655cc
Commit
dc2655cc
authored
14 years ago
by
Alex Barth
Browse files
Options
Downloads
Patches
Plain Diff
#838018 infojunkie: Mapper for Formatted Number CCK field.
parent
fb1a3853
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.txt
+1
-0
1 addition, 0 deletions
CHANGELOG.txt
mappers/formatted_number.inc
+54
-0
54 additions, 0 deletions
mappers/formatted_number.inc
tests/feeds_mapper_formatted_number.test
+102
-0
102 additions, 0 deletions
tests/feeds_mapper_formatted_number.test
with
157 additions
and
0 deletions
CHANGELOG.txt
+
1
−
0
View file @
dc2655cc
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
Feeds 6.x 1.X XXXX
Feeds 6.x 1.X XXXX
------------------
------------------
- #838018 infojunkie: Mapper for Formatted Number CCK field.
- #856408 c.ex: Pass all $targets for hook_feeds_node_processor_targets_alter()
- #856408 c.ex: Pass all $targets for hook_feeds_node_processor_targets_alter()
by reference.
by reference.
- #853194 andrewlevine, alex_b: Mapping: don't reset all targets.
- #853194 andrewlevine, alex_b: Mapping: don't reset all targets.
...
...
This diff is collapsed.
Click to expand it.
mappers/formatted_number.inc
0 → 100644
+
54
−
0
View file @
dc2655cc
<?php
// $Id$
/**
* @file
* On behalf implementation of Feeds mapping API for Formatted Number CCK.
*/
/**
* Implementation of feeds_node_processor_target_alter().
*/
function
formatted_number_feeds_node_processor_targets_alter
(
&
$targets
,
$content_type
)
{
if
(
module_exists
(
'formatted_number'
))
{
$info
=
content_types
(
$content_type
);
$fields
=
array
();
if
(
isset
(
$info
[
'fields'
])
&&
count
(
$info
[
'fields'
]))
{
foreach
(
$info
[
'fields'
]
as
$field_name
=>
$field
)
{
if
(
in_array
(
$field
[
'type'
],
array_keys
(
formatted_number_get_fields_info
())))
{
$fields
[
$field_name
]
=
isset
(
$field
[
'widget'
][
'label'
])
?
$field
[
'widget'
][
'label'
]
:
$field_name
;
}
}
}
foreach
(
$fields
as
$k
=>
$name
)
{
$targets
[
$k
]
=
array
(
'name'
=>
$name
,
'callback'
=>
'formatted_number_feeds_set_target'
,
'description'
=>
t
(
'The CCK !name field of the node.'
,
array
(
'!name'
=>
$name
)),
);
}
}
}
/**
* Set the CCK field target after import.
*/
function
formatted_number_feeds_set_target
(
$node
,
$target
,
$value
)
{
$field
=
isset
(
$node
->
$target
)
?
$node
->
$target
:
array
();
// Handle multiple value fields.
if
(
is_array
(
$value
))
{
$i
=
0
;
foreach
(
$value
as
$v
)
{
if
(
!
is_array
(
$v
)
&&
!
is_object
(
$v
))
{
$field
[
$i
][
'value'
]
=
parse_formatted_number
(
$v
,
TRUE
);
}
$i
++
;
}
}
else
{
$field
[
0
][
'value'
]
=
parse_formatted_number
(
$value
,
TRUE
);
}
$node
->
$target
=
$field
;
}
This diff is collapsed.
Click to expand it.
tests/feeds_mapper_formatted_number.test
0 → 100644
+
102
−
0
View file @
dc2655cc
<?php
// $Id$
/**
* @file
* Test case for simple CCK field mapper mappers/content.inc.
*/
require_once
(
drupal_get_path
(
'module'
,
'feeds'
)
.
'/tests/feeds_mapper_test.inc'
);
/**
* Class for testing Feeds <em>formatted_number</em> mapper.
*/
class
FeedsMapperFormattedNumberTestCase
extends
FeedsMapperTestCase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
t
(
'Mapper: Formatted Number'
),
'description'
=>
t
(
'Test Feeds Mapper support for Formatted Number CCK fields. <strong>Requires CCK, Format Number API and Formatted Number CCK modules</strong>.'
),
'group'
=>
t
(
'Feeds'
),
);
}
/**
* Set up the test.
*/
function
setUp
()
{
// Call parent setup with required modules.
parent
::
setUp
(
'feeds'
,
'feeds_ui'
,
'ctools'
,
'content'
,
'format_number'
,
'formatted_number'
);
// Create user and login.
$this
->
drupalLogin
(
$this
->
drupalCreateUser
(
array
(
'administer content types'
,
'administer feeds'
,
'administer nodes'
,
'administer site configuration'
)
));
}
/**
* Basic test loading a doulbe entry CSV file.
*/
function
test
()
{
// Create content type.
$typename
=
$this
->
createContentType
(
NULL
,
array
(
'beta'
=>
array
(
'type'
=>
'formatted_integer'
,
'widget'
=>
'formatted_number'
),
'gamma'
=>
array
(
'type'
=>
'formatted_decimal'
,
'widget'
=>
'formatted_number'
),
'delta'
=>
array
(
'type'
=>
'formatted_float'
,
'widget'
=>
'formatted_number'
),
));
// Create and configure importer.
$this
->
createFeedConfiguration
(
'Content CSV'
,
'csv'
);
$this
->
setSettings
(
'csv'
,
NULL
,
array
(
'content_type'
=>
''
,
'import_period'
=>
FEEDS_SCHEDULE_NEVER
,));
$this
->
setPlugin
(
'csv'
,
'FeedsFileFetcher'
);
$this
->
setPlugin
(
'csv'
,
'FeedsCSVParser'
);
$this
->
setSettings
(
'csv'
,
'FeedsNodeProcessor'
,
array
(
'content_type'
=>
$typename
));
$this
->
addMappings
(
'csv'
,
array
(
array
(
'source'
=>
'title'
,
'target'
=>
'title'
,
),
array
(
'source'
=>
'created'
,
'target'
=>
'created'
,
),
array
(
'source'
=>
'body'
,
'target'
=>
'body'
,
),
array
(
'source'
=>
'beta'
,
'target'
=>
'field_beta'
,
),
array
(
'source'
=>
'gamma'
,
'target'
=>
'field_gamma'
,
),
array
(
'source'
=>
'delta'
,
'target'
=>
'field_delta'
,
),
));
// Import CSV file.
$this
->
importFile
(
'csv'
,
$this
->
absolutePath
()
.
'/tests/feeds/content.csv'
);
$this
->
assertText
(
'Created 2 '
.
$typename
.
' nodes.'
);
// Check the two imported files.
$this
->
drupalGet
(
'node/1/edit'
);
$this
->
assertCCKFieldValue
(
'beta'
,
'42'
);
$this
->
assertCCKFieldValue
(
'gamma'
,
'4.20'
);
$this
->
assertCCKFieldValue
(
'delta'
,
'3.14'
);
$this
->
drupalGet
(
'node/2/edit'
);
$this
->
assertCCKFieldValue
(
'beta'
,
'32'
);
$this
->
assertCCKFieldValue
(
'gamma'
,
'1.20'
);
$this
->
assertCCKFieldValue
(
'delta'
,
'5.63'
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment