First, remarkable how usable the D7a2 release is, congratulations.

I nearly described this as a bug but wasn't sure. AIUI, previous issues have made sure that when a node is created, the summary will be generated. But the summary (teaser) is a separate field and it seems like it ought to be possible also to map to it.

Based on http://drupal.org/node/622700#comment-3669444 I got as far as this mini-module to retrofit it:

<?php
function mymodule_enable() {
 
cache_clear_all('plugins:feeds:plugins', 'cache');
}
function
mymodule_feeds_processor_targets_alter(&$targets, $content_type) {
 
$targets['summary'] = array(
   
'name' => t('Summary'),
   
'description' => t('Overrides the automatically generated teaser of the node.'),
   
'callback' => 'mymodule_set_target',
  );
}
function
mymodule_set_target($node, $target, $value) {
  if (!
is_array($value)) {
   
$node->body['und'][0]['summary'] = $value;
  }
}
?>

but although the first function works (having renamed the hook from the one in the manual) the second doesn't seem to do anything.

Any clues gratefully received.

Files: 
CommentFileSizeAuthor
#30 feeds-map-text-with-summary-962912-30.patch8.76 KBMegaChriz
PASSED: [[SimpleTest]]: [MySQL] 5,363 pass(es).
[ View ]
#23 feeds-map-text-with-summary-962912-23.patch9.74 KBMegaChriz
PASSED: [[SimpleTest]]: [MySQL] 4,672 pass(es).
[ View ]
#11 node-summary-mapper-962912-11.patch1.38 KBPeacog
PASSED: [[SimpleTest]]: [MySQL] 3,705 pass(es).
[ View ]
#9 962912-explicit-summary-mapping-9.patch1.47 KBNiklas Fiekas
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 962912-explicit-summary-mapping-9.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

Status:Active» Needs work

Mapping to summary should be a part of the summary text field mapper in mappers/field.inc.

Hey Alex, I don't see the option to map to the summary field in Feeds. I'm using version Feeds 7.x-2.x-dev and drupal 7.2 Am I missing something? What addition/change to the file.inc file would I nned to make to see that field for the mapper using node import and a csv?

Thanks.

subscribe

Hey,
I need this functionality as well. Has anyone made any progress towards getting this to work?

Thanks.

Subscribing - I need this, too.

i would be more than willing to contribute paypal to the maintianers for a patch. I really need this.

thanks.

I was trying the equivalent on the theme layer. I discovered that ['und'] is not there when you try to use it.
Here is the preprocess function I made:

<?php
function videomaker_preprocess_node(&$vars) {
 
// makes the summary easily available to print in the node-template as a new node variable $vm_summary
 
if($vars['type'] == 'magazine_article') {
 
$vars['vm_summary'] = $vars['body']['0']['safe_summary'];
  }
}
?>

hey taiger, could you explain how i would apply your code to feeds and which file so I could map a field in my csv to the summary?

thanks.

Status:Needs work» Needs review
StatusFileSize
new1.47 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 962912-explicit-summary-mapping-9.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Put @willmoy's code in a patch. Not so confident this is the correct place to do it, but it seems to work.

Thanks Niklas, it works fine with Feeds 7.x-2.0-alpha5. I am now trying to find a way to make it multilingual using feeds entity translation.

Version:7.x-2.0-alpha2» 7.x-2.0-alpha7
StatusFileSize
new1.38 KB
PASSED: [[SimpleTest]]: [MySQL] 3,705 pass(es).
[ View ]

Thanks for the patch, I have re-rolled it for 7.x-2.0-alpha7, which replaces field.inc with two files, text.inc and number.inc.

Patch in #11 worked for me.

This worked for me too - Thank you!
I'm surprised more people haven't registered that this functionality was missing.

Am not sure if I am missing something here. I have version 7.x-2.0 alpha 7 and I cannot see where to go to make the summary entry seperate from the main Body.

In the mapping there is not option to map the Summary field.

After you apply the patch in #11 you should see Body (Summary) immediately below Body in the dropdown list of targets when you add a mapping. If you have renamed to Body field, (for example you might have called it Description) then you'll see Description (Summary).

I think issue #1329626: Auto generate body_summary for node on import? deals with the exact same problem.

Patch #11 works fine.

I see that language is hard coded in multiple places.
For example 'und' in following piece of code ...
$entity->{$target}['und'][$i]['summary'] = $v;

I wonder if there is better way?

#11 worked for me as well. Thank you!

I'm having a bit of an issue after applying this patch. My body text is filtered HTML. It would import fine before applying this patch. After applying the patch the summary goes in fine, but the body no longer imports. (Not sure if the filtered HTML has anything to do with it.)

Any ideas?

Status:Needs review» Reviewed & tested by the community

Ok, scrap that last comment. It does work. However there's an important point here and that is that the summary must go after the body in the mapping, otherwise it doesn't work.

Otherwise I can confirm that this patch works.

Version:7.x-2.0-alpha7» 7.x-2.x-dev
Status:Reviewed & tested by the community» Needs work

This patch uses the older style of mapping. Also, the comment from #20 means that it needs serious work. We cannot have order dependent mappings. This needs to be rolled against dev.

Patch #11 is still working against the latest dev, but does appear to need some work to bring it up to par.

Status:Needs work» Needs review
StatusFileSize
new9.74 KB
PASSED: [[SimpleTest]]: [MySQL] 4,672 pass(es).
[ View ]

This patch is based on the patch in #23 of #1329626: Auto generate body_summary for node on import?.

What this patch does:

Other then the patch in #11 of this issue, the mappings can be defined in any order (I tested this manually).

The patch still uses the old style of mapping as mentioned in #21. It doesn't add any mapping config as I thought that didn't make sense for this case. In UI terms of speaking, the summary field looks like it is an other field.

The trimming option is left out
The patch from #23 in #1329626: Auto generate body_summary for node on import? also added an option to trim the summary with text_summary(). If that should get back in, then that would be candidate for a mapping option. I didn't see a reason to keep that option though, because why should you want to trim data to be imported with the text_summary() function? If you want to trim data, then you can also use the Feeds Tamper module for that. So I left that out for this patch.

Status:Needs review» Needs work

Thanks for consolidating issues.

  1. +++ b/mappers/text.inc
    @@ -11,21 +11,32 @@
    -  $text_types = array(
    -    'list_text',
    -    'text',
    -    'text_long',
    -    'text_with_summary',
    -  );
    ...
    -    if (in_array($info['type'], $text_types)) {
    -      $targets[$name] = array(
    -        'name' => check_plain($instance['label']),
    -        'callback' => 'text_feeds_set_target',
    -        'description' => t('The @label field of the entity.', array('@label' => $instance['label'])),
    -      );

    This should stay the same. We should just add an extra check after for the summary target.

  2. +++ b/mappers/text.inc
    @@ -77,3 +88,68 @@ function text_feeds_set_target($source, $entity, $target, $value) {
    + * Callback for mapping fields of type "text_with_summary".
    + */
    +function text_with_summary_feeds_set_target($source, $entity, $target, $value, $mapping = array()) {
    +  // Handle non-multiple value fields.
    +  if (!is_array($value)) {
    +    $value = array($value);
    +  }
    +
    +  // @todo In issue #1588938, setting a text format per field is proposed.
    +  // If that gets in, this piece must be rewritten.
    +  // @see https://drupal.org/node/1588938.

    This entire function is unneeded. Mapping to value, or summary should be the same operation.

We can set the default column to 'value' by doing, list($field_name, $column) = explode(':', $target . ':value')

@see file.inc

@twistor
Your feedback makes sense. I'd like to provide a new patch for this issue, but maybe I should wait to see where #2093651: Simplify target callbacks. will go to as an eventually new patch provided here would conflict with the patch provided there (same piece of code is touched).

EDIT: linked to wrong issue.

Hi. I applied the patch in #23 and I now see Body: Summary in the list of targets in the Mappings section of the the config of a Feeds Importer instance. This is good! I can also define a Command in Parser Settings, map that command to Body: Summary, set a default value for this Command in my Mailhandler Source instance, and now when I import nodes from email, the Body: Summary is filled in with my default value. All good!
I also now no longer get the "Notice: Undefined index: summary in node_tokens() (line 142 of..." entry in watchdog when I import emails into Group Posts. (that's what got me to this post). Not sure if the patch in #23 was expected to do all of this, but works for me.
My question is: the comments above mention a new vs old style of mapping config. Where are the two types discussed? What version of Feeds has the new config?
Thanks

Issue summary:View changes

The latest patch in #2093651: Simplify target callbacks. was committed, and #23 still applies cleanly and seems to work. Looks like it's safe for @MegaChriz to provide an update.

Assigned:Unassigned» MegaChriz

@byrond
Thanks for the notification. I've added this issue to my agenda. I don't have time to provide an update right now, but hopefully in about 2-3 weeks.

Status:Needs work» Needs review
StatusFileSize
new8.76 KB
PASSED: [[SimpleTest]]: [MySQL] 5,363 pass(es).
[ View ]

This patch addresses the issues in #25. I had token mappers/file.inc as an example.

It also splits the automated test FeedsMapperNodeSummaryTestCase into two test methods, because in that test two types of behavior are tested: if mapping to summary works and if the summary gets cleared out when the imported value is empty.

Assigned:MegaChriz» Unassigned

The patch (both 30 and 23) fails at the latest version of feeds (7.x-2.0-alpha8).
File: feeds.info --> ok
File: mappers/text.inc --> FAILED

Keep up the good work, I really need this mapper.