You are viewing beta documentation for Hyper 3.x.
Reference

Link Type API

Registered link classes define destination behaviour and provide settings and input controls. Start with Creating Link Types for a complete registration example. These methods are extension points for subclasses of verbb\hyper\base\Link.

Settings and Input Configuration

displayName(): string

Purpose: Name shown for the type.

Name shown for the type.

getSettingsConfig(): array

Purpose: Settings to retain on the link type definition.

Settings to retain on the link type definition.

getInputConfig(): array

Purpose: Configuration and current values supplied to the input.

Configuration and current values supplied to the input.

getSettingsHtmlVariables(): array

Purpose: Template variables including linkType.

Template variables including linkType.

getInputHtmlVariables(LinkField $layoutField, HyperField $field): array

Purpose: Input context including link, layoutField and field.

Input context including link, layoutField and field.

getSettingsHtml(): ?string

Purpose: Type-specific settings controls.

Type-specific settings controls.

getInputHtml(LinkField $layoutField, HyperField $field): ?string

Purpose: The destination input inside the Link layout field.

The destination input inside the Link layout field.

The following is a partial class example. Add these members to your custom link class when its settings template includes a hint input and its browser input needs that hint:

public ?string $hint = null;

public function getSettingsConfig(): array
{
    $values = parent::getSettingsConfig();
    $values['hint'] = $this->hint;

    return $values;
}

public function getInputConfig(): array
{
    $values = parent::getInputConfig();
    $values['hint'] = $this->hint;

    return $values;
}

getSettingsConfig() makes the setting available for persistence with the definition. getInputConfig() does not replace that persistence or save arbitrary editor content. Store editor values in linkValue or custom layout fields; see Saved Content.

Destination Behaviour

getLinkUrl(): ?string

Purpose: Resolve the type-specific destination before prefix, suffix and URL-policy checks.

Resolve the type-specific destination before prefix, suffix and URL-policy checks.

getLinkText(): ?string

Purpose: Resolve the type’s label, including appropriate defaults.

Resolve the type’s label, including appropriate defaults.

isInstanceEmpty(LinkInstance $instance): bool

Purpose: Static check for meaningful saved content.

Use this storage and authoring check to recognise entered destinations, labels, attributes or custom fields without requiring a resolvable URL. It is separate from a Link’s public isEmpty(), which checks its resolved destination. Preserve that separation when extending a link type so temporarily unavailable destinations do not discard authored content.

getRequiredPlugins(): array

Purpose: Static list of plugins needed for this type to be available.

Static list of plugins needed for this type to be available.

supportsBulkCreation(): bool

Purpose: Static opt-in to bulk creation.

Static opt-in to bulk creation.

bulkCreationMode(): ?string

Purpose: Static bulk input mode for an opted-in type.

Static bulk input mode for an opted-in type.

Element types extend verbb\hyper\base\ElementLink and implement the static elementType(): string method. supportsUriSelectorCriteria(): bool controls whether URI-based selector settings apply. Keep getElement() nullable and respect the destination’s site and status.

The registry event is verbb\hyper\services\Links::EVENT_REGISTER_LINK_TYPES with a craft\events\RegisterComponentTypesEvent. Append your class to $event->types when registering it.