change permalink when title changes

5 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: March 9, 2022   (RSS)

By kitsguru - March 1, 2022 - edited: March 1, 2022

A hook system in the permalink plugin would be very useful. OR allow 'category:label' in autopopulate_fromFields

Jeff Shields

By kitsguru - March 6, 2022

I have written some custom js to do what I need to do. Here it is for anyone who wants to use it.

# custom.js

$(document).ready(function() {
	$("input[name=title], input[name=name], select[name=category]").on('change', function() {
		// console.log('name or title changed');
		$("input[name=permalink]").val("");
	});
});

I have renamed 'title' to 'name' in some table, and have a 'category' field in most tables. If any of these change then the permalink is cleared and reset on save.

I have a custom plugin to handle the category lookup for label since the permalink does not currently support 'category:label'.

Jeff Shields

By daniel - March 9, 2022

Hey Jeff,

Thanks for posting your update!

Another similar idea would be to use the record_presave hook to check to see if a field has been changed and similarly empty the permalink from the $_REQUEST array. Since the record_presave hook provides the old record's data (new data is in $_REQUEST), it would be relatively simple to compare the new and old values. There's an example included in the Permalinks readme.txt for creating custom permalink formats with a plugin - this should have most of the info required to set this up.

I'll note that we do have "category:label" support in the works for an upcoming release of the Permalinks plugin. Keep an eye out for this! Also, If you have any specific hooks you think would be useful within the plugin, let me know and I can bring them up for consideration.

Thanks,

Daniel
Technical Lead
interactivetools.com

By kitsguru - March 9, 2022

One thing I would like to see is being able to use a / in some cases when using 2 fields.

So ”city address” instead of ‘mycity-123-anywhere’ could be ‘mycity/123-anywhere’

Jeff Shields