Have you seen our new video tutorials? Check it out!

Slug Field Type

The slug field type provides an URI/slug formatted input.

Introduction

anomaly.field_type.slug

The slug field type provides a an input that forces the value to a slug formatted string with a configurable separator.

Configuration

Below is a list of available configuration with default values:

"example" => [
    "type"   => "anomaly.field_type.slug",
    "config" => [
        "type"      => "_",
        "slugify"   => null,
        "lowercase" => true,
        "min"       => null,
        "max"       => null,
    ]
]
Configuration
Key Example Description

type

-

The slug type. Valid options are _ and -.

slugify

name

The field slug to automatically slugify.

lowercase

false

If enabled the slug will be forced to lowercase.

min

5

The minumum slug length allowed.

max

10

The maximum slug length allowed.

Usage

This section will show you how to use the field type via API and in the view layer.

Setting Values

You can set the value by string and the slug will be automatically generated:

$entry->example = "Ryan Thompson";

echo $entry->example; // ryan_thompson

Basic Output

The value returned is always null or the slug value:

$entry->example; // example_slug

Presenter Output

When accessing the field value from a decorated entry model the an instance of \Anomaly\FilesModule\Slug\SlugPresenter will be returned.

SlugFieldTypePresenter::humanize()

The humanize method returns the slug without separators.

Returns: string
Example
$decorated->example->humanize(); // ryan thompson

ucwords($decorated->example->humanize()); // Ryan Thompson
Twig
{{ decorated.example.humanize() }} // ryan thompson

{{ zucwords(decorated.example.humanize()) }} // Ryan Thompson