Documentation

Lnk
in package

This is a system of portable, extensible link management.

The system is based around the "link specification", which is a string. Link specifications should be stored in a TEXT field.

These specs relate to classes which extend LinkSpec. The class name needs to start with "LinkSpec" too.

Table of Contents

Methods

atag()  : string
Return an opening A tag for a link specification.
editform()  : string
Output html for editing link specifications.
editformNeeds()  : mixed
Some edit forms require additional javascript via the {@see needs} helper Load in all of these requirements for all LinkSpec classes
instance()  : array<string|int, mixed>
For a given link specification, instance it's class
parse()  : array<string|int, mixed>
Parse a link specification.
tryUrl()  : string|null
Attempts to convert a link specification into a URL
typename()  : string
Output the name of the type of the linkspec.
url()  : string|null
Convert a link specification into a URL.
valid()  : bool
Check if the data supplied for a spec is valid.

Methods

atag()

Return an opening A tag for a link specification.

public static atag(string|array<string|int, mixed> $spec[, array<string|int, mixed> $attributes = array() ]) : string
Parameters
$spec : string|array<string|int, mixed>

A link specification

$attributes : array<string|int, mixed> = array()

Additional link attributes These take precedence over any default attributes

Tags
throws
InvalidArgumentException

If the link specification is malformed (invalid data, missing class)

Return values
string —

HTML for an opening A tag

editform()

Output html for editing link specifications.

public static editform(string $field_name[, string $curr_spec = null ][, bool $required = false ]) : string

This is designed for admin use.

Parameters
$field_name : string

The name to use for the field

$curr_spec : string = null

Current spec data, for existing fields

$required : bool = false

Is it a required field?

Return values
string —

HTML

editformNeeds()

Some edit forms require additional javascript via the {@see needs} helper Load in all of these requirements for all LinkSpec classes

public static editformNeeds() : mixed

instance()

For a given link specification, instance it's class

public static instance(string|array<string|int, mixed> $spec[, LinkSpec>|array<string|int, LinkSpec>> $assert = null ]) : array<string|int, mixed>
Parameters
$spec : string|array<string|int, mixed>
$assert : LinkSpec>|array<string|int, LinkSpec>> = null

must match one of these (not all)

Tags
throws
InvalidArgumentException

If the link specification is malformed (invalid data, missing class)

Return values
array<string|int, mixed> —

[0] => instance, [1] => spec data, [2] => spec label (as registered)

parse()

Parse a link specification.

public static parse(mixed $spec) : array<string|int, mixed>
Parameters
$spec : mixed
Tags
throws
InvalidArgumentException
Return values
array<string|int, mixed> —

[ class, data, label ]

tryUrl()

Attempts to convert a link specification into a URL

public static tryUrl(string|array<string|int, mixed> $spec) : string|null

This differs in behaviour to Lnk::url as it will return null if the spec is empty, but not malformed; it still throws an InvalidArgumentException in that case. It will also return null if a RowMissingException is thrown by the link spec instance during processing.

Helpful when you wish to avoid breaking pages when someone deletes the linked record, e.g. a blog post, without updating the corresponding link(s).

Parameters
$spec : string|array<string|int, mixed>

A JSON link specification

Tags
throws
InvalidArgumentException

If the link specification is malformed (invalid data, missing class)

Return values
string|null —

The target URL or null if the spec is empty or if a RowMissingException is thrown during processing.

typename()

Output the name of the type of the linkspec.

public static typename(string|array<string|int, mixed> $spec) : string
Parameters
$spec : string|array<string|int, mixed>

A link specification

Tags
throws
InvalidArgumentException

If the link specification is malformed (invalid data, missing class)

Return values
string

url()

Convert a link specification into a URL.

public static url(string|array<string|int, mixed> $spec) : string|null
Parameters
$spec : string|array<string|int, mixed>

A link specification

Tags
throws
InvalidArgumentException

If the link specification is malformed (invalid data, missing class)

Return values
string|null —

Target URL, or null if the target cannot be resolved

valid()

Check if the data supplied for a spec is valid.

public static valid(string|array<string|int, mixed> $spec) : bool
Parameters
$spec : string|array<string|int, mixed>

A link specification

Tags
throws
InvalidArgumentException

If the link specification is malformed (invalid data, missing class)

Return values
bool —

True if valid, false if invalid

On this page

Search results