Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev Feature Request - Auto Create URL titles #952

Closed
blairliikala opened this issue Mar 18, 2021 · 5 comments · Fixed by #2677 or #3046
Closed

Dev Feature Request - Auto Create URL titles #952

blairliikala opened this issue Mar 18, 2021 · 5 comments · Fixed by #2677 or #3046
Labels
enhancement New feature or request under review An EE team member is reviewing this issue

Comments

@blairliikala
Copy link

blairliikala commented Mar 18, 2021

Is your feature request related to a problem? Please describe.
When addons such as DataGrab or Smart Importer create new entries, they have to handle the logic of creating a URL title that EE thinks is valid. Also if the title is not unique. If this validation fails, the entry is rejected. This behavior changed between v2 and v3.

Describe the solution you'd like
EE should have a method in the Entries model to create a valid, unique, URL title when validation fails.

Describe alternatives you've considered
I created an extension that created a random URL title (since I don't use them). Could create an extension from the function below. Could modify the core, or addons to add this function.

Teachability, Documentation, Adoption, Migration Strategy
This should reduce documentation.

For reference, I think this is the EE v2 URL title method /system/codeigniter/system/helpers/url_helper.php

if ( ! function_exists('url_title'))
{
	function url_title($str, $separator = 'dash', $lowercase = FALSE)
	{
		if ($separator == 'dash')
		{
			$search		= '_';
			$replace	= '-';
		}
		else
		{
			$search		= '-';
			$replace	= '_';
		}

		$trans = array(
						'&\#\d+?;'				=> '',
						'&\S+?;'				=> '',
						'\s+'					=> $replace,
						'[^a-z0-9\-\._]'		=> '',
						$replace.'+'			=> $replace,
						$replace.'$'			=> $replace,
						'^'.$replace			=> $replace,
						'\.+$'					=> ''
					);

		$str = strip_tags($str);

		foreach ($trans as $key => $val)
		{
			$str = preg_replace("#".$key."#i", $val, $str);
		}

		if ($lowercase === TRUE)
		{
			$str = strtolower($str);
		}

		return trim(stripslashes($str));
	}
}
@blairliikala blairliikala changed the title Dev Feature Request - AutoCreate URL titles Dev Feature Request - Auto Create URL titles Mar 18, 2021
@TomJaeger
Copy link
Contributor

TomJaeger commented Mar 22, 2021

Hi @blairliikala Thanks for posting this.

I think the URL Slug in the text format services might do what your looking for?

https://docs.expressionengine.com/latest/development/services/format/text.html#url-slug


$url_title = ee('Format')->make('Text', 'A discussion about "Wonko the Sane"')->urlSlug();

// a-discussion-about-wonko-the-sane

@blairliikala
Copy link
Author

Ah fantastic!

So the second part of the request, can this be automatic when the entry is created if the URL slug is not included in the object? And also be made unique if it is not unique? The rational is since both entry id and url_title are required, and must be unique, that they be handled the same way, at least from the model standpoint where add-ons are creating entries.

@ops-andy ops-andy added enhancement New feature or request under review An EE team member is reviewing this issue labels Mar 24, 2021
@intoeetive
Copy link
Contributor

@blairliikala I don't think we can do that automatically, because this would essentially break URL Title validation for cases when it's not provided. I believe the add-ons that do import (or other kinds of entry creation) would need to implement URL title updating / creation within themselves as a configurable behavior

@intoeetive intoeetive closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2022
@pyrobob83
Copy link

Adding this here, but let me know if this would be better as a separate FR. I did search the issues and this was the closest one that made sense to comment on... It's also related to #2645 but that issue is requesting explicit control of how the url_titles are made unique.

I believe the change that happened between EE2 & 3 that Blair eluded to was the change to NOT automatically increment the url_title if it wasn't unique and instead force the editor to update it in the Publish screen. Why that decision was made, I have no idea, but it's caused all kinds of issues with clients ever since, particularly with sites utilizing Structure that don't even use url_title where devs typically hide that field away in a different tab to the content. My request is to reintroduce that native behavior and automatically postfix the url_title with an incrementing digit (like _1 then _2 etc) if it's not unique.

If there's a legit reason to not do this by default, then I'd be fine with CP option or config variable to control that. The only reason I can think of as to why this decision was made was because users didn't realize the url_title was being automatically amended, but if that's the case, I'd suggest a simple real-time notification explaining the url_title isn't unique and is being automatically updated. Even that, if deemed necessary, could maybe be optional via CP setting or config variable.

@intoeetive
Copy link
Contributor

I will reopen this ticket and we'll have a discussion internally. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request under review An EE team member is reviewing this issue
Projects
None yet
5 participants