For my current project I have a node type that doesn't include any images in the node body, but does output images attached to nodes associated to this node via a node reference field. Since the node body had no images and the node itself has no image fields, the og:image tag wasn't being added. I needed a way to suggest my own images to be harvested.

I saw a few issues that suggest a similar use case, but didn't see any fixes:

I would like to propose a new hook for altering the image harvesting that harvest_images_from_node() does. I will attach a patch shortly.

Comments

jemond’s picture

Status: Active » Needs review
StatusFileSize
new619 bytes

Patch attached for consideration.

foxtrotcharlie’s picture

Thanks for the patch - it works for me. I was able to implement a custom function using the new hook to use a nodereference image. I tested on 6.x-1.7.

jemond’s picture

Sweet. Now only if we can get this committed...

torotil’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Issue summary: View changes
Status: Needs review » Needs work

I think that's a good idea. Could you port the patch to 7.x-2.x?

arunkumark’s picture

Status: Needs work » Needs review
StatusFileSize
new445 bytes

Hi,

I have also faced similar scenario for my project to alter facebook image. So, i have created a patch for the Drupal 7.x version.

To alter the image we need to implement the hook_opengraph_meta_harvest_images_alter().

Example:

/**
 * Implements hook_opengraph_meta_harvest_images_alter().
 */
function mymodule_opengraph_meta_harvest_images_alter(&$ret, &$node, &$body) {
  $ret[$key]['title'] = 'https://www.example.com/sites/default/files/image1.jpg';
  $ret[$key]['url'] = 'https://www.example.com/sites/default/files/image1.jpg';
  $ret[$key]['alt'] = 'https://www.example.com/sites/default/files/image1.jpg';
}