You are here

function yoast_seo_field_attach_form in Real-time SEO for Drupal 7

Implements hook_field_attach_form().

File

./yoast_seo.module, line 407
Primary hook implementations for Yoast SEO for Drupal module.

Code

function yoast_seo_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {

  // Entity_Translation will trigger this hook again, skip it.
  if (!empty($form_state['entity_translation']['is_translation'])) {
    return;
  }
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
  if (!yoast_seo_entity_supports_yoast_seo($entity_type, $bundle)) {
    return;
  }
  $instance = "{$entity_type}:{$bundle}";
  $options['token types'] = array(
    token_get_entity_mapping('entity', $entity_type),
  );
  $options['context'] = $entity_type;

  // Allow hook_metatag_token_types_alter() to modify the defined tokens. We do
  // this because we are using metatags own fields.
  drupal_alter('metatag_token_types', $options);
  $form['#yoast_seo'] = array(
    'instance' => $instance,
    'options' => $options,
  );
}