mjawad096 / laravel-grapesjs

This package provide an esay way to integrate GrapesJS into your laravel proejct.
MIT License
107 stars 54 forks source link

How can I use modified Assets php files ? #40

Closed sergeynilov closed 2 years ago

sergeynilov commented 2 years ago

Hello, Working with "jd-dotlogics/laravel-grapesjs": "^3" I need to extend data returned from server's requests. I found that server's requests are implemented in /vendor/jd-dotlogics/laravel-grapesjs/src/App/Repositories/AssetRepository.php /vendor/jd-dotlogics/laravel-grapesjs/src/App/Editor/AssetManager.php files. I can not edit these files, as any file any “/vendor” subdirectory would be overwritten by composer. If there is a way to use copied under project directories these files and use them, modifying where I need it ?

Thanks!

ghost commented 2 years ago

Hello, these classes are being resolved from the Larave container. So you can simply create your class, and extend your class from your respective editor class, then bind in the service provider. For example, to extend AssetRepository create a new file "app/Vendor/Editor/AssetRepository.php" (you can place it anywhere in your project )

<?php 

namespace App\Vendor\Editor;

use Dotlogics\Grapesjs\App\Repositories\AssetRepository as BaseAssetRepository;

class AssetRepository extends BaseAssetRepository
{

//Override any method you want from the parent class 

}

Then in the boot method of your AppServiceProvider bind your new class

use App\Vendor\Editor\AssetRepository;
use Dotlogics\Grapesjs\App\Repositories\AssetRepository as BaseAssetRepository;

/**
 * Bootstrap your package's services.
 *
 * @return void
 */
public function boot()
{
    $this->app->bind(BaseAssetRepository::class, AssetRepository::class);
}

Hopefully it resolved your problem.

sergeynilov commented 2 years ago

Thanks for your feedback! It was usefull and I found how to manage server part on laravel. But I need to add additive parameter to url laravel-grapesjs.assets.upload_url from client side.

Any hint where on client side url above is fetched ?

I need to edit public/vendor/laravel-grapesjs/assets/editor.js file anyway - I can not do it in another way. All images has category and editors page has selection category input. I need to add selected category id to this assets.upload_url ...

ghost commented 2 years ago

@sergeynilov There are multiple ways to override upload URL.

  1. Add it to config laravel-grapesjs.assets.upload_url
  2. There is a method called getUploadUrl in AssetRepository -- This method sends the upload URL to the editor. You can override that method.
  3. Override editor config as described here https://github.com/jd-dotlogics/laravel-grapesjs/issues/18#issuecomment-1132712115