Get Package from within block controller
PermalinkHow can I get the package from within a block controller?
When adding a new block onto an area (so, BlockController::add()) r=there is now BlockObject yet.
How can I get the Package? (other than hardcode the packagehandle).
SnefIT
// Get package $pkg = $this->getPackage(); // Get packageid $pkgID = $this->getPackageID(); // Get package handle $pkgHandle = $this->getPackageHandle();
When there is a block, I can get the block and from there I can get the package like:
// Get block $b = $this->getBlockObject(); // Get packageID $pkgID = $b->getPackageID(); // Get package handle $pkgHandle = $b->getPackageHandle();
Unfortunately when adding a block for the first time, there is no block in code yet, so I can't get the block object.
Normally I also use the simple solution like you do, but I thought it was "better" to get the package/packagehandle "automatic" (less hardcoded spots). Should be available somewhere, because the block (blocktype) was installed within a package so you should have that information available somewhere.
It's no showstopper, just trying to cleanup some code ;-)
PS. I need the packagehandle to get to the config of that package.
You can always do $pkg = Package::getByHandle('my_package');
but you're saying you want to be able to figure out the package another way?
How so? By figuring out what package the block is part of?