/[drupal]/contributions/modules/pathauto/pathauto.module
ViewVC logotype

Diff of /contributions/modules/pathauto/pathauto.module

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

revision 1.125, Fri Sep 25 16:05:39 2009 UTC revision 1.126, Sat Oct 17 17:45:10 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: pathauto.module,v 1.124 2009/04/20 22:52:37 greggles Exp $  // $Id: pathauto.module,v 1.125 2009/09/25 16:05:39 greggles Exp $
3    
4  /**  /**
5   * @defgroup pathauto Pathauto: Automatically generates aliases for content   * @defgroup pathauto Pathauto: Automatically generates aliases for content
# Line 253  function pathauto_nodeapi(&$node, $op, $ Line 253  function pathauto_nodeapi(&$node, $op, $
253   * into the path module's fieldset in the node form.   * into the path module's fieldset in the node form.
254   */   */
255  function pathauto_form_alter(&$form, $form_state, $form_id) {  function pathauto_form_alter(&$form, $form_state, $form_id) {
256    // Only do this for node forms    // Process only node forms.
257    if (isset($form['#id']) && ($form['#id'] == 'node-form') && arg(0) == 'node') {    if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
258      $node = $form['#node'];      $node = $form['#node'];
259        $pattern = FALSE;
260    
261      // See if there is a pathauto pattern or default applicable      // Find if there is an automatic alias pattern for this node type.
262      if (isset($form['language'])) {      if (isset($form['language'])) {
263        $language = isset($form['language']['#value']) ? $form['language']['#value'] : $form['language']['#default_value'];        $language = isset($form['language']['#value']) ? $form['language']['#value'] : $form['language']['#default_value'];
264        $pattern = trim(variable_get('pathauto_node_'. $form['type']['#value'] .'_'. $language .'_pattern', ''));        $pattern = trim(variable_get('pathauto_node_'. $form['type']['#value'] .'_'. $language .'_pattern', ''));
265      }      }
266      if (empty($pattern)) {      if (!$pattern) {
267        $pattern = trim(variable_get('pathauto_node_'. $form['type']['#value'] .'_pattern', ''));        $pattern = trim(variable_get('pathauto_node_'. $form['type']['#value'] .'_pattern', ''));
268        if (empty($pattern)) {        if (!$pattern) {
269          $pattern = trim(variable_get('pathauto_node_pattern', ''));          $pattern = trim(variable_get('pathauto_node_pattern', ''));
270        }        }
271      }      }
272      // If there is a pattern AND the user is allowed to create aliases AND the path textbox is present on this form  
273      if (!empty($pattern) && user_access('create url aliases') && isset($form['path']['path'])) {      // If there is a pattern, show the automatic alias checkbox.
274        $output = t('An alias will be generated for you. If you wish to create your own alias below, untick this option.');      if ($pattern) {
275        if (user_access('administer pathauto')) {        if (!isset($node->pathauto_perform_alias)) {
276          $output .= ' '. t('To control the format of the generated aliases, see the <a href="@pathauto">Pathauto settings</a>.', array('@pathauto' => url('admin/build/path/pathauto')));          if (isset($node->nid)) {
277              // If this is not a new node, compare it's current alias to the
278              // alias that would be genereted by pathauto. If they are the same,
279              // then keep the automatic alias enabled.
280              _pathauto_include();
281              $placeholders = pathauto_get_placeholders('node', $node);
282              $pathauto_alias = pathauto_create_alias('node', 'return', $placeholders, "node/{$node->nid}", $node->nid, $node->type, $node->language);
283              $node->pathauto_perform_alias = isset($node->path) && $node->path == $pathauto_alias;
284            }
285            else {
286              // If this is a new node, enable the automatic alias.
287              $node->pathauto_perform_alias = TRUE;
288            }
289        }        }
290    
291          // Add JavaScript that will disable the path textfield when the automatic
292          // alias checkbox is checked.
293        drupal_add_js(drupal_get_path('module', 'pathauto') .'/pathauto.js');        drupal_add_js(drupal_get_path('module', 'pathauto') .'/pathauto.js');
       $form['path']['#collapsed'] = FALSE;  
294    
295        $form['path']['pathauto_perform_alias'] = array(        $form['path']['pathauto_perform_alias'] = array(
296          '#type' => 'checkbox',          '#type' => 'checkbox',
297          '#title' => t('Automatic alias'),          '#title' => t('Automatic alias'),
298          '#default_value' => isset($node->pathauto_perform_alias) ? $node->pathauto_perform_alias : TRUE,          '#default_value' => $node->pathauto_perform_alias,
299          '#description' => $output,          '#description' => t('An alias will be generated for you. If you wish to create your own alias below, uncheck this option.'),
300          '#weight' => -1,          '#weight' => -1,
301        );        );
302    
303        if (!empty($node->pathauto_perform_alias) && !empty($node->old_alias) && $node->path == '') {        if (user_access('administer pathauto')) {
304            $form['path']['pathauto_perform_alias']['#description'] .= ' '. t('To control the format of the generated aliases, see the <a href="@pathauto">automated alias settings</a>.', array('@pathauto' => url('admin/build/path/pathauto')));
305          }
306    
307          if ($node->pathauto_perform_alias && !empty($node->old_alias) && empty($node->path)) {
308          $form['path']['path']['#default_value'] = $node->old_alias;          $form['path']['path']['#default_value'] = $node->old_alias;
309          $node->path = $node->old_alias;          $node->path = $node->old_alias;
310        }        }
311    
312        //For Pathauto to remember the old alias and prevent the Path-module from deleteing it when Pathauto wants to preserve it        // For Pathauto to remember the old alias and prevent the Path-module from deleteing it when Pathauto wants to preserve it
313        if (isset($node->path)) {        if (isset($node->path)) {
314          $form['path']['old_alias'] = array('#type' => 'value', '#value' => $node->path);          $form['path']['old_alias'] = array(
315              '#type' => 'value',
316              '#value' => $node->path,
317            );
318        }        }
319      }      }
320    }    }

Legend:
Removed from v.1.125  
changed lines
  Added in v.1.126

  ViewVC Help
Powered by ViewVC 1.1.2