/[drupal]/contributions/modules/nodewords_bypath/nodewords_bypath.forms.inc
ViewVC logotype

Diff of /contributions/modules/nodewords_bypath/nodewords_bypath.forms.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.3.2.1, Mon Dec 29 12:28:00 2008 UTC revision 1.1.2.3.2.2, Thu Jan 1 02:37:28 2009 UTC
# Line 13  Line 13 
13   */   */
14  function nodewords_bypath_admin_overview() {  function nodewords_bypath_admin_overview() {
15    $form  = array();    $form  = array();
16    $rules = _nodewords_bypath_get_all();    $rules = _nodewords_bypath_load_all();
17    
18    foreach ($rules as $rule) {    if (empty($rules)) {
19      $form[$rule->id]['id'] = array(      $form['emptytext']['#value'] = t('No rules found. <a href="@newrule">Create a new rule to get started.</a>', array('@newrule' => url('admin/content/nodewords/path/new')));
20        '#type'  => 'value',    }
21        '#value' => $rule->id,    else {
22      );      foreach ($rules as $rule) {
23          $form[$rule->id]['id'] = array(
24      $form[$rule->id]['name']   = array('#value' => $rule->name);          '#type'  => 'value',
25      $form[$rule->id]['weight'] = array('#value' => $rule->weight);          '#value' => $rule->id,
26      $form[$rule->id]['edit']   = array('#value' => l(t('Edit'), 'admin/content/nodewords/path/edit/'. $rule->id));        );
27      $form[$rule->id]['delete'] = array('#value' => l(t('Delete'), 'admin/content/nodewords/path/delete/'. $rule->id));  
28          $form[$rule->id]['name']   = array('#value' => $rule->name);
29          $form[$rule->id]['weight'] = array('#value' => $rule->weight);
30          $form[$rule->id]['edit']   = array('#value' => l(t('Edit'), 'admin/content/nodewords/path/'. $rule->id .'/edit'));
31          $form[$rule->id]['delete'] = array('#value' => l(t('Delete'), 'admin/content/nodewords/path/'. $rule->id .'/delete'));
32        }
33    }    }
34    
35    return $form;    return $form;
# Line 35  function nodewords_bypath_admin_overview Line 40  function nodewords_bypath_admin_overview
40   * Generate the form for creating a new custom title rule or editing an   * Generate the form for creating a new custom title rule or editing an
41   * existing one.   * existing one.
42   *   *
43   * @param $id int The ID of an existing title pattern to edit. If specified,   * @param $rule An existing rule to edit. If specified, this rule will be used
44   *        this title pattern will be used to populate the form fields.   *   to populate the form fields.
45   *   *
46   * @return array The form.   * @return array The form.
47   */   */
48  function nodewords_bypath_create_form($id = -1) {  function nodewords_bypath_form(&$form_state, $rule = NULL) {
49    $form = array();    $form = array();
50    
51    $existing = ($id > -1) ? _nodewords_bypath_load_instance($id) : NULL;    if (!$rule) {
52    if ($existing) {      $rule = new stdClass;
     $existing->tags = _nodewords_bypath_get_tags_for($id);  
53    }    }
54    
55    //------------------------------------------------------------------------    //------------------------------------------------------------------------
# Line 54  function nodewords_bypath_create_form($i Line 58  function nodewords_bypath_create_form($i
58      '#type'        => 'fieldset',      '#type'        => 'fieldset',
59      '#title'       => t('Meta Tag Rule'),      '#title'       => t('Meta Tag Rule'),
60      '#collapsible' => TRUE,      '#collapsible' => TRUE,
61      '#weight'      => -5,      '#weight'      => -10,
62    );    );
63    
64    $form['meta_rule']['rule_id'] = array(    $form['meta_rule']['rule_id'] = array(
65      '#type'  => 'value',      '#type'  => 'value',
66      '#value' => ($existing) ? $existing->id : -1,      '#value' => $rule->id,
67    );    );
68    
69    $form['meta_rule']['name'] = array(    $form['meta_rule']['name'] = array(
70      '#type'          => 'textfield',      '#type'          => 'textfield',
71      '#title'         => t('Name'),      '#title'         => t('Name'),
72      '#default_value' => ($existing) ? $existing->name : '',      '#default_value' =>  $rule->name,
73      '#description'   => t('A short name to help you identify this rule when it\'s shown in the list view.'),      '#description'   => t('A short name to help you identify this rule when it\'s shown in the list view.'),
74    );    );
75    
76    $form['meta_rule']['weight'] = array(    $form['meta_rule']['weight'] = array(
77      '#type'        => 'select',      '#type'        => 'select',
78      '#title'       => t('Weight'),      '#title'       => t('Weight'),
79      '#default_value' => ($existing) ? $existing->weight : 0,      '#default_value' => ($rule) ? $rule->weight : 0,
80      '#options'     => drupal_map_assoc(range(-10, 10)),      '#options'     => drupal_map_assoc(range(-10, 10)),
81      '#description' => t('This determines the order that rules are evaluated. Rules with lower weight values are evaluated before rules with higher weights. Evaluation stops at the first rule that matches the path.'),      '#description' => t('This determines the order that rules are evaluated. Rules with lower weight values are evaluated before rules with higher weights. Evaluation stops at the first rule that matches the path.'),
82    );    );
# Line 85  function nodewords_bypath_create_form($i Line 89  function nodewords_bypath_create_form($i
89    $form['meta_rule']['type'] = array(    $form['meta_rule']['type'] = array(
90      '#type'        => 'radios',      '#type'        => 'radios',
91      '#title'       => t('Rule Application'),      '#title'       => t('Rule Application'),
92      '#default_value' => ($existing) ? $existing->type : 1,      '#default_value' => ($rule) ? $rule->type : 1,
93      '#options'     => $options,      '#options'     => $options,
94      '#description' => t('Determines the method used apply the meta tag rule.'),      '#description' => t('Determines the method used apply the meta tag rule.'),
95    );    );
# Line 104  function nodewords_bypath_create_form($i Line 108  function nodewords_bypath_create_form($i
108    $form['meta_rule']['paths'] = array(    $form['meta_rule']['paths'] = array(
109        '#type'          => 'textarea',        '#type'          => 'textarea',
110        '#title'         => t('Path(s)'),        '#title'         => t('Path(s)'),
111        '#default_value' => ($existing) ? $existing->path_expr : '',        '#default_value' => ($rule) ? $rule->path_expr : '',
112        '#description'   => $description,        '#description'   => $description,
113    );    );
114    
# Line 125  function nodewords_bypath_create_form($i Line 129  function nodewords_bypath_create_form($i
129    foreach (_nodewords_get_possible_tags() as $tag) {    foreach (_nodewords_get_possible_tags() as $tag) {
130      $function = 'nodewords_'. $tag .'_form';      $function = 'nodewords_'. $tag .'_form';
131      if ($settings['edit'][$tag] && function_exists($function)) {      if ($settings['edit'][$tag] && function_exists($function)) {
132        $default = ($existing) ? $existing->tags[$tag] : '';        $default = ($rule) ? $rule->tags[$tag] : '';
133        $element = $function('page', $default, $settings);        $element = $function('page', $default, $settings);
134        if ($element) {        if ($element) {
135          $form['meta_tags']['meta_tag_'. $tag] = $element;          $form['meta_tags']['meta_tag_'. $tag] = $element;
# Line 136  function nodewords_bypath_create_form($i Line 140  function nodewords_bypath_create_form($i
140    //------------------------------------------------------------------------    //------------------------------------------------------------------------
141    $form['submit'] = array(    $form['submit'] = array(
142      '#type'  => 'submit',      '#type'  => 'submit',
143      '#value' => ($existing) ? t('Update Rule') : t('Save Rule'),      '#value' => ($rule) ? t('Update Rule') : t('Save Rule'),
144    );    );
145    
146    $form['cancel'] = array(    $form['cancel'] = array(
# Line 154  function nodewords_bypath_create_form($i Line 158  function nodewords_bypath_create_form($i
158   * @param $form_id mixed The ID of the form.   * @param $form_id mixed The ID of the form.
159   * @param $form_values array The form values.   * @param $form_values array The form values.
160   */   */
161  function nodewords_bypath_create_form_submit($form, &$form_state) {  function nodewords_bypath_form_submit($form, &$form_state) {
162    // -------------------------------------------------------------------------    // -------------------------------------------------------------------------
163    // Bail out on cancel.    // Bail out on cancel.
164    if ($form_state['values']['op'] == t('Cancel')) {    if ($form_state['values']['op'] == t('Cancel')) {
# Line 179  function nodewords_bypath_create_form_su Line 183  function nodewords_bypath_create_form_su
183      }      }
184    }    }
185    
186    _nodewords_bypath_save($rule);    nodewords_bypath_rule_save($rule);
187    if ($rule->id > -1) {    if ($rule->id > -1) {
188      drupal_set_message(t('Updated meta tag rule %name', array('%name' => $rule->name)));      drupal_set_message(t('Updated meta tag rule %name', array('%name' => $rule->name)));
189    }    }
# Line 195  function nodewords_bypath_create_form_su Line 199  function nodewords_bypath_create_form_su
199  /**  /**
200   * Generate the confirmation form for deleting a title.   * Generate the confirmation form for deleting a title.
201   *   *
202   * @param $id int The ID of the rule to delete.   * @param $rule The rule to delete.
203   *   *
204   * @return array The form.   * @return array The form.
205   */   */
206  function nodewords_bypath_delete_form($id) {  function nodewords_bypath_delete_form(&$form_state, $rule) {
207    $form = array();    $form = array();
208    
   $existing = _nodewords_bypath_load_instance($id);  
   
209    $form['pattern_id'] = array(    $form['pattern_id'] = array(
210      '#type'  => 'value',      '#type'  => 'value',
211      '#value' => $id,      '#value' => $rule->id,
212    );    );
213    
214    $form['pattern_name'] = array(    $form['pattern_name'] = array(
215      '#type'  => 'value',      '#type'  => 'value',
216      '#value' => $existing->name,      '#value' => $rule->name,
217    );    );
218    
219    $question = t('You are about to remove the meta tag rule "%name".',    $question = t('You are about to remove the meta tag rule "%name".',
220                  array('%name' => $existing->name));                  array('%name' => $rule->name));
221    $desc     = t('This action cannot be undone.');    $desc     = t('This action cannot be undone.');
222    
223    return confirm_form($form, $question, 'admin/content/nodewords/path', $desc, t('Delete'), t('Cancel'));    return confirm_form($form, $question, 'admin/content/nodewords/path', $desc, t('Delete'), t('Cancel'));
# Line 365  function theme_nodewords_bypath_tokenref Line 367  function theme_nodewords_bypath_tokenref
367   * @return string The rendered form elements.   * @return string The rendered form elements.
368   */   */
369  function theme_nodewords_bypath_admin_overview($form) {  function theme_nodewords_bypath_admin_overview($form) {
370    $rows = array();    $output = '';
371    foreach ($form as $name => $element) {    if (!$form['emptytext']) {
372      if (isset($element['name']) && is_array($element['name'])) {      $rows = array();
373        $rows[] = array(      foreach ($form as $name => $element) {
374          drupal_render($element['name']),        if (isset($element['name']) && is_array($element['name'])) {
375          drupal_render($element['weight']),          $rows[] = array(
376          drupal_render($element['edit']),            drupal_render($element['name']),
377          drupal_render($element['delete'])            drupal_render($element['weight']),
378        );            drupal_render($element['edit']),
379        unset($form[$name]);            drupal_render($element['delete'])
380            );
381            unset($form[$name]);
382          }
383      }      }
384        $header = array(t('Name'), t('Weight'), t('Edit'), t('Delete'));
385        $output = theme('table', $header, $rows);
386    }    }
   $header = array(t('Name'), t('Weight'), t('Edit'), t('Delete'));  
   $output = theme('table', $header, $rows);  
387    $output .= drupal_render($form);    $output .= drupal_render($form);
388    
389    return $output;    return $output;

Legend:
Removed from v.1.1.2.3.2.1  
changed lines
  Added in v.1.1.2.3.2.2

  ViewVC Help
Powered by ViewVC 1.1.2