---
title: Field Type
date: 2026-06-12T22:27:00+01:00
author: John Henry Donovan
canonical_url: "https://johnhenry.ie/plugins/matrix-block-anchor/docs/api/field-type"
section: Plugins
---
esc

↑↓ to navigate↵ to selectesc to close

Menu On this page 

- [Return to top](#)

Documentation

Documentation

# Field Type API

`MatrixBlockAnchorField` extends `craft\base\Field` and implements `craft\base\PreviewableFieldInterface`.

**Class:** `johnhenry\matrixblockanchor\fields\MatrixBlockAnchorField`

## Methods

### `normalizeValue(mixed $value, ?ElementInterface $element): string`

Returns the resolved anchor ID for a given element. If custom anchors are enabled and the editor has set a value, returns that value (stripped of any `#` prefix). Otherwise returns `{prefix}{separator}{blockId}`.

### `getInputHtml(mixed $value, ?ElementInterface $element): string`

Renders the field input. When custom anchors are disabled, renders a read-only display of the auto-generated anchor. When enabled, renders an editable text input alongside the auto-generated anchor as a fallback preview.

### `getElementValidationRules(): array`

Registers the `validateAnchorId` validator, which enforces:

- Starts with a letter
- Contains only `[a-zA-Z0-9_-]`
- Does not exceed 100 characters
- Is unique within the owner entry

### `getAnchorPrefix(): string`

Returns the configured anchor prefix from plugin settings. Defaults to `blockIdAnchor`.

### `getAllowCustomAnchors(): bool`

Returns whether editors may set a custom anchor on blocks using this field.

### `getPreviewHtml(mixed $value, ElementInterface $element): string`

Returns `#anchorId` for display in element index preview columns.

## Template Output

The field value is the anchor ID **without** a `#` prefix. Use it directly as an `id` attribute:

```twig
<section id="{{ block.anchorField }}">
```

To build a full anchor link:

```twig
<a href="#{{ block.anchorField }}">Jump to section</a>
```

On this page
