protected function _slug($string, $entity)
    {
        $string = $this->_mbTrim(mb_strtolower($string));
        $config = $this->config();
        $slug = Inflector::slug($string, $config['separator']);
        $pk = $this->_table->primaryKey();

        if (mb_strlen($slug) > $config['length']) {
            $slug = mb_substr($slug, 0, $config['length']);
        }

        $conditions = ["{$config['slug']} LIKE" => "{$slug}%"];
        if ($entity->has($pk)) {
            $conditions["{$pk} NOT IN"] = [$entity->{$pk}];
        }

        $same = $this->_table->find()
            ->where($conditions)
            ->all()
            ->extract($config['slug'])
            ->toArray();

        if (!empty($same)) {
            $initialSlug = $slug;
            $index = 1;
            while ($index > 0) {
                $nextSlug = "{$initialSlug}{$config['separator']}{$index}";
                if (!in_array($nextSlug, $same)) {
                    $slug = $nextSlug;
                    $index = -1;
                }

                $index++;
            }
        }

        return $slug;
    }