Skip to content

Accessing $this->viewBuilder()->getPlugin() inside \Cake\View\Cell::initialize() #18035

@mehov

Description

@mehov

Description

What I have:

Inside plugins/MyPlugin/src/View/Cell/SelectorCell.php:

<?php

namespace MyPlugin\View\Cell;

class SelectorCell extends \Cake\View\Cell
{

    public function initialize(): void
    {
        parent::initialize();
        debug($this->viewBuilder()->getPlugin());
    }

    public function test()
    {
        debug($this->viewBuilder()->getPlugin());
    }

}

Elsewhere in my application:

<?= $this->cell('MyPlugin.Selector::test') ?>

What I expect to happen

Both debug() calls show MyPlugin

What actually happens

The one in initialize() says null; every $this->viewBuilder() property in initialize() is actually null.

object(Cake\View\ViewBuilder) id:0 {
    protected _templatePath => null
    protected _template => null
    protected _plugin => null
    protected _theme => null
    protected _layout => null
    protected _autoLayout => true
    protected _layoutPath => null
    protected _name => null
    protected _className => null
    protected _options => [ ]
    protected _helpers => [ ]
    protected _vars => [ ]
}

The call in test() says MyPlugin as expected.

CakePHP Version

5.1.2

PHP Version

8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions