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

URL Field Type

The URL field type provides an HTML5 URL input.

Introduction

The URL field provides a versatile URL input.

Configuration

Below is the full configuration available with defaults values:

"example" => [
    "type"   => "anomaly.field_type.url",
    "config" => [
        "default_value" => null,
    ]
]
Configuration
Key Required Type Default Description

default_value

false

string

none

The default value.

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 URL field type value with a string.

$entry->example = "http://pyrocms.com";

Basic Output

The URL field type returns the string value:

$entry->example; // http://pyrocms.com

Presenter Output

This section will show you how to use the decorated value provided by the \Anomaly\UrlFieldType\UrlFieldTypePresenter class.

UrlFieldTypePresenter::query()

The query field type return the URL query string as an array. An optional key can be passed to return a specific value.

Returns: array or string or null
Arguments
Key Required Type Default Description

$key

false

string

null

The the query key value to return.

Example
$id = $decorated->query('id');
Twig
ID: {{ decorated.query('id') }}

UrlFieldTypePresenter::parsed()

The parsed method returns the parsed URL.

Returns: array or string or null
Arguments
Key Required Type Default Description

$key

false

string

null

The the key value to return.

Example
$host = $decorated->parsed('host');
Twig
{{ decorated.parsed('host') }}

UrlFieldTypePresenter::link()

The link method returns an HTML link.

Returns: string
Arguments
Key Required Type Default Description

$title

false

string

The URL

The title of the link.

$attributes

false

array

null

The an associated array of the link attribute values.

Example
$decorated->link('PyroCMS');
Twig
{{ decorated.link('PyroCMS')|raw }}

UrlFieldTypePresenter::to()

The to method returns a URL to the provided path using the value as a root URL.

Returns: string
Arguments
Key Required Type Default Description

$path

false

string

null

The URI path to append to the URL.

Example
$decorated->to('docs'); // http://pyrocms.com/docs