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
c1be7de9
Commit
c1be7de9
authored
14 years ago
by
Alex Barth
Browse files
Options
Downloads
Patches
Plain Diff
#623444 mongolito404, pvhee, pdrake, servantleader, alex_b et. al.: Mapper for link module.
parent
ec7ed737
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.txt
+2
-0
2 additions, 0 deletions
CHANGELOG.txt
mappers/link.inc
+84
-0
84 additions, 0 deletions
mappers/link.inc
tests/feeds_mapper_link.test
+177
-0
177 additions, 0 deletions
tests/feeds_mapper_link.test
with
263 additions
and
0 deletions
CHANGELOG.txt
+
2
−
0
View file @
c1be7de9
...
...
@@ -3,6 +3,8 @@
Feeds 6.x 1.0 XXXXXXXXXXXXXXXXXXXX
----------------------------------
- #623444 mongolito404, pvhee, pdrake, servantleader, alex_b et. al.: Mapper for
link module.
- #652180 ronald_istos, rjbrown99, et. al.: Assign author of imported nodes.
- #783098 elliotttf: Introduce hook_feeds_user_processor_targets_alter(), mapper
for user profile fields.
...
...
This diff is collapsed.
Click to expand it.
mappers/link.inc
0 → 100644
+
84
−
0
View file @
c1be7de9
<?php
// $Id$
/**
* @file
* On behalf implementation of Feeds mapping API for link.module (CCK).
*/
/**
* Implementation of hook_feeds_node_processor_targets_alter().
*/
function
link_feeds_node_processor_targets_alter
(
$targets
,
$content_type
)
{
$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
(
'link'
)))
{
$name
=
isset
(
$field
[
'widget'
][
'label'
])
?
$field
[
'widget'
][
'label'
]
:
$field_name
;
$targets
[
$field_name
.
':url'
]
=
array
(
'name'
=>
t
(
'!field_name (URL)'
,
array
(
'!field_name'
=>
$name
)),
'callback'
=>
'link_feeds_set_target'
,
'description'
=>
t
(
'The URL for the CCK !name field of the node.'
,
array
(
'!name'
=>
$name
)),
);
//Provides a mapping target for the field title if used.
if
(
in_array
(
$field
[
'title'
],
array
(
'optional'
,
'required'
)))
{
$targets
[
$field_name
.
':title'
]
=
array
(
'name'
=>
$name
.
' ('
.
t
(
'title'
)
.
')'
,
'callback'
=>
'link_feeds_set_target'
,
'description'
=>
t
(
'The title for the CCK !name field of the node.'
,
array
(
'!name'
=>
$name
)),
);
}
}
}
}
}
/**
* Callback for mapping to link field.
*
* @param $node
* Reference to the node object we are working on.
* @param $target
* The selected link CCK field.
* @param $value
* The value to assign to the CCK field.
*/
function
link_feeds_set_target
(
$node
,
$target
,
$value
)
{
if
(
!
empty
(
$value
))
{
static
$defaults
=
array
();
list
(
$field_name
,
$sub_field
)
=
split
(
':'
,
$target
);
if
(
!
isset
(
$defaults
[
$node
->
type
][
$field_name
]))
{
$field
=
content_fields
(
$field_name
,
$node
->
type
);
$defaults
[
$node
->
type
][
$field_name
][
'attributes'
]
=
$field
[
'attributes'
];
if
(
!
in_array
(
$field
[
'title'
],
array
(
'optional'
,
'required'
,
'none'
)))
{
$defaults
[
$node
->
type
][
$field_name
][
'title'
]
=
$field
[
'title_value'
];
}
}
$field_data
=
isset
(
$node
->
$field_name
)
?
$node
->
$field_name
:
array
();
if
(
!
is_array
(
$value
))
{
$value
=
array
(
$value
);
}
$i
=
0
;
foreach
(
$value
as
$v
)
{
if
(
$v
instanceof
FeedsEnclosure
)
{
$v
=
$v
->
getValue
();
}
if
(
!
isset
(
$field_data
[
$i
]))
{
$field_data
[
$i
]
=
$defaults
[
$node
->
type
][
$field_name
];
}
if
(
$sub_field
!=
'url'
||
((
$v
=
link_cleanup_url
(
$v
))
&&
valid_url
(
$v
,
true
)))
{
$field_data
[
$i
][
$sub_field
]
=
$v
;
}
$i
++
;
}
$node
->
$field_name
=
$field_data
;
}
}
This diff is collapsed.
Click to expand it.
tests/feeds_mapper_link.test
0 → 100644
+
177
−
0
View file @
c1be7de9
<?php
// $Id$
require_once
(
drupal_get_path
(
'module'
,
'feeds'
)
.
'/tests/feeds_mapper_test.inc'
);
/**
* Class for testing Feeds <em>link</em> mapper.
*/
class
FeedsMapperLinkTestCase
extends
FeedsMapperTestCase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
t
(
'Mapper: Link'
),
'description'
=>
t
(
'Test Feeds Mapper support for Link CCK fields'
),
'group'
=>
t
(
'Feeds'
),
);
}
/**
* Set up the test.
*/
public
function
setUp
()
{
// Call parent setup with the required module
parent
::
setUp
(
'devel'
,
'feeds'
,
'feeds_ui'
,
'ctools'
,
'content'
,
'link'
);
// Create user and login
$this
->
drupalLogin
(
$this
->
drupalCreateUser
(
array
(
'administer content types'
,
'administer feeds'
,
'administer nodes'
,
'administer site configuration'
,
'access devel information'
)
));
}
/**
* Basic test loading a single entry CSV file.
*/
public
function
test
()
{
$static_title
=
$this
->
randomName
();
// Create content type.
$typename
=
$this
->
createContentType
(
NULL
,
array
(
'alpha'
=>
array
(
'type'
=>
'link'
,
'settings'
=>
array
(
'title'
=>
'required'
,
'multiple'
=>
'0'
,
),
),
'beta'
=>
array
(
'type'
=>
'link'
,
'settings'
=>
array
(
'title'
=>
'none'
,
'multiple'
=>
'0'
,
),
),
'gamma'
=>
array
(
'type'
=>
'link'
,
'settings'
=>
array
(
'title'
=>
'optional'
,
'multiple'
=>
'0'
,
),
),
'omega'
=>
array
(
'type'
=>
'link'
,
'settings'
=>
array
(
'title'
=>
'value'
,
'title_value'
=>
$static_title
,
'multiple'
=>
'0'
,
),
),
));
//Create importer configuration
$this
->
createFeedConfiguration
();
//Create a default importer configuration
$this
->
setSettings
(
'syndication'
,
'FeedsNodeProcessor'
,
array
(
'content_type'
=>
$typename
));
//Processor settings
$this
->
addMappings
(
'syndication'
,
array
(
array
(
'source'
=>
'title'
,
'target'
=>
'title'
),
array
(
'source'
=>
'timestamp'
,
'target'
=>
'created'
),
array
(
'source'
=>
'description'
,
'target'
=>
'body'
),
array
(
'source'
=>
'url'
,
'target'
=>
'field_alpha:url'
),
array
(
'source'
=>
'title'
,
'target'
=>
'field_alpha:title'
),
array
(
'source'
=>
'url'
,
'target'
=>
'field_beta:url'
),
array
(
'source'
=>
'url'
,
'target'
=>
'field_gamma:url'
),
array
(
'source'
=>
'title'
,
'target'
=>
'field_gamma:title'
),
array
(
'source'
=>
'url'
,
'target'
=>
'field_omega:url'
),
));
// Import RSS file.
$nid
=
$this
->
createFeedNode
();
// Assert 10 items aggregated after creation of the node.
$this
->
assertText
(
'Created 10 '
.
$typename
.
' nodes.'
);
// Edit the imported node.
$this
->
drupalGet
(
'node/2/edit'
);
$url
=
'http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating'
;
$title
=
'Open Atrium Translation Workflow: Two Way Translation Updates'
;
$this
->
assertCCKFieldValue
(
'alpha'
,
array
(
'url'
=>
$url
,
'static'
=>
$title
));
$this
->
assertCCKFieldValue
(
'beta'
,
array
(
'url'
=>
$url
));
$this
->
assertCCKFieldValue
(
'gamma'
,
array
(
'url'
=>
$url
,
'static'
=>
$title
));
$this
->
assertCCKFieldValue
(
'omega'
,
array
(
'url'
=>
$url
,
'static'
=>
$static_title
));
// Test the static title.
$this
->
drupalGet
(
'node/2'
);
$this
->
assertText
(
$static_title
,
'Static title link found.'
);
}
/**
* Override parent::getFormFieldsNames().
*/
protected
function
getFormFieldsNames
(
$field_name
,
$index
)
{
if
(
in_array
(
$field_name
,
array
(
'alpha'
,
'beta'
,
'gamma'
,
'omega'
)))
{
$fields
=
array
(
"field_
{
$field_name
}
[
{
$index
}
][url]"
);
if
(
in_array
(
$field_name
,
array
(
'alpha'
,
'gamma'
)))
{
$fields
[]
=
"field_
{
$field_name
}
[
{
$index
}
][title]"
;
}
return
$fields
;
}
else
{
return
parent
::
getFormFieldsNames
(
$field_name
,
$index
);
}
}
/**
* Override parent::getFormFieldsValues().
*/
protected
function
getFormFieldsValues
(
$field_name
,
$value
)
{
$field
=
content_fields
(
$field_name
);
if
(
in_array
(
$field_name
,
array
(
'alpha'
,
'beta'
,
'gamma'
,
'omega'
)))
{
if
(
!
is_array
(
$value
))
{
$value
=
array
(
'url'
=>
$value
);
}
$values
=
array
(
$value
[
'url'
]);
if
(
in_array
(
$field_name
,
array
(
'alpha'
,
'gamma'
)))
{
$values
[]
=
isset
(
$value
[
'title'
])
?
$value
[
'title'
]
:
''
;
}
return
$values
;
}
else
{
return
parent
::
getFormFieldsValues
(
$field_name
,
$index
);
}
}
}
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