When creating a node, under the Thumbnail Image section there are two radio buttons.

( ) No image (Facebook will choose one automatically).
( ) Provide a URL to a custom preview image.

Per default, No image should be selected because if I do nothing I get an error when trying to submit/save the node

"An illegal choice has been detected. Please contact the site administrator."

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ludberg created an issue. See original summary.

rajeev_drupal’s picture

I am also facing the same issue, while editing the node.Ideally it should work without selection of image as well.

jamesrice’s picture

I have this issue as well, and it seems to potentially be further complicated when I try to setup a default value of the OG Image as well.

lehnle’s picture

It seems to me that setting a default value for og:image causes the problem.
Leaving it blank uses the "no image" option as default.

Details:
in opengraph_meta.module the thumbnail image options include a blank
'' => t('No image (Facebook will choose one automatically).')
the other options are "harvested" from the node. The selected default value is then set by

'#default_value' => $metatags['og:image']['value']['#default_value']

So if og:image is set but does not correspond to a node image, the select will be broken.

Additionally even if the default value is a node token, e.g. [field_image], during the select widget creation this value does not seem to be resolved to the corresponding url. So the select field will not have the correct option pre-selected.

lehnle’s picture

FileSize
1.84 KB

As suspected the token is not replaced during the select widget creation. So to pass the default select field validation the token has to be added to the '#options' array.

I created a patch that does this, while not actually rendering the option as a selectable choice.

If you do not want to patch the module, you could probably use hook_form_alter to do the same.
Untested, but something similar to this should work.

function hook_form_FORM_ID_alter(&$form, $form_state, $form_id) {
  if(!array_key_exists('opengraph_meta', $form){
      return;
  }
  $default_value = $form['opengraph_meta']['image']['#default_value'];
  if(!isset($form['opengraph_meta']['image']['#options'][$default_value])) {
      //add default value, so validation passes
      $form['opengraph_meta']['image']['#options'][$default_value] = "Default";
      $form['#pre_render'][] = 'hook_form_remove_default';
  }
}
function hook_form_remove_default($element) {
  $image = &$element['opengraph_meta']['image'];
  unset($image['select'][$image['#default_value']]);
  return $element;
}
geoffreyr’s picture

This is the same as #5 but with the paths tidied up so we can apply it against the module directly.

rajeev_drupal’s picture

Assigned: Unassigned » rajeev_drupal
rajeev_drupal’s picture

# 5 and and #6 both working for me. Thanks for patch.

rajeev_drupal’s picture

Assigned: rajeev_drupal » Unassigned