"Automatic alias" checkbox should be configurable to default to unchecked (or checked).

Comments

greggles’s picture

Version: 5.x-2.3 » 7.x-1.x-dev
Component: User interface » Code

If this happens it will be in code only (i.e. not have a user interface to control the variable) and will be in 6.x-2.x (where all new features go).

Freso’s picture

Should be easy enough to implement. If we want to do this, what should the variable be called? pathauto_perform_alias_default?

greggles’s picture

Status: Active » Closed (duplicate)

Also, this is really a desire to have update actions work properly and/or for the checkbox to respect the update actions which is fixed (among other things) in http://drupal.org/node/242456 so I think this is duplicate.

markj’s picture

Actually, it would be useful to have an option under the General settings at admin/build/path/pathauto to not even show this checkbox in the node edit form's URL path settings' form fieldset, and for the help text to say something like "Enter an optional custom URL for this node". In other words, Path Alias would provide the option for people to create their own URL but not force automatic creation of the URL. Would you be willing to accept a patch that offers this combination of changes?

greggles’s picture

I'm not entirely sure that I understand that idea, but

1) Anything that involves adding a new option without removing some other options can't get in. The admin page is too overwhelming as it is
2) If I do understand what you're saying...it won't work during node edits.

markj’s picture

I've achieved what I'm after by using form_alter() in a site-specific module. In case anyone else is interested I'll document it here:

1) Make the custom module load later than Pathauto by giving it a weight of 2 in the {system} table (see http://drupal.org/node/110238 -- this can be done in the module's install file), since Pathauto has a weight of 1. We need to do this because we are applying form_alter() to a form that has already had form_alter() applied to it by another module (in other words, Pathauto is altering the core node edit form, and we are altering the alteration applied by Pathauto).

2) In our form_alter() function, add the following code:

<?php
  // Alter the form so the "Autogenerate URL" checkbox is no longer visible
  // and its value is set to 0. We also need to load some javascript to override
  // some JS loaded earlier by Pathauto which renders the text area 'disabled'.
  if($form_id =='page_node_form') {
    drupal_add_js(drupal_get_path('module', 'markslaptop') .'/pathauto_markslaptop.js');
    $form['path']['pathauto_perform_alias'] = array('#type' => 'value', '#value' => 0);
  }
?>

3) Create a little Javascript file called pathauto_markslaptop.js (or whatever you call it in the drupal_add_js() function in your form_alter() function):

if (Drupal.jsEnabled) {
  $(document).ready(function() {
      // Enable input disabled by Pathauto
      $("#edit-path").attr("enabled","enabled");
   });
}

The overall effect is to make "Automatic alias" checkbox disappear from the node edit form (I mean totally disappear, there's no more option to auto generate) and to make it's value unchecked, so the user can add an optional path.

charmer’s picture

Is there any chance to port this feature to 5.x branch?

I'd appreciate if I could tell Pathauto whether it should start with 'Automatic Alias' ticked (both for new nodes and edit forms) per node type, but if it's too difficult, very simple option just to set up the default state of the checkbox would be nice and it would help me just the same.

Thank in advance.

priya_86’s picture

About automatic aliases..

tahiche’s picture

Related to markj´s solution...
I know it´s wrong to modify module´s files instead of overwriting functions and such, but then again, I keep seeing patches to alter modules files, right?.
My scenario:
1)On a generalo basis, I don´t want the editor to control the alias. But I don´t want to permanently exclude the posibility.
2) Paths are generated according to taxonomy tags...

Therefore if taxonomy is changed for a node, I want a new path generated. In that case pathauto interprets the paths are different and the checkbox (use automatic) is unchecked, which is an unwanted behaviour. So basically I want the checkbox checked unless you REALLY want to change it...

Simplest solution ever:
pathauto.js - line 5 (at the begining)

if ($("#edit-pathauto-perform-alias").length) $('#edit-pathauto-perform-alias').attr('checked', true);

Which basically checks it by default.

jusfeel’s picture

Version: 7.x-1.x-dev » 5.x-2.1
Category: feature » support
Priority: Normal » Critical
Status: Closed (duplicate) » Active

my automatic alias box just gone for one content type from some reason...any idea where I can look into?

dave reid’s picture

Version: 5.x-2.1 » 7.x-1.x-dev
Category: support » feature
Priority: Critical » Normal
Status: Active » Closed (duplicate)
ccshannon’s picture

Wow, after an hour of head-banging (and no, not in the good way) @tahiche at #9 posts something that solves the problem that seems to have been plaguing pathauto for many versions now and is still not fixed in current version (1.5)

I don't create my nodes via Drupal UI. My nodes are imported from a php script and created using Drupal API calls (drupal_write_record NOT node_save). So, I thought the reason that the Automatic URL Alias checkbox wasn't getting checked was because of my imports, but then I remembered, "Hey, I've been doing these imports for two years and this wasn't a problem before .. hmmm" Ever since Pathauto 1.2, the checkbox has not been checked properly in defaults, and, get this, using form_alter does NOTHING. You cannot control the checkbox being on or off using form_alter. I'm not sure if that's Pathauto or a Drupal bug (foind lots of tickets of people not able to control checkbox defaults using form_alter).

Anyway, I'm commenting in this (closed) ticket because numerous other tickets about this issue have been closed without the problem actually being fixed.

Really, there should be a module setting that lets you default the checkbox to on or off, even better would be by content type, context, etc.

The only correction I would make to #9 code is to format it properly and NOT put it on line 5, rather start it at line 4 :

  $(document).ready(function() { // This line is already in pathauto.js - add the following after it
    if ($("#edit-pathauto-perform-alias").length) {
      $('#edit-pathauto-perform-alias').attr('checked', true);
    }
    // That's it ... you're done
    // The next line already in pathauto.js will be something like
    if ($("#edit-pathauto-perform-alias").size() && $("#edit-pathauto-perform-alias").attr("checked")) {

Eaglecanada’s picture

this is a better method:
http://browse-tutorials.com/snippet/drupal-snippet-automatic-alias-check...

using #12, you have to give user administer url aliases & create url aliases permission

ccshannon’s picture

The link is bad. There is a colon on the end that shouldn't be there.

Yes, that also works, but none of these solutions is really all that great, because they require hacking directly into the module. The module should offer the option to have the checkbox on or off by default.

Also, I would contend that you should have administer url aliases & create url aliases permission enabled to be able to have the alias checkbox in the first place, but to each his own.

Encarte’s picture

@ccshannon: I also think «The module should offer the option to have the checkbox on or off by default.», but this was marked as a duplicate of #242456: Allow unique "Update Action" settings per item type (node, taxonomy,etc) or item (eg. page, story, vocabulary, etc). I think greggles marked it as a duplicate because he's concerned about the user-friendliness of the admin page and would rather have this feature on the node type page (and I think that makes sense).

ccshannon’s picture

@Encarte: Thanks, I did not catch the duplicate issue! That sounds like a good way to go .. content type setting. :)