Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change default flash element? #129

Closed
thinkingmedia opened this issue Jun 2, 2016 · 2 comments
Closed

How to change default flash element? #129

thinkingmedia opened this issue Jun 2, 2016 · 2 comments

Comments

@thinkingmedia
Copy link
Contributor

thinkingmedia commented Jun 2, 2016

CrudView.php is used to render the views, and it's loading BootstrapUI.Flash with default settings.

My app has a custom render element for Flash messages, but it's not being used because of the defaults.

I also noticed BootstrapUI.Flash is loaded twice by the view.

    protected function _setupHelpers()
    {
        $this->loadHelper('Html', ['className' => 'BootstrapUI.Html']);
        $this->loadHelper('Form', [
            'className' => 'BootstrapUI.Form',
            'widgets' => [
               'datetime' => ['CrudView\View\Widget\DateTimeWidget', 'select']
            ]
        ]);
        $this->loadHelper('Flash', ['className' => 'BootstrapUI.Flash']);
        $this->loadHelper('Paginator', ['className' => 'BootstrapUI.Paginator']);

        $this->loadHelper('CrudView.CrudView');
        $this->loadHelper('BootstrapUI.Flash');

        if (Configure::read('CrudView.useAssetCompress')) {
            $this->loadHelper('AssetCompress.AssetCompress');
        }
    }

Any ideas how I can make CrudView use my Template\Element\Flash elements?

@thinkingmedia
Copy link
Contributor Author

So I think I solved my issue. If my approach is the correct way, then please close this issue.

I created my own view called AdminView.php and derived it from CrudView.

I then override the _setupHelpers() method, and just skipped BootstrapUI.Flash as I don't need it.

A quick test appears to have fixed my flash messages.

Here's my view if anyone wants a copy.

<?php
namespace App\View;

use CrudView\View\CrudView;

/**
 * @property \BootstrapUI\View\Helper\FormHelper $Form
 * @property \BootstrapUI\View\Helper\HtmlHelper $Html
 * @property \BootstrapUI\View\Helper\PaginatorHelper $Paginator
 * @property \CrudView\View\Helper\CrudViewHelper $CrudView
 */
class AdminView extends CrudView
{
    /**
     * @var string
     */
    public $layout = 'default';

    /**
     * Setup helpers
     */
    protected function _setupHelpers()
    {
        $this->loadHelper('Html', ['className' => 'BootstrapUI.Html']);
        $this->loadHelper('Form', [
            'className' => 'BootstrapUI.Form',
            'widgets' => [
                'datetime' => ['CrudView\View\Widget\DateTimeWidget', 'select']
            ]
        ]);
        $this->loadHelper('Paginator', ['className' => 'BootstrapUI.Paginator']);
        $this->loadHelper('CrudView.CrudView');
   }
}

@thinkingmedia
Copy link
Contributor Author

This works fine for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant