Skip to content

Combining translatable with images in a Trix field does not work #85

@bmellink

Description

@bmellink

When using withFiles() to store images within a Trix field, the browser generates 404 errors when inserting the image (during edits). Example

public function fields(Request $request) {
    return [
        ID::make(__('ID'), 'id')->sortable(),
        Translatable::make([
	    Text::make('title')->sortable(),
	    Trix::make('text')->hideFromIndex()->withFiles(env('POSTS_DISK','public')),
        ]),
       ...
    ]
}

The browser will try to call a POST URL /nova-api/posts/field-attachment/translations_text_xx/{uuid of post} for each language (where xx is the language code). These URLs don't exist.

Workaround is to add hidden dummy fields for each language to ensure the URLs exist and nova can actually store the image file:

public function fields(Request $request) {
    return [
        ID::make(__('ID'), 'id')->sortable(),
        Translatable::make([
	    Text::make('title')->sortable(),
	    Trix::make('text')->hideFromIndex()->withFiles(env('POSTS_DISK','public')),
        ]),
	Trix::make('translations_text_en')->withFiles(env('POSTS_DISK','public'))->hideWhenCreating()->hideWhenUpdating()->hideFromDetail(),
	Trix::make('translations_text_nl')->withFiles(env('POSTS_DISK','public'))->hideWhenCreating()->hideWhenUpdating()->hideFromDetail(),
       ...
    ]
}

For this workaround to work the name of the dummy fields should be "translations_<original fieldname>_<language code>"
This will need to be fixed in the code, or clear instructions can be added to the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions