Hi,

I need to use "Author" meta tag on my web. I was able to create a custom meta tag in nodewords_custom.module:

function nodewords_custom_nodewords_tags_info() {
  $tags = array(
    'author' => array(
     'tag:context:allowed' => array('default', 'node'),
     'tag:db:type' => 'string',
     'tag:function:prefix' => 'nodewords_author',
     'tag:template' => array('author' => NODEWORDS_META),
     'widget:label' => t('Author'),
     'widget:permission' => 'edit meta tag Author',
     ),
  );

  return $tags;
}

The tag appeared in Meta Tags settings in "Meta tags to show on edit forms" and "Meta tags to output in HTML" but didn't in actual node edit form. Anyway, I'd like to use this tag as one per site so I need to add this tag among global default values. I wasn't able to find the procedure in README. Is it possible? Can you help?

Thank you.

Comments

avpaderno’s picture

See the code used in nodewords_basic.module. The module needs to add some functions that are called for some tasks; in particular, for the code you reported, the module should contain a function nodewords_author_form(), which should return the form fields used in the meta tags edit forms.

To make an example, this is the code that handles the canonical URL meta tag.

/**
 * Set the form fields used to implement the options for the meta tag.
 */
function nodewords_basic_canonical_form(&$form, $content, $options) {
  $form['canonical'] = array(
    '#tree' => TRUE,
  );

  $form['canonical']['value'] = array(
    '#type' => 'textfield',
    '#title' => t('Canonical URL'),
    '#description' => t('Canonical URLs are used from the search engines, and allow them to not report duplicate titles for HTML pages that are accessible from different URLs. Use a relative URL without the initial slash; canonical URLs that point to a different domain are normally not accepted.'),
    '#default_value' => empty($content['value']) ? '' : $content['value'],
    '#element_validate' => array('nodewords_basic_canonical_form_validate'),
    '#size' => 60,
    '#maxlength' => variable_get('nodewords_max_size', 350),
  );
}

/**
 * Set the meta tag content.
 */
function nodewords_basic_canonical_prepare(&$tags, $content, $options) {
  if (!empty($content['value'])) {
    $content['value'] = trim($content['value'], '/');
  }

  if (empty($content['value'])) {
    $path = '';

    switch ($options['type']) {
      case NODEWORDS_TYPE_FRONTPAGE:
        $content['value'] = '<front>';
        break;

      case NODEWORDS_TYPE_NODE:
        if (count($options['ids']) == 1) {
          $path = 'node/' . $options['ids'][0];
        }
        break;

      case NODEWORDS_TYPE_TERM:
        if (count($options['ids']) == 1) {
          $path = 'taxonomy/term/' . $options['ids'][0];
        }
        break;

      case NODEWORDS_TYPE_TRACKER:
        if (count($options['ids']) == 1) {
          if ($options['ids'][0] == -1) {
            $path = NODEWORDS_TYPE_TRACKER;
          }
          elseif (is_numeric($options['ids'][0])) {
            $path = 'user/' . $options['ids'][0] . '/track';
          }
        }
        break;

      case NODEWORDS_TYPE_USER:
        if (count($options['ids']) == 1) {
          $path = 'user/' . $options['ids'][0];
        }
        break;

      default:
        $path = $_GET['q'];
    }

    if ($path) {
      $content['value'] = drupal_get_path_alias($path);
    }
  }
  elseif (!empty($content['value']) && strpos($content['value'], '/') === 0) {
    $content['value'] = drupal_substr($content['value'], 1);
  }

  $base_url = rtrim(variable_get('nodewords_base_url', ''), '/');
  $options = array(
    'absolute' => TRUE,
    'base_url' => $base_url,
  );

  $tags['canonical'] = !empty($content['value']) ? check_url(url($content['value'], $options)) : '';
}

function nodewords_basic_canonical_form_validate($element, &$form_state) {
  $canonical_url = trim($element['#value'], '/');

  if (!empty($canonical_url) && !valid_url($canonical_url)) {
    form_error($element, t('Canonical URL must be a relative URL.'));
  }
}

function nodewords_basic_canonical_settings_form(&$form, $form_id, $options) {
  if ($form_id == 'nodewords_settings_form') {
    $form['metatags_creation']['nodewords_base_url'] = array(
      '#type' => 'textfield',
      '#title' => t('Base URL'),
      '#description' => t('Enter the base URL that will be used for canonical URLs.'),
      '#default_value' => variable_get('nodewords_base_url', ''),
      '#element_validate' => array('nodewords_basic_canonical_settings_form_validate'),
      '#size' => 60,
    );
  }
}

function nodewords_basic_canonical_settings_form_validate($element, &$form_state) {
  $base_url = rtrim($element['#value'], '/');

  if (!empty($base_url) && !valid_url($base_url, TRUE)) {
    form_error($element, t('Invalid base URL.'));
  }
}
ilo’s picture

What is the purpose of nodewords_custom.module? should everyone be able to alter it? if so we should take care to not overwrite with module updates, otherwise I'd suggest to use the module as a template, but not edit the files..

avpaderno’s picture

nodewords_custom.module had that purpose, in the same way tokenSTARTER.module.
As everybody can create a custom module, I removed it.

In branch 6.x-3, nodewords_custom.module will have a different purpose, and it is not supposed to be altered from the users.

ilo’s picture

Status: Active » Needs work

Oh, probably we should document this..

Anonymous’s picture

Status: Needs work » Fixed

The module has been removed, and it will added back to branch 6.x-3 later in the development of the branch.

Status: Fixed » Closed (fixed)

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