You are here

function nodewords_edit_widget in Nodewords: D6 Meta Tags 6.2

Edit widget.

File

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

Code

function nodewords_edit_widget(&$form_state, $tag) {
  drupal_set_title(t('Edit %tag_name meta tag widget', array(
    '%tag_name' => $tag->name,
  )));
  if (isset($form_state['rebuild']) && $form_state['rebuild']) {
    $widget_options = $form_state['values']['widget_options'];
    $widget = $form_state['values']['widget'];
  }
  else {
    $widget_options = $tag->widget_options;
    $widget = $tag->widget;
  }
  $form = array();
  $form['tagid'] = array(
    '#type' => 'value',
    '#value' => $tag->tagid,
  );
  $form['name'] = array(
    '#type' => 'value',
    '#value' => $tag->name,
  );
  $form['old-widget'] = array(
    '#type' => 'value',
    '#value' => $widget,
  );
  $widgets = _nodewords_widgets();
  $titles = array();
  $descriptions = array();
  foreach ($widgets as $key => $value) {
    $titles[$key] = $value['title'];
    if (isset($value['description'])) {
      $descriptions[$value['title']] = $value['description'];
    }
  }
  $description = t('<p>Select the widget to use to edit this meta tag.</p>');
  if (count($descriptions)) {
    $description .= theme('nodewords_descriptions', $descriptions);
  }
  $form['widget'] = array(
    '#type' => 'radios',
    '#title' => t('Widget type'),
    '#description' => $description,
    '#options' => $titles,
    '#default_value' => $widget,
    '#required' => TRUE,
  );
  $form['widget_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Widget options'),
    '#tree' => TRUE,
    '#description' => t('Here you can customize the widget. The available options depend on the selected widget.'),
  );
  $function = '_nodewords_widget_options_' . $widget;
  if (function_exists($function)) {
    $form_options = $function($widget_options);
    $form['widget_options'] = array_merge($form['widget_options'], $form_options);
  }
  if (count(element_children($form['widget_options'])) == 0) {
    $form['widget_options'][] = array(
      '#value' => t('There are no options available for this widget.'),
    );
  }
  $form['buttons'] = array(
    '#weight' => 50,
    'save' => array(
      '#type' => 'submit',
      '#value' => t('Save widget'),
      '#validate' => array(
        'nodewords_edit_widget_validate_save',
      ),
      '#submit' => array(
        'nodewords_edit_widget_submit_save',
      ),
    ),
  );
  return $form;
}