---
title: "Services API"
manual: "CKEditor Image Support"
version: "13.11"
permalink: "https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:api-services@13.11"
source: "API/Services.rst"
rendered: "2026-11-23T12:52:55+00:00"
---

# Services API {#api-services}

<!-- TODO: no Markdown rendering for "versionadded" -->

The new service architecture replaces legacy controllers with a clean pipeline:
Parser → Resolver → Renderer.

The CKEditor Image Support extension uses a three-service architecture following TYPO3 v13
best practices with clear separation of concerns.

**Table of contents**

-   [Architecture overview](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:architecture-overview@13.11)
-   [ImageAttributeParser](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:imageattributeparser@13.11)
-   [ImageResolverService](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:imageresolverservice@13.11)
-   [ImageRenderingService](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:imagerenderingservice@13.11)
-   [Service decoration](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:service-decoration@13.11)
-   [Related documentation](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:related-documentation@13.11)

## Architecture overview {#architecture-overview}

```plantuml
skinparam componentStyle rectangle
skinparam backgroundColor white

component "ImageAttributeParser" as Parser
component "ImageResolverService" as Resolver
component "ImageRenderingService" as Renderer
component "Rendered HTML" as Output

note right of Parser
    HTML Parsing
    DOMDocument
    Attribute extraction
end note

note right of Resolver
    Business Logic
    Security Validation
    FAL Processing
end note

note right of Renderer
    Fluid Rendering
    ViewFactoryInterface
    Template Selection
end note

Parser --> Resolver : Raw attributes
Resolver --> Renderer : ImageRenderingDto
Renderer --> Output
```

Service pipeline architecture

## ImageAttributeParser {#api-imageattributeparser}

-   **class ImageAttributeParser**

    -   *Fully qualified name:* `\Netresearch\RteCKEditorImage\Service\ImageAttributeParser`

    Pure HTML parsing using `DOMDocument` \- no business logic.

### Responsibility {#responsibility}

-   Extract raw attributes from HTML strings.
-   Parse `<img>` tags within content.
-   Parse `<a>` tags containing `<img>` tags.
-   **NO** validation, **NO** sanitization - just parsing.

### Methods {#methods}

#### parseImageAttributes() {#parseimageattributes}

-   **parseImageAttributes($html)**

    Parse attributes from `<img>` tag HTML string.

    -   *param string $html:* HTML string containing `<img>` tag.
    -   *returntype:* array\<string,string>

    *Returns:* Attribute name => value pairs.

**Example:**

**Parsing image attributes**

```php
$parser = GeneralUtility::makeInstance(ImageAttributeParser::class);
$attributes = $parser->parseImageAttributes(
    '<img src="image.jpg" data-htmlarea-file-uid="123" alt="Example" />'
);
// Returns: ['src' => 'image.jpg', 'data-htmlarea-file-uid' => '123', 'alt' => 'Example']
```

#### parseLinkWithImages() {#parselinkwithimages}

-   **parseLinkWithImages($html)**

    Parse attributes from `<a>` tag containing `<img>` tags.

    -   *param string $html:* HTML string containing `<a><img /></a>`.
    -   *returntype:* array{link: array\<string,string>, images: array}

    *Returns:* Array with `link` and `images` keys.

**Return structure:**

**Return value structure**

```php
[
    'link' => ['href' => 'page.html', 'title' => 'Link title'],
    'images' => [
        [
            'attributes' => ['src' => 'image.jpg', 'alt' => 'Alt text'],
            'originalHtml' => '<img src="image.jpg" alt="Alt text" />'
        ]
    ]
]
```

## ImageResolverService {#api-imageresolverservice}

-   **class ImageResolverService**

    -   *Fully qualified name:* `\Netresearch\RteCKEditorImage\Service\ImageResolverService`

    Business logic, security validation, and FAL processing.

### Responsibility {#responsibility-1}

-   Transform raw attributes into validated DTOs.
-   Resolve FAL file references.
-   Apply security checks (file visibility, protocol blocking).
-   Process images with quality settings.
-   **ALL** security validation happens here.

### Security features {#security-features}

<!-- TODO: no Markdown rendering for "versionadded" -->

The service includes comprehensive security measures:

-   **File visibility validation**: Prevents access to hidden/restricted files.
-   **Protocol blocking**: Blocks dangerous protocols (`javascript:`, `file:`, `data:text/html`, `vbscript:`).
-   **XSS prevention**: Figcaption markup is reduced to an inline allowlist (`br`, `strong`, `b`, `em`, `i`, `a`);
    plain-text captions use `htmlspecialchars()` with `ENT_QUOTES | ENT_HTML5`.
-   **Type safety**: Read-only DTO properties prevent modification.

### Quality settings {#quality-settings}

<!-- TODO: no Markdown rendering for "versionadded" -->

The service supports quality multipliers for image processing:

**Quality constants in ImageResolverService**

```php
const QUALITY_NONE     = 'none';     // N/A - Skip processing entirely
const QUALITY_LOW      = 'low';      // 0.9x - Performance optimized
const QUALITY_STANDARD = 'standard'; // 1.0x - Default
const QUALITY_RETINA   = 'retina';   // 2.0x - High-DPI displays
const QUALITY_ULTRA    = 'ultra';    // 3.0x - Extra sharp
const QUALITY_PRINT    = 'print';    // 6.0x - Print quality
```

### Methods {#methods-1}

#### resolve() {#resolve}

-   **resolve($attributes, $conf, $request, $linkAttributes = null, $figureClass = null, $figureWidth = null)**

    Resolve image attributes to validated DTO.

    -   *param array $attributes:* Raw attributes from parser.
    -   *param array $conf:* TypoScript configuration.
    -   *param ServerRequestInterface $request:* Current request.
    -   *param array|null $linkAttributes:* Optional link attributes for linked images.
    -   *param string|null $figureClass:* Optional figure class for alignment (for example `image-left`).
    -   *param string|null $figureWidth:* Optional normalized resize width from the figure (for example `26.43%`).
    -   *returntype:* ImageRenderingDto|null
    -   *throws NonPublicFileException:*

        If the file is in a non-public storage.
        The caller must render nothing for the image.

    *Returns:* Validated DTO or null if validation fails.

**Example:**

**Resolving image attributes to DTO**

```php
$resolver = GeneralUtility::makeInstance(ImageResolverService::class);

try {
    $dto = $resolver->resolve(
        $attributes,
        $typoScriptConfig,
        $request
    );
} catch (NonPublicFileException) {
    // File is in a non-public storage - render nothing
    return '';
}

if ($dto === null) {
    // Validation failed - return original content
    return $content;
}
```

## ImageRenderingService {#api-imagerenderingservice}

-   **class ImageRenderingService**

    -   *Fully qualified name:* `\Netresearch\RteCKEditorImage\Service\ImageRenderingService`

    Presentation layer using TYPO3 v13 `ViewFactoryInterface`.

### Responsibility {#responsibility-2}

-   Render validated DTOs via Fluid templates.
-   Select appropriate template based on context.
-   **NO** business logic, **NO** validation - trusts the DTO.

### Template selection {#template-selection}

The service automatically selects templates based on the rendering context:

| Context | Template |
| --- | --- |
| Standalone image | `Image/Standalone` |
| Image with caption | `Image/WithCaption` |
| Image within link | `Image/Link` |
| Linked image with caption | `Image/LinkWithCaption` |
| Image with zoom/popup | `Image/Popup` |
| Popup image with caption | `Image/PopupWithCaption` |

### Methods {#methods-2}

#### render() {#render}

-   **render(ImageRenderingDto $imageData, ServerRequestInterface $request, array $config = \[\]) : string**

    Render image HTML from validated DTO.

    -   *param ImageRenderingDto $imageData:* Validated image data.
    -   *param ServerRequestInterface $request:* Current request.
    -   *param array $config:* TypoScript configuration for template paths.
    -   *returntype:* string

    *Returns:* Rendered HTML.

**Example:**

**Rendering image from DTO**

```php
$renderer = GeneralUtility::makeInstance(ImageRenderingService::class);
$html = $renderer->render($dto, $request);
```

## Service decoration {#service-decoration}

To customize service behavior, use Symfony service decoration.
`ImageRenderingAdapter` type-hints the concrete class
`ImageResolverService` in its constructor, and the extension provides no
interface for it.
The decorating service must therefore extend `ImageResolverService`;
a class that only wraps it causes a `TypeError` when the adapter is
created.

**EXT:my_extension/Configuration/Services.yaml**

```yaml
App\Service\CustomImageResolver:
  decorates: Netresearch\RteCKEditorImage\Service\ImageResolverService
```

**EXT:my_extension/Classes/Service/CustomImageResolver.php**

```php
<?php

declare(strict_types=1);

namespace App\Service;

use Netresearch\RteCKEditorImage\Domain\Model\ImageRenderingDto;
use Netresearch\RteCKEditorImage\Service\ImageResolverService;
use Psr\Http\Message\ServerRequestInterface;

class CustomImageResolver extends ImageResolverService
{
    public function resolve(
        array $attributes,
        array $conf,
        ServerRequestInterface $request,
        ?array $linkAttributes = null,
        ?string $figureClass = null,
        ?string $figureWidth = null,
    ): ?ImageRenderingDto {
        // Custom pre-processing
        $dto = parent::resolve(
            $attributes,
            $conf,
            $request,
            $linkAttributes,
            $figureClass,
            $figureWidth,
        );
        // Custom post-processing
        return $dto;
    }
}
```

The subclass inherits the constructor of `ImageResolverService`.
The extension wires its arguments explicitly in its `Services.yaml`;
check that your service definition provides the same arguments.

## Related documentation {#related-documentation}

-   [DTOs](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:api-dtos@13.11) \- Data transfer objects.
-   [Controllers API](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:api-controllers@13.11) \- TypoScript adapter.
-   [Template Overrides](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:examples-template-overrides@13.11) \- Customizing output.
