I'm quite sure its a duplicate but wasn't able to figure out which one.

This patch is missing the UI for setting the variable for which there are several possibilities.

  • node-type configuration: /admin/structure/types/manage/article
  • pathauto UI: /admin/config/search/path/
  • path auto extra-field configuration
  • ...

You often want to use pathauto for some content; disabled for every other content.
The rationale of this patch is that you may also want to use pathauto in some case while keeping it mostly disabled for newly created nodes.
With this patch (+ the missing UI bits), you can disable the automatic generation on a per-bundle basis.

On a side note: $pattern = pathauto_pattern_load_by_entity($entity_type, $bundle, $langcode); can be rewritten if(pathauto_pattern_load_by_entity($entity_type, $bundle, $langcode)) return; as $pattern is not used.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Ah, I see what's going on. When there is no available pattern for a specific entity type and bundle, we mistakenly return out of pathauto_field_attach_form() rather than setting $form['path']['pathauto'] to a FALSE value. Currently it will not add anything to the form which then on submit means that !isset($node->path['pathauto']) which means do apply an automatic alias, which is not desired in this case.

Dave Reid’s picture

Title: Default checkbox value for "Generate automatic URL alias", by node-type. » Entities with no pattern should still get an Automatic alias checkbox but unchecked by default
Assigned: Unassigned » Dave Reid
Category: feature » bug
Dave Reid’s picture

Status: Active » Needs review
FileSize
851 bytes

Patch attached for review, this also needs a unit test to confirm its behavior and ensure we don't have a regression in the future.

Dave Reid’s picture

Title: Entities with no pattern should still get an Automatic alias checkbox but unchecked by default » Default checkbox value for "Generate automatic URL alias", by node-type.
Assigned: Dave Reid » Unassigned
Category: bug » feature
Status: Needs review » Closed (won't fix)

Hrm, I'm not sure about this after some review - if there's no pattern, then there's no reason to show an Automatic alias checkbox since checking it would do nothing on node save since there would be no pattern to alias from. The current behavior of 7.x-1.x is correct. This isn't in fact a bug, my mistake.

The originally proposed feature will not be accepted into Pathauto since having a pattern for a content type assumes new content should have that pattern by default. As such, I'm marking this issue closed as a won't fix.

If you want to alter the Pathauto checkbox for new nodes, then you should use something like this in a custom module:

/**
 * Implements hook_node_prepare().
 */
function mymodule_node_prepare($node) {
  if (empty($node->nid) && !isset($node->path['pathauto']) && in_array($node->type, array('page'))) {
    // Default the Pathauto checkbox to be unchecked for new page nodes.
    $node->path['pathauto'] = FALSE;
  }
}
drzraf’s picture

I'm fine with using this hook, which does the trick (thanks).
( Anyway other people may find an UI for this to be valid feature request )

drzraf’s picture

Sorry to bumb, but I'm not aware of any workaround for taxonomy terms edit forms.

Dave Reid’s picture

Yeah you'd have to manually form_alter the taxonomy form and $form['path']['pathauto']['#default_value'].

jeremiahtre.in’s picture

@Dave Reid

I'm attempting to leave the checkbox checked. In my custom module I can't get #4 to work for new or existing nodes (tried both in logic). I even installed pathauto_persist, just in case.

I am using your recommended version, however. Is this dev-only? Alas, here's what I've altered to fit my needs:

function custom_node_prepare($node) {
  if (in_array($node->type, array('panopoly_page'))) {
    // Default the Pathauto checkbox to be checked for new page nodes.
    $node->path['pathauto'] = TRUE;
  }
}

Issue

No matter what, I cannot get the "Generate automatic URL alias" button to be checked. Even on node creation, with a pattern defined.

Motivation

For permissions and semantic reasons (for our many authors) we want the node form to always have this checked. For example: when they change the menu item, we want to make sure that the alias (patterned to menu parents + join) matches that updated menu position.


Thanks for your time, and we truly appreciate this module.

jtreinau

jeremiahtre.in’s picture

Well, turns out Panopoly implements a form_alter to change the value.

Among other Panopoly-specific overrides, here is what code worked for me:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  $form['path']['pathauto']['#default_value'] = 1;
}

Could probably be more specific as to what form I am selecting. Nevertheless, it works.

jtreinau