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

Slug conversion to ASCII does not work when using custom title #2096

Closed
steveooo9 opened this issue Nov 8, 2017 · 15 comments
Closed

Slug conversion to ASCII does not work when using custom title #2096

steveooo9 opened this issue Nov 8, 2017 · 15 comments

Comments

@steveooo9
Copy link

steveooo9 commented Nov 8, 2017

Description

Auto-generate slugs (conversion from ä-ö-ü-ß => ae-oe-ue-ss) from a title does work, but defining a title like {entryField.first().title} doesn't convert the äüöß, but removes them.

Steps to reproduce

  1. Define auto title like {entryField.first().title}
  2. Remove previously generated slug
  3. Save a title with "öäüßÖÄÜ" and see that everything non-ASCII get's removed instead of converted

If you can't reproduce, I am glad to help in any further bugfixing!

@brandonkelly
Copy link
Member

What version of Craft are you seeing this in?

@steveooo9
Copy link
Author

@brandonkelly I am using Craft CMS 2.6.2989

@brandonkelly
Copy link
Member

Just tested and I’m not able to reproduce on 2.6.2997. Can you try updating and see if that helps?

The only thing I can think of is, maybe you enabled the limitAutoSlugsToAscii config setting in craft/config/general.php? Although if you had, it should have affected the auto-generated slug as well.

@steveooo9
Copy link
Author

steveooo9 commented Nov 9, 2017

@brandonkelly I am unable to test in the most recent version at the moment..

I have following in my general.php: 'omitScriptNameInUrls' => true, 'limitAutoSlugsToAscii' => true, 'convertFilenamesToAscii' => true,

@brandonkelly
Copy link
Member

'limitAutoSlugsToAscii' => true is your problem. You are telling Craft to downgrade/discard anything but plain ASCII characters in slugs.

@steveooo9
Copy link
Author

steveooo9 commented Nov 9, 2017

@brandonkelly But this conversion from ä => ae and such did work before... Where do I control these character conversions?

I want that my characters (often used in German language) äöüßÄÖÜ to convert to the corresponding ASCII letters..

@steveooo9
Copy link
Author

@brandonkelly It seems that the logic from the limitAutoSlugsToAscii setting (discard anything but ASCII chars) is being applied before some other character conversions (e.g. ä => ae)?

@brandonkelly
Copy link
Member

@steveooo9 Tested both and both were converting correctly for me. Possible you added that config setting after the initial entry had been saved?

@brandonkelly
Copy link
Member

There are two places that config setting is taken into account – in the CP JavaScript, when auto-populating the Slug value as you type in the Title field, and in the PHP when the entry is being saved.

@angrybrad
Copy link
Member

I'm not able to reproduce this on a stock Craft install, either. The limitAutoSlugsToAscii config settings calls StringHelper::asciiString($str), which uses the Craft default ASCII character mappings, but also factors in any custom ASCII character mappings via the customAsciiCharMappings config setting. Are you setting any custom mappings via that last config setting?

@steveooo9
Copy link
Author

@takobell Can it be that when using auto title via entry.first().titlesomehow a step is missing? Is seems that without it everything get's lowercased and ASCII get mapped. Maybe with the first one, only it get's ASCII mapped but not lowercased. In Craft's asciiString method, there's no conversion for uppercase ÖÄÜ, so maybe there's an issue?

@brandonkelly
Copy link
Member

brandonkelly commented Nov 15, 2017

@steveooo9 Try this for me… open up craft/app/helpers/ElementHelper.php and replace your setValidSlug() method with this:

public static function setValidSlug(BaseElementModel $element)
{
	$slug = $element->slug;

	if (!$slug)
	{
		// Create a slug for them, based on the element's title.
		// Replace periods, underscores, and hyphens with spaces so they get separated with the slugWordSeparator
		// to mimic the default JavaScript-based slug generation.
		$slug = str_replace(array('.', '_', '-'), ' ', $element->title);

		// Enforce the limitAutoSlugsToAscii config setting
		if (craft()->config->get('limitAutoSlugsToAscii'))
		{
			if (!craft()->config->get('allowUppercaseInSlug'))
			{
				// Do this now because our ASCII character mappings are lowercase only.
				$slug = mb_strtolower($slug);
			}

			$slug = StringHelper::asciiString($slug);
		}
	}

	$element->slug = static::createSlug($slug);
}

Then clear out the auto-generated entry slug and try re-saving it.

@brandonkelly brandonkelly reopened this Nov 15, 2017
@steveooo9
Copy link
Author

@brandonkelly Yep, this works great! Great fix!

@brandonkelly
Copy link
Member

Awesome, thanks for letting me know. We’ll get that fix into the next release.

@steveooo9
Copy link
Author

@brandonkelly Great!

brandonkelly added a commit that referenced this issue Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants