opening this one after discussed/proposed here: http://drupal.org/node/828038#comment-3159304

I am pretty sure I've seen a type-something-in-a-field-see-it-update-live-in-another done someplace around the net. So, I guess it can be done with the page title field and the auto-url field too.

... Quoting Dave Reid's words from that post:

...How do we handle a an alias that uses certain fieldss that a user role doesn't have access to? We can probably base some of the work off the Live modules which passes the values and through the ajax request builds a full node...

...and setting to minor.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greggles’s picture

Priority: Minor » Normal

It's at least as high priority if not more than the other issue.

klonos’s picture

... was trying to be modest and all ;)

timmillwood’s picture

I was working on a separate module to do this.

Will now look at doing it as a patch.

timmillwood’s picture

Assigned: Unassigned » timmillwood
Status: Active » Needs review
FileSize
5.43 KB

I have been working on this for two hours. Here's what I have so far.

Would be great if someone could take a look at it.

I am going to do a bit of testing and work on it for the rest of the day.

stewsnooze’s picture

Status: Needs review » Needs work

I haven't looked at it properly but there is at least one line of debug code that needs to come out

//drupal_set_message('<pre>'.print_r($placeholders,true).'</pre>');
timmillwood’s picture

Oops, thanks stewsnooze.

Also it works great when adding a new node, but seems to break when editing an existing one.

timmillwood’s picture

Access argument changed to "create url aliases".

timmillwood’s picture

Next iteration.

Now works better for existing nodes, and previously noted comments fixed.

DamienMcKenna’s picture

Status: Needs work » Needs review
Dave Reid’s picture

Status: Needs review » Needs work

A lot of this should be able to be simplified as you can use pathauto_create_alias() with the 'return' op.

timmillwood’s picture

It cannot use the return op until the alias has been created.

Unless the patch patches pathauto_create_alias() to return paths for uncreated aliases.

Dave Reid’s picture

What's wrong with pathauto_create_alias() with the 'return' op before an alias is created? I would think we would need to fix it to work in that case.

Oh, because node->nid is empty a lot of stuff goes wrong with that.

timmillwood’s picture

pathauto_create_alias() (http://drupalcontrib.org/api/function/pathauto_create_alias/6) requires the $src (The "real" URI of the content to be aliased (e.g., "node/$node->nid")). This (nid) is not available until the node has been saved. One option is passing the part of the node (such as nid or title) instead of $src, then doing a node load. If the node does not exist them a dummy node can be created with all known information.

Maybe this method needs a little more discussion, IRC anyone?

The current patch seems to do a good job in my view without any fundamental changes to the existing pathauto code. FAQ and Ubercart modules uses
pathauto_create_alias(), so they will be affected by the changes.

timmillwood’s picture

This patch now uses pathauto_create_alias().

Dave Reid’s picture

A few things I've already noticed:
1. This won't work if the clean urls are turned off (using paths like ?q=node/add/story) because the JS tries to load a clean url path which may not work. We have to add a JS setting to give us the proper base URL because Drupal.settings.basePath does not provide the necessary information.
2. We should probably add the node type as a Drupal.settings.pathauto['nodeType'] instead of parsing it from the form ID and then having to strip '_node_form' from it.
3. So to review this will only work with basic tokens, like node title, and not with field values.
4. All of our JS callbacks return JSON, so it seems odd that this doesn't.
5. The JS callback should probably call a direct exit() because currently this will still allow modules to execute in hook_exit() (e.g. devel and it's query output).

timmillwood’s picture

Factored in all Dave's suggestions.

klonos’s picture

Nothing seems to break with the patch in #8, but the only preview I see is the domain name (http://www.mysite.net/). I have this D6.17 installation as a 'test' subfolder in my servers root, so I believe I am supposed to see http://www.mysite.net/test/page/[page_title] instead. Actually http://www.mysite.net/test/en/page/[page_title] if you take the language prefix under consideration.

I believe that the cause of this is that I also use Vertical Tabs (also Vertical Tabs Default Tab), so my 'URL path settings' is in a vertical tab (à la D7) rather than in a collapsible fieldset.

klonos’s picture

...same with patch in #16

timmillwood’s picture

I will install vertical tabs and test.

I am also thinking of removing the "Automatic alias - An alias will be generated for you. If you wish to create your own alias below, uncheck this option." text along with the checkbox and replacing it with an edit button next to the live URL.

Much like Wordpress.

Image stolen from http://busyblogging.com/wordpress/easily-reload-the-permalink-url-in-wor... as an example
klonos’s picture

That would be a fantastic UI enhancement! Should have been like that from the start.

greggles’s picture

I don't think that makes sense as a solution for all of Pathauto's users. We should make it easy to do that for an installation profile that needs it, but I'm not sure for everyone else.

timmillwood’s picture

Greggles: Would this be better as a contrib module?

greggles’s picture

I love the idea of alias preview prior to node submission in Pathauto itself but I think we should put it where we put all the other metadata - in the fieldsets at the bottom of the node.

I'm just not sure (though could be convinced) that putting it under the title is the best place for it. I saw that feature in Jens' presentation about Wordpress and was instantly excited about putting it in Drupal. But having it right under the title - i.e. the second most important spot on the page - feels like an overemphasis on something that is mostly not important (the url).

If Drupal were only a blogging platform, I could definitely see sticking it right under the title.

timmillwood’s picture

Sorry, I guess I didn't explain correctly.

My only change would be removing the "Automatica alias" checkbox and replacing it with an edit link / button next to the live URL. The edit link will perform the save function as unchecking the checkbox.

The pathauto settings would stay in the save place on the node/add form in the same field set.

timmillwood’s picture

FileSize
58.39 KB

Here's where I am so far.

mcrittenden’s picture

Sub. Nice work so far, Tim. Is this for Project Verity, by any chance?

klonos’s picture

looking really fine! ;)

...btw there could be a check about any trailing slashes and they could be auto-removed (perhaps if http:// and domain name was entered at the start of the edited field as well). Better not to leave things like that to the end users.

Dave Reid’s picture

I guess what I'm unsure of is what is actually being moved/removed from the 'Path' fieldset on the node add/edit form. Any number of modules could add form elements to the fieldset, so we can't get rid of it all. Or maybe you're changing the weight of the path fieldset to move it up above. Maybe longer screenshots would help me see the context?

timmillwood’s picture

The only reason it is up the top is that I am using the nodeformcols (http://drupal.org/project/nodeformcols) module to sort the fields. Maybe if I install the patch on an vanilla drupal install and allow anonymous posts you can all take a look.

timmillwood’s picture

timmillwood’s picture

Here is the latest patch and the new pathauto.css file.

Dave Reid’s picture

I can image a ton of support requests with people saying "I changed this random field value which is used to generate the URL. Why didn't the preview change?" I feel like we need to add something in the help text that says "This only previews changes to the title."

timmillwood’s picture

It will only be an issue if the settings on "admin/build/path/patterns" are changed. Maybe the help text should go there.

Or maybe if the pattern is invalid for live previews, then live previews is disabled.

greggles’s picture

I agree that help text makes more sense in the admin area and/or the idea of disabling the live previews for patterns that are weird. I think this functionality should work for title, global tokens (i.e. date), and most node tokens, right?

mcrittenden’s picture

I'm a little wary of only enabling it for certain patterns (i.e., those in which the only token is the node's title, I guess?). Seems like it would only add confusion for it to work on some content types and not on others, depending on how the patterns for those content types are set up.

IMO, it either needs to work consistently no matter what field is being changed and no matter what the pattern is (which may or may not be realistic), or it should not be included by default.

timmillwood’s picture

@greggles: yes, the patch generates a fake node object with $node->uid, $node->name, $node->title and $node->type, this is then passed to pathauto_get_placeholders() to generate which creates the tokens. So, yes, a lot of global and node tokens are available.

@mcrittenden: I think if we all can't agree on on things like this I would vote for it to be another contrib module "pathauto live" or something.

greggles’s picture

I just tested out the demo, it seems awesome to me.

Tim, what do you think, can you figure out which tokens won't work and disable it in those cases? I'd love to get this patch in and have some time to review/commit if we can get that last piece.

timmillwood’s picture

Shouldn't be a problem, I'll see what I can do over the next 24 hours.

timmillwood’s picture

It has been a month since I said "I'll see what I can do over the next 24 hours", but I have just been super busy with client work, drupalcon etc.

I do still want to get this done for Pathauto!

klonos’s picture

Ping?

timmillwood’s picture

pong.

It's still on my todo list.

klonos’s picture

I understand... real-life/no-time ;)

Don't mind if I 'ping' you every once in a month as a reminder. Do you?

klonos’s picture

Tim, I ain't gonna ask stupid questions because I know if you had progressed at all on this one you would have posted some news here. So, just pinging you so it doesn't get 'buried' in your todo list ;)

klonos’s picture

...and do remember the vertical tabs issue I reported back in #17. Let me know if I can help in any other way (besides coding this myself I mean).

Dave Reid’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev

Features must go in 7.x-1.x and then get backported to 6.x-2.x.

effulgentsia’s picture

Here's an approach that uses AJAX, so that it works for any token pattern without exposing the token structure to the client-side code. Whenever any form element is changed, the "live preview" is marked as needing an update, and via css, becomes grey. An AJAX request to update it is only triggered when the preview element is visible, so that if its vertical tab isn't currently open, we don't generate needless round trips to the server.

Because Pathauto is already at RC status, and this is experimental code, this is implemented as its own module. That way, people wanting it can enable it, but not every user of Pathauto has it forced on them until it's been well tested in the wild.

Dave Reid’s picture

@effulgentsia: Can you provide this is a sandbox in the meantime so I can easily check this out via git?

pyrello’s picture

@Dave Reid - I have gone ahead and set this up as a git project here: https://github.com/webgeeks/pathauto_live_preview

I am interested in getting this functionality working and so I will be taking a look at it and seeing what I can do.

Thanks!

Sean

cbrody’s picture

Thanks @pyrello for #48, which works fine. However, I haven't managed to move the live preview out of the default vertical tabs to directly below the title field where it properly belongs. Neither hook_form_alter() nor hook_form_BASE_FORM_ID_alter() seem to operate on the vertical tab groups. I also tried using Renderable elements together with Field group to move the relevant fields to near the top of the node edit form, but this is cumbersome, results in the relevant fields appearing twice, and breaks the edit button functionality. Any clues would be appreciated.

pyrello’s picture

@cbrody - I am accomplishing it via a custom module. Here is the code I am using:

function YOURMODULE_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['#node_edit_form']) && $form['#node_edit_form']) {
    $form['path']['#group'] = ''; // <-- This is what you are really looking for
    $form['path']['#title'] = '';
    $form['path']['#collapsible'] = FALSE;
    $form['path']['#collapsed'] = FALSE;
    $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
    $hostname = $_SERVER['SERVER_NAME'];
    $form['path']['alias']['#title'] = t('<strong>Link:</strong> @baseurl/', array('@baseurl' => $protocol . $hostname));
  }
}

This removes the path section from vertical tabs, as well as making several other modifications that I needed to make. Also, you could set the weight here, but I do it via the manage fields page for that content type.

Hope this helps!

Sean

bartmcpherson’s picture

FileSize
30.29 KB

Nice work so far.

This is a fringe case, but an AJAX error occurs if you make a change to the title and then immediately close the editing form. (Say you spontaneously changed your mind about making the edit.)
This happens with both the patch in #46 and the github project in #48.

An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /system/ajax
StatusText:
ResponseText:
ReadyState: 4

effulgentsia’s picture

baisong’s picture

Issue summary: View changes

Hi all, if anyone wants a simple, stable implementation of this on node forms, you can use alias_preview.

That said, this looks like a better general solution that could be integrated into a nearly-ubiquitous module! The issue in #51 seems to have been resolved (see https://www.drupal.org/project/drupal/issues/2808789), so maybe this can be merged in to 7.x-1.x?

Update: I just re-queued tests and there is one new failure:

"The Pattern for all Basic page paths cannot contain fewer than one token."