You are here

function nodewords_edit_attributes in Nodewords: D6 Meta Tags 6.2

Edit the attributes of a meta tag.

Parameters

$tag: Object. The meta tag to edit. If NULL a new meta tag will be created.

File

./nodewords.admin.inc, line 202
Administration forms.

Code

function nodewords_edit_attributes(&$form_state, $tag) {
  drupal_set_title(t('Edit %tag_name meta tag attributes', array(
    '%tag_name' => $tag->name,
  )));
  if ($tag->widget == 'alias') {
    drupal_set_message(t('You can not set attributes for a meta tag which is an alias.'), 'error');
    return array();
  }
  $form = array();
  $form['tagid'] = array(
    '#type' => 'value',
    '#value' => $tag->tagid,
  );
  $form['name'] = array(
    '#type' => 'value',
    '#value' => $tag->name,
  );
  if ($form_state['rebuild']) {
    $attributes = $form_state['values']['attributes'];
  }
  else {
    $attributes = $tag->attributes;
  }
  $form['attributes'] = array(
    '#tree' => TRUE,
  );
  foreach ((array) $attributes as $i => $value) {
    $value = (object) $value;
    $form['attributes'][] = array(
      'attid' => array(
        '#type' => 'value',
        '#value' => $value->attid,
      ),
      'delete' => array(
        '#type' => 'checkbox',
        '#default_value' => isset($value->delete) ? $value->delete : FALSE,
      ),
      'name' => array(
        '#type' => 'textfield',
        '#default_value' => $value->name,
        '#size' => 16,
      ),
      'value' => array(
        '#type' => 'textfield',
        '#default_value' => $value->value,
        '#size' => 32,
      ),
      'weight' => array(
        '#type' => 'weight',
        '#default_value' => $value->weight,
      ),
    );
  }
  $form['buttons'] = array(
    '#weight' => 50,
    'save' => array(
      '#type' => 'submit',
      '#value' => t('Save attributes'),
      '#validate' => array(
        'nodewords_edit_attributes_validate_save',
      ),
      '#submit' => array(
        'nodewords_edit_attributes_submit_save',
      ),
      '#weight' => 5,
    ),
    'add' => array(
      '#type' => 'submit',
      '#value' => t('Add new attribute'),
      '#submit' => array(
        'nodewords_edit_attributes_submit_add',
      ),
      '#weight' => 5,
    ),
  );
  return $form;
}