Skip to content

Instantly share code, notes, and snippets.

@HelgeSverre
Created April 30, 2023 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HelgeSverre/5f85a73a05c88749e39754466a7a380a to your computer and use it in GitHub Desktop.
Save HelgeSverre/5f85a73a05c88749e39754466a7a380a to your computer and use it in GitHub Desktop.
Allow relative links in FilamentPHP's RichEditor Field.
<?php
namespace App\Providers;
use Filament\Facades\Filament;
use Illuminate\Contracts\View\View;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register() {}
public function boot()
{
Filament::registerRenderHook(
'body.start',
fn(): View => view('admin.trix-editor-url-workaround'),
);
}
}
<script>
// This hooks into attribute changes to the Trix "link field" and
// changes the type from "url" to "text" to allow for relative links.
document.addEventListener("DOMContentLoaded", function () {
const observer = new MutationObserver(() => {
document
.querySelectorAll('[data-trix-input][name=href]')
.forEach(el => el.type = "text");
});
document
.querySelectorAll('.trix-dialog--link')
.forEach(el => observer.observe(el, {attributes: true}));
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment