1

Issue

Users will input text that need to be copied into (hidden) meta tag fields when the user have written them into normal fields on the input node.

What I am looking for is either a module to help me with this, a user guide to doing it or an alternative solution to the issue described in the background.

Background

I need to use Meta tags quick to annotate user submitted content on my website.

The user submit article information in normal fields (ie for example an Author field exposed on any node with the article content type). My plan is to to use the Meta tags quick module to create hidden fields and then have those fields filled in by copying content from the user input fields.

An alternative is of course to use the Metatag module but I find it harder to work with and I also need to copy some other fields.

3
  • 1
    Why? If you want to copy from field A to hidden field B verbatim, why not just remove A and show B? It seems you have some requirement you didn't put into your question, it would be a waste if our answers would fail to satisfy you due to that unknown requirement.
    – Mołot
    Commented Mar 3, 2014 at 8:27
  • Because meta tags are hidden in the HTML header while the input fields are displayed in the node body. I need them available in both places.
    – Sigvard
    Commented Mar 3, 2014 at 14:43
  • But you can do that on theme level instead. Your need does not excuse / explain data duplication at field level unless something more is going on.
    – Mołot
    Commented Mar 3, 2014 at 14:54

3 Answers 3

3

You can metatags from fields on the node with

hook_preprocess_html

e.g

/**
 * Implements hook_preprocess_html
 */
function THEME_preprocess_html(&$variables){
  // Only add on node pages
  if($node = menu_get_object('node')){
    // Read node fields, wrapper requires entity api module
    $wrapper = entity_metadata_wrapper('node', $node);
    if(isset($wrapper->field_some_field)){
      if($some_content = $wrapper->field_some_field->value()){ 
        $element = array(
          '#tag' => 'html_tag', 
          '#type' => 'meta', 
          '#attributes' => array(
            'name' => 'some-metatag',
            'content' => $some_content, 
          ),
        );
        drupal_add_html_head($element, 'some_metatag');
      }
    }
  }
}
1

I don’t know the Meta tags quick module, but according to this comparison it seems to support tokens.

So the same method that works for Metatags should work for Meta tags quick, too:

Take the token of the field and set it as content for the meta tag.

0

Mmmh.. You're issues is not really detailed so I will give a general answer.

function yourmodule_form_alter(&$form, &$form_state, $form_id){ 
  if( $form_id == 'your form id' ){   

    $form['field_B']['#access'] = FALSE;
    $form['#validate'][] = 'yourmodule_validate';    

  }
}

function yourmodule_validate($form, &$form_state) {

    $field_A_value = $form_state['values']['field_B']
    $form_state['values']['field_B'] = $field_A_value;

}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.