Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
murdercode committed Apr 28, 2022
2 parents 98d14dd + d3bc2ae commit 105eca3
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Nova4 TinyMCE Editor

I'm proud to present a simple wrapper that allows you to use the excellent **TinyMCE Editor(v6)** within Larvale Nova 4.

![](https://s10.gifyu.com/images/2022-04-21-12.44.26.gif)

# Prerequisites
- Laravel 9
- Laravel Nova 4
- TinyMCE API Key ([get one here](https://www.tiny.cloud/))

## How to install

In the root of your Laravel installation launch:
```bash
composer require murdercode/nova4-tinymce-editor
```

Then publish the config:
```bash
php artisan vendor:publish --provider="Murdercode\TinymceEditor\FieldServiceProvider"
```

A file in _config/nova_tinymce_editor.php_ will appear:

```php
<?php

return [
'init' => [
'menubar' => false,
'autoresize_bottom_margin' => 40,
'branding' => false,
'image_caption' => true,
'paste_as_text' => true,
'paste_word_valid_elements' => 'b,strong,i,em,h2',
],
'plugins' => [
'anchor advlist autolink autoresize autosave code fullscreen link lists image imagetools media
paste wordcount',
],
'toolbar' => [
'undo redo | formatselect |
bold italic underline strikethrough blockquote removeformat |
align bullist numlist outdent indent | link anchor table media insertmedialibrary | code restoredraft fullscreen',
],

'apiKey' => env('TINYMCE_API_KEY', ''),
];
```

In your **.env** file please add the key:
```
TINYMCE_API_KEY=[YOUR_PRECIOUS_PRIVATE_KEY]
```

**Please make sure** that you have added domain in your tiny.cloud account list.

## Register the Field

In your Nova/Resource.php add the field as following:

```php
<?php

use Murdercode\TinymceEditor\TinymceEditor;

class Article extends Resource
{
//...
public function fields(NovaRequest $request)
{
return [
TinymceEditor::make(__('Content'), 'content')
->rules(['required', 'min:20'])
->help(__('The content of the article.')),
];
}
}
//...
```

## Feedback and Support
Test, PR (also of this doc) are welcome.

40 changes: 40 additions & 0 deletions mix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const mix = require('laravel-mix')
const webpack = require('webpack')
const path = require('path')

class NovaExtension {
name() {
return 'nova-extension'
}

register(name) {
this.name = name
}

webpackPlugins() {
return new webpack.ProvidePlugin({
_: 'lodash',
Errors: 'form-backend-validation',
})
}

webpackConfig(webpackConfig) {
webpackConfig.externals = {
vue: 'Vue',
}

webpackConfig.resolve.alias = {
...(webpackConfig.resolve.alias || {}),
'laravel-nova': path.join(
__dirname,
'../../vendor/laravel/nova/resources/js/mixins/packages.js'
),
}

webpackConfig.output = {
uniqueName: this.name,
}
}
}

mix.extend('nova', new NovaExtension())

0 comments on commit 105eca3

Please sign in to comment.