BKWLD / decoy

A Laravel model-based CMS
http://docs.decoy.bukwild.com/
MIT License
303 stars 44 forks source link

Wrap Image Field $src in asset #75

Open toddvalentine opened 7 years ago

toddvalentine commented 7 years ago

Can we wrap the $src below from Bkwld's Image field in the asset method so it plays nice with Laravel sub-directory installs? Bkwld\Decoy\Fields\Image::renderEditor()

        if ($src = Former::getValue($this->inputName('file'))) {
            $src = Croppa::url($src, 1050);
        }

Tried using the container to override and running into issues with private methods and instances being new'd up instead of being made from the container.

weotch commented 7 years ago

Yeah I could, I'm surprised this would be enough of a fix, though. Are you not using the Croppa helpers on your public site? How is your Laravel configured so that asset() fixes it for you? Or does it just happen automatically with no configuration?

Just trying to find the most comprehensive fix possible with these questions.

Relates a bit to #63

toddvalentine commented 7 years ago

I am using a couple different strategies to tackle the sub-directory issue.

I have created a Service Provider:

    public function register()
    {
        $this->app['path.public'] = base_path().DIRECTORY_SEPARATOR.'public';

        if (App::environment(['staging'])) {
            $this->app['path.public'] = '/site.com/my/path';

            $path =  '/site.com/my/path/uploads';

            $this->app['config']->set('upchuck.disk.path', $path);
            $this->app['config']->set('croppa.src_dir', $path);
            $this->app['config']->set('croppa.crops_dir', $path);
        }

        if (App::environment(['production'])) {

        }
    }

I have also set up a env var that I change based on environment that I use in config/decoy/core to properly get path for assets and in config/decoy/site to properly set nav paths.

The asset wrap would cover the instance where the image is not showing in the admin

toddvalentine commented 7 years ago

To get correct routes to destroy, I have also had to customize the shared footer haml files to use

%a.btn.btn-danger.delete(href=DecoyURL::relative('destroy', $item->id))
                %span.glyphicon.glyphicon-trash.glyphicon
                != __('decoy::form.actions.delete')

to

%a.btn.btn-danger.delete(href=URL::to(DecoyURL::relative('destroy', $item->id)))
                %span.glyphicon.glyphicon-trash.glyphicon
                != __('decoy::form.actions.delete')