Support from Acquia helps fund testing for Drupal Acquia logo

Comments

axe312’s picture

/signed

and please add support that the default image can be ALLWAYS taken instead of cck field-image

thank u :)

hiddentao’s picture

I could add a field to the Open Graph admin pages which allows you to specify a default image to use for all nodes which don't have an image of their own. Will this do?

axe312’s picture

Yeah that would be awesome!

Please also add a checkbox where the admin can choose if that image is allways taken or only when the node has no image.

thx :)

jlea9378’s picture

I'm interested in this feature also. =)

thewoodm’s picture

I would also LOVE to see this feature. The implementation suggestion in #2 would be perfect.

hiddentao’s picture

Assigned: Unassigned » hiddentao
Priority: Normal » Major
hiddentao’s picture

Status: Active » Needs review

I've added a simple text field to the admin screen in which you can specify the URL to a fallback image you can use in case if the node doesn't have an image attached (or in its body). I did consider allowing for an image to be uploaded but I didn't want to restrict it that way - with the text field solution you can use any image from anywhere.

@axe312 I've assumed for now that if a node doesn't have an image of its own to use then the fallback image will be used. If enough people want the checkbox added in I can do that too.

hiddentao’s picture

Assigned: hiddentao » Unassigned
jlea9378’s picture

The default image seems to work great except if you override it on a node it seems to still use the default image.

What we (at my organization) want is that it always uses the fallback/default image unless someone overrides it on a specific page. I'm not sure if that was your original intention with your proposed solution or not?

Thanks for working on this!

jlea9378’s picture

Version: 6.x-1.x-dev » 6.x-1.5
hiddentao’s picture

@jlea9378 It definitely shouldn't be doing that. If you set an image specifically within a node it should use that image rather than the default image. Are you sure you've selected a specific thumbnail in your node to be the og:image?

jlea9378’s picture

Yup. The radio button beside the image under "Open Graph meta tags (e.g. for Facebook sharing)" "Thumbnail Image" is filled and I saved. But it still uses the default image.

Unless the fact that it can't find the image is part of the problem? This is what it is trying to load next to the radio button: http://sites/default/files/images/5052740428_f6687f5c9c_s.jpg

el_reverend’s picture

Title: Default Image » Default / Fallback Image
Issue tags: +facebook, +meta, +og:image, +OpenGraph

I can confirm jlea9378's comment, that the default or fallback image will always be used even when assigning an image from within the node (in my case a custom blog post).

I have also noticed that the Fallback Image will not show up in Facebook with either a relative or absolute path. The specified image path however is present in the HTML og:image tag, and is accessable directly via URL. This may be a problem on FB however.

jlea9378’s picture

Found a problem with the default/fallback image. It seems to stop working if you change the URL of the image. We recently changed our logo so I had to change the URL in the Default/Fallback Image field and it caused the wrong images to be sent to facebook. I looked at the og:image tag on some of the pages and it was using the images off the pages in most cases.

Completely uninstalling and reinstalling the module seemed to fix it.

Edit: However on pages that I previously had clicked to "Share on Facebook", facebook brought up the old image even though the og:image tag said to use the new image. Checking the page via the Facebook Linter (http://developers.facebook.com/tools/lint) fixed it and made it load the new image. I suspect this is caused by facebook caching the image for a given URL.

jlea9378’s picture

Status: Needs review » Needs work

Still seems to be some issues with this. Sometimes the fallback image isn't being used even though it should be. As far as I can tell this page should be using the fallback image but it's not. The og:image tag shows a different image.
http://www.clatsopcc.edu/about-ccc/press-releases/congratulations-year-s...

kurth’s picture

Version: 6.x-1.5 » 6.x-1.x-dev
Assigned: Unassigned » kurth
Priority: Major » Normal
Status: Needs work » Needs review
FileSize
3.07 KB

Greetings everyone!

I had a client requirement to force the "Fallback Image" to be displayed regardless of any other images available in the node. So I did just that and am sharing with you. :]

This patch adds a checkbox under the "Fallback Image" field, allowing the user to force the use of the fallback image regardless of other images available.

This patch was developed for Koumbit.org

This is my first contribution, so your constrictive feedback is appreciated.

~k

jlea9378’s picture

I checked the box on the Open Graph Meta settings page to always use the Fallback Image. When viewing a node, I got this:

warning: Missing argument 2 for OGMDrupalSettings::get(), called in /var/www/html/drupal_test/sites/all/modules/opengraph_meta/opengraph_meta.common.inc on line 148 and defined in /var/www/html/drupal_test/sites/all/modules/opengraph_meta/opengraph_meta.common.inc on line 361.

lyricnz’s picture

#17: you need to modify line 148 of opengraph_meta.common.inc - add a FALSE to the end of the function call

Index: sites/all/modules/opengraph_meta/opengraph_meta.common.inc
===================================================================
--- sites/all/modules/opengraph_meta/opengraph_meta.common.inc	(revision 5734)
+++ sites/all/modules/opengraph_meta/opengraph_meta.common.inc	(working copy)
@@ -131,7 +131,7 @@
 
       $ret[self::TYPE] = $this->settings_obj->get(OPENGRAPH_META_VAR_CONTENT_TYPE_.$node->type,'');
 
-      if (!$this->settings_obj->get(OPENGRAPH_META_VAR_FALLBACK_IMG_FORCE)) {
+      if (!$this->settings_obj->get(OPENGRAPH_META_VAR_FALLBACK_IMG_FORCE, FALSE)) {
         $image_paths = $this->harvest_images_from_node($node);
         if (!empty($image_paths))
           $ret[self::IMAGE] = array_shift($image_paths);
jlea9378’s picture

Thanks, that fixed it. The patch (with the fix in #18) seems to work great. I tested it on a dozen or so pages and the correct image was sent to facebook every time.

kurth’s picture

@lyricnz Thank you for picking that up. :]

I've attached a new patch, with the change implemented in #18

Thank You.

jlea9378’s picture

Seems to work great with the patch in #20. I just applied it to the latest dev release and tested it on a bunch of pages on my site.

hiddentao’s picture

That's great on the 'always force fallback image' work. If there's enough demand for this I can put this into the next release. Or better yet perhaps a hook can be added to the tag rendering function so that anyone wanting to override tag output values can simply intercept that hook.

jlea9378’s picture

Attached are patches to add kurth's force feature to the module in drupal 7.x-1.x-dev. Sorry I don't know how to make a patch using cvs, so it's just a diff from my filesystem.

edit: Not sure why it is giving Page Not Found...

jlea9378’s picture

Reposting. This is for 7.x-1.x-dev:

bkosborne’s picture

Can we get these commit? This is a great feature, being able to specify a specific the node use the default instead of one from the fields.

fmitchell’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
FileSize
3.55 KB

@24 patch didn't work for me.

We needed on more component to check as it will set the pulled image if it already exists. Coincidentally, when I updated my module to 7.x-1.x, an alter hook was called, so this patch really isn't needed. I"m attaching it anyways since I only found the alter after the fact.

This patch includes @24, so you should only need this one.

jlea9378’s picture

Status: Needs review » Reviewed & tested by the community

I installed the latest Drupal 7 dev release (May 20th) and applied the patch in #26. It worked great. I would love to see this patch included in the next dev release.

jlea9378’s picture

I installed Open Graph meta tags 6.x-1.x-dev (2012-May-19), however the patch in #20 no longer works. It looks like part of the patch might already be implemented in this latest dev release, however not all of it is. Specifically, the option to force the fallback image that appears on the admin ui is missing.

jlea9378’s picture

Status: Reviewed & tested by the community » Needs review

I was getting an error when I attempted to update one of our pages that has 4 images on it, stating that my selection was invalid. This error was referring to the Opengraph Meta image selection. It was harvesting the images and showing the 4 images as selections, despite the Force Fallback being enabled. I took a look through the code and noticed that the patch does not change any of the code in opengraph_meta.module. It looks to me like some changes are needed in this file in the opengraph_meta_form_alter function. The following changes seem to work for me.

Before:

    // if we have images in this node then show thumbnail selector
    $images = OpenGraphMeta::instance()->harvest_images_from_node($node);
    if (!empty($images)) {
      $image_selector_options = array();
      foreach ($images as $image) {
        $image_selector_options[$image['url']] = OpenGraphMetaDrupalLayer::theme_selector_image($image);
      }
      $form['opengraph_meta'][OpenGraphMeta::IMAGE] = array(
        '#title' => t('Thumbnail image'),
        '#type' => 'radios',
        '#default_value' => !empty($node->opengraph_meta) ? $node->opengraph_meta[OpenGraphMeta::IMAGE] : '',
        '#description' => t('The thumbnail image that will get shown in e.g. a Facebook preview. If left unset then then the first available image will be used. If none available then the global fallback image will be used.'),
        '#options' => $image_selector_options,
        '#attributes' => array('class' => array('opengraph-thumbs-wrapper','clearfix')),
      );
    }
  }
}

After:

    // if we have images in this node then show thumbnail selector
    $image_selector_options = array();
    $objs = OpenGraphMeta::instance()->__get_objects();
    $image_selector_options[$image['url']] = $objs[1]->get(OPENGRAPH_META_VAR_FALLBACK_IMG, '');
    
  if(!$objs[1]->get(OPENGRAPH_META_VAR_FALLBACK_IMG_FORCE, FALSE)){
      $images = OpenGraphMeta::instance()->harvest_images_from_node($node);
      if (!empty($images)) {
        foreach ($images as $image) {
          $image_selector_options[$image['url']] = OpenGraphMetaDrupalLayer::theme_selector_image($image);
        }
      }
    }
      $form['opengraph_meta'][OpenGraphMeta::IMAGE] = array(
        '#title' => t('Thumbnail image'),
        '#type' => 'radios',
        '#default_value' => !empty($node->opengraph_meta) ? $node->opengraph_meta[OpenGraphMeta::IMAGE] : '',
        '#description' => t('The thumbnail image that will get shown in e.g. a Facebook preview. If left unset then then the first available image will be used. If none available then the global fallback image will be used.'),
        '#options' => $image_selector_options,
        '#attributes' => array('class' => array('opengraph-thumbs-wrapper','clearfix')),
      );
  }
}
lyricnz’s picture

FYI http://drupal.org/project/metatag project appears to be better maintained than this, and offers a more general solution to the problem. I've switched my D7 sites, at least, to using this - and it works great.

  • hiddentao committed 38f397e on 7.x-2.x
    Issue #1006888 by hiddentao: Added concept of "fallback image" to use...
torotil’s picture

Issue summary: View changes
Status: Needs review » Fixed

Closing as fixed due to the commit mention.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

tamer.kamel’s picture

You can replace the thumbnail by the original image by this patch.