<p>Brad, I realize my initial question is a bit vague, oops! I did however find a solution to why my localized slugs for my plugin element weren't being saved as a unique string.</p>

<p>I traced through <code>ElementHelper::setUniqueUri()</code> and figured out I was missing the <code>getUrlFormat()</code> function. Also to make sure I include <code>{slug}</code> in my <code>urlFormat</code> string in this particular case.</p>

CC BY-SA 3.0
2016-02-19T18:31:49.527Z
2016-02-19T18:31:49.527Z
Sean Langlands
<p>A bit hard to tell what you're trying to do from the description and without seeing some code examples, but internally Craft uses <a href="https://craftcms.com/classreference/helpers/ElementHelper#setValidSlug-detail" rel="nofollow">ElementHelper::setValidSlug()</a> and <a href="https://craftcms.com/classreference/helpers/ElementHelper#setUniqueUri-detail" rel="nofollow">ElementHelper::setUniqueUri()</a> to perform those tasks.</p>

<p>Whether you need to use them directly or call a Craft method that uses them is hard to say without more context.</p>

CC BY-SA 3.0
2016-02-05T18:23:04.337Z
2016-02-05T18:23:04.337Z
Brad Bell
<p>I have my slug saving to the <code>element_i18n</code> table but it's not unique. When saving a non-unique slug using the default Craft entries, the slug gets appended with "-1".</p>

<p>How can I extend the default functionality for a slug?</p>

<plugins><slug>
How to utilize unique slugs for plugin elements that extend the BaseElement class
# How to utilize unique slugs for plugin elements that extend the BaseElement class

(Asked by: username_0 on 2016-02-05)

I have my slug saving to the `element_i18n` table but it's not unique. When saving a non-unique slug using the default Craft entries, the slug gets appended with "-1".

How can I extend the default functionality for a slug?

**Tags:** plugins, slug

---

## 2 answers

### Answer by username_0 on 2016-02-19. Score: 1 | Accepted answer

Brad, I realize my initial question is a bit vague, oops! I did however find a solution to why my localized slugs for my plugin element weren't being saved as a unique string.

I traced through `ElementHelper::setUniqueUri()` and figured out I was missing the `getUrlFormat()` function. Also to make sure I include `{slug}` in my `urlFormat` string in this particular case.


---

### Answer by username_1 on 2016-02-05. Score: 0

A bit hard to tell what you're trying to do from the description and without seeing some code examples, but internally Craft uses [ElementHelper::setValidSlug()](https://craftcms.com/classreference/helpers/ElementHelper#setValidSlug-detail) and [ElementHelper::setUniqueUri()](https://craftcms.com/classreference/helpers/ElementHelper#setUniqueUri-detail) to perform those tasks.

Whether you need to use them directly or call a Craft method that uses them is hard to say without more context.


---

