LaravelRUS / SleepingOwlAdmin

🦉 Administrative interface builder for Laravel (Laravel admin)
http://sleepingowladmin.ru/
MIT License
805 stars 217 forks source link

AdminFormElement::view get 'Call to a member function getName() on null' #174

Closed denistorresan closed 8 years ago

denistorresan commented 8 years ago

Hello, I recently updates the SleepingOwl package (from 4.17.88-beta to 4.41.8), and now all 'views' I defined into forms goes to error. My form is like:

    // Create And Edit
    $model->onCreateAndEdit(function() {
        return $form = AdminForm::panel()->addBody(
            AdminFormElement::text('name', 'Name')->required(),
            AdminFormElement::text('slug', 'Slug')->required(),
            AdminFormElement::textarea('note', 'Note')->setRows(2),
            AdminFormElement::checkbox('scheduler_enabled', 'Scheduler Enabled'),
            AdminFormElement::view('sleeping_owl::customers.modules'),
            AdminFormElement::view('sleeping_owl::customers.configure')
        );

        return $form;
    });

and I got this error when I try to edit an element:

FatalErrorException in Assets.php line 76: Call to a member function getName() on null

When I comment AdminFormElement::view all works good, so maybe there's some changes into 'View' class. I never figure out how to fix it, also because I never found an example on Demo about 'View'.

I also try calling the method AdminFormElement::view(''), same error.

Thank you! Denis

denistorresan commented 8 years ago

Hey, I fixed SleepingOwl\Admin\Form\Element\View class, source (/vendor/laravelrus/sleepingowl/src/Form/Element/View.php) in this way (I copy from Html.php).

here the working code:

<?php

namespace SleepingOwl\Admin\Form\Element;

class View extends Custom
{
    /**
     * @var string
     */
    protected $view;

    /**
     * @param string $view
     */
    public function __construct($view)
    {
        $this->setView($view);
        parent::__construct();
    }

    /**
     * @return string
     */
    public function getView()
    {
        return $this->view;
    }

    /**
     * @param string $view
     *
     * @return $this
     */
    public function setView($view)
    {
        $this->view = $view;

        $this->setDisplay(function ($model) {
            return view($this->getView(), ['model' => $model]);
        });

        return $this;
    }

    /*
    public function save()
    {
        $callback = $this->getCallback();
        if (is_callable($callback)) {
            call_user_func($callback, $this->getModel());
        }
    }
    */
}