---
title: "Custom Extensions"
manual: "CKEditor Image Support"
version: "13.11"
permalink: "https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:examples-custom-extensions@13.11"
source: "Examples/Custom-Extensions.rst"
rendered: "2026-11-23T12:52:55+00:00"
---

# Custom Extensions {#examples-custom-extensions}

Advanced examples for extending the image plugin with custom attributes, external image handling, multi-language support, and backend processing.

**Table of Contents**

-   [Custom Image Attributes](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:custom-image-attributes@13.11)
-   [External Image Handling](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:external-image-handling@13.11)
-   [Multi-Language Setup](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:multi-language-setup@13.11)
-   [Custom Backend Processing](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:custom-backend-processing@13.11)
-   [Related Documentation](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:related-documentation@13.11)

## Custom Image Attributes {#custom-image-attributes}

### Extended Image Properties {#extended-image-properties}

**Objective**: Add custom attributes to the image model and its HTML

#### CKEditor Plugin Extension {#ckeditor-plugin-extension}

**EXT:my_site/Resources/Public/JavaScript/Plugins/extended-typo3image.js**

```javascript
import { Plugin } from '@ckeditor/ckeditor5-core';

export default class ExtendedTypo3Image extends Plugin {
    static get pluginName() {
        return 'ExtendedTypo3Image';
    }

    init() {
        const editor = this.editor;

        // Extend schema with custom attributes
        editor.model.schema.extend('typo3image', {
            allowAttributes: ['customCaption', 'customCopyright']
        });

        // Add upcast conversion
        editor.conversion.for('upcast').attributeToAttribute({
            view: 'data-custom-caption',
            model: 'customCaption'
        });

        // Add downcast conversion
        editor.conversion.for('downcast').attributeToAttribute({
            model: 'customCaption',
            view: 'data-custom-caption'
        });

        // Same pair for the second attribute
        editor.conversion.for('upcast').attributeToAttribute({
            view: 'data-custom-copyright',
            model: 'customCopyright'
        });
        editor.conversion.for('downcast').attributeToAttribute({
            model: 'customCopyright',
            view: 'data-custom-copyright'
        });

    }
}
```

> [!NOTE]
> The image dialog has no extension point for extra fields.
> The plugin fires no dialog event; the only custom event it fires is
> `dblclick:typo3image`, which opens the built-in dialog.
> Saving the dialog creates the image model element again from the dialog
> fields, so attributes added this way are lost once an editor edits the
> image in the dialog.
> Inline images use the separate `typo3imageInline` model, which needs
> its own `schema.extend()` and converters.
> Switching an image between block and inline also creates a new element
> from a fixed attribute list, so the custom attributes are lost there too.

#### Register Plugin {#register-plugin}

**Configuration/RTE/Extended.yaml**

```yaml
editor:
  config:
    importModules:
      - { module: '@my-vendor/my-site/extended-typo3image.js', exports: ['default'] }
```

TYPO3's RTE also accepts the module as a plain string, but integrations that
read the preset themselves, such as the Visual Editor of FriendsOfTYPO3, expect
the `{ module, exports }` form.

**Result**: Custom attributes survive loading and saving the content, but not editing the image in the dialog.

## External Image Handling {#external-image-handling}

### Fetch and Upload External Images {#fetch-and-upload-external-images}

#### Extension Configuration {#extension-configuration}

**settings.php**

```php
$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['rte_ckeditor_image'] = [
    'fetchExternalImages' => true,
];
```

#### Custom Upload Folder {#custom-upload-folder}

**User TSConfig**

```typoscript
options.defaultUploadFolder = 1:user_upload/rte_images/
```

**Result**: Automatic external image import ✅

## Multi-Language Setup {#multi-language-setup}

### Language-Specific Image Variants {#language-specific-image-variants}

#### Page TSConfig {#page-tsconfig}

```typoscript
[siteLanguage("languageId") == 0]
    # Default language (English)
    RTE.default.preset = default
[END]

[siteLanguage("languageId") == 1]
    # German
    RTE.default.preset = german
[END]

[siteLanguage("languageId") == 2]
    # French
    RTE.default.preset = french
[END]
```

#### RTE Configuration {#rte-configuration}

**Configuration/RTE/German.yaml**

```yaml
imports:
  - { resource: "EXT:rte_ckeditor_image/Configuration/RTE/Plugin.yaml" }

editor:
  config:
    language: de
    style:
      definitions:
        - name: 'Bild Links'
          element: 'img'
          classes: ['float-left']
        - name: 'Bild Rechts'
          element: 'img'
          classes: ['float-right']
```

**Result**: Language-specific configurations ✅

## Custom Backend Processing {#custom-backend-processing}

### Automatic Image Optimization {#automatic-image-optimization}

#### Custom Hook {#custom-hook}

**EXT:my_site/Classes/Hooks/ImageOptimizationHook.php**

```php
namespace MyVendor\MySite\Hooks;

use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class ImageOptimizationHook
{
    public function processDatamap_afterDatabaseOperations(
        string $status,
        string $table,
        string $id,
        array $fieldArray,
        DataHandler $dataHandler
    ): void {
        if ($table !== 'tt_content') {
            return;
        }

        foreach ($fieldArray as $field => $value) {
            if (!$this->isRteField($table, $field)) {
                continue;
            }

            // Find images in RTE content
            preg_match_all('/data-htmlarea-file-uid="(\d+)"/', $value, $matches);

            foreach ($matches[1] as $fileUid) {
                $this->optimizeImage((int)$fileUid);
            }
        }
    }

    protected function isRteField(string $table, string $field): bool
    {
        $tcaConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config'] ?? [];
        return ($tcaConfig['enableRichtext'] ?? false) === true;
    }

    protected function optimizeImage(int $fileUid): void
    {
        $fileRepository = GeneralUtility::makeInstance(FileRepository::class);

        try {
            $file = $fileRepository->findByUid($fileUid);

            // Generate optimized variants
            $file->process(
                \TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGECROPSCALEMASK,
                ['width' => 1920, 'height' => 1080]
            );

            // Generate WebP variant
            $file->process(
                \TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGECROPSCALEMASK,
                ['width' => 1920, 'height' => 1080, 'fileExtension' => 'webp']
            );
        } catch (\Exception $e) {
            // Log error
        }
    }
}
```

#### Register Hook {#register-hook}

**ext_localconf.php**

```php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][]
    = \MyVendor\MySite\Hooks\ImageOptimizationHook::class;
```

**Result**: Automatic optimization on save ✅

## Related Documentation {#related-documentation}

-   [CKEditor Plugin Development](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:ckeditor-plugin-development@13.11) \- Plugin development guide
-   [Event Listeners API](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:api-eventlisteners@13.11) \- Event listener API
-   [Testing Examples](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:examples-testing@13.11) \- Testing examples
-   [Integration & Configuration](https://docs.typo3.org/permalink/netresearch/rte-ckeditor-image:integration@13.11) \- Configuration guide
