Call to a member function setBlockObject() on a non-object

Permalink
Hi,
I'm getting below error on specific pages, I am not able to edit page and when I open page, it throws below error.

Page Link :http://www.exrx.net/concrete/People/JTGResume...

Error :
Whoops \ Exception \ ErrorException (E_ERROR)
HELP
Call to a member function setBlockObject() on a non-object
/home/exrx/public_html/concrete/updates/concrete5.7.5.6/concrete/blocks/core_area_layout/controller.php
    public function getAreaLayoutObject()
    {
        if ($this->arLayoutID) {
            $arLayout = AreaLayout::getByID($this->arLayoutID);
            $b = $this->getBlockObject();
            if (is_object($b)) {
                $arLayout->setBlockObject($b);
            }

1 Attachment

srjahir32
View Replies: View Best Answer
A3020 replied on at Permalink Best Answer Reply
A3020
You might be able to go back to a previous page version via the Dashboard / Sitemap. Make sure you approve a former version and then load that page in cognito. (A logged in administrator will always see the most recent unapproved version)

If that doesn't work you I'd temporarily modify the core files, undo the layout in some way, save the page and then revert the core code changes.

I've submitted a PR to fix this in the core, btw:https://github.com/concrete5/concrete5/pull/3942....

Good luck ;)
srjahir32 replied on at Permalink Reply
srjahir32
Thanks.
nthorpe replied on at Permalink Reply
Hi,
Did you get anywhere with this? I'm just having the same problem, right after having moved a layout within a page.
Thanks
jfhencken replied on at Permalink Reply
jfhencken
I also had the same problem while working on a fresh install of 5.7.5.9. One minute all is going well and the error comes up just under my header image: "An unexpected error occurred. Call to a member function setBlockObject() on a non-object".
Another very similar page does not have the problem.
The page with the error has a right sidebar layout and a nav stack in the right sidebar. The left side contains a content block.
I had started reviewing each page of the 6 pages I recently added and when I returned to this one particular page the error was showing under my banner image.
Any new insights on why this happens?
Can I just delete the page and recreate it? Or do I now have a corruption that will pop up later?
It saddens me to say that If this keeps up I will not be using concrete5.7+ for a while.
A3020 replied on at Permalink Reply
A3020
I don't mind if you use c5 or not. If you want to use WordPress, no problemo.

Regarding your issue: it seems the fix is only merged into the v8 branch, so you'll have to create a controller override in the meanwhile. Add a file called 'controller.php' in /application/blocks/core_area_layout with these contents:

<?php
namespace Application\Block\CoreAreaLayout;
class Controller extends \Concrete\Block\CoreAreaLayout\Controller {
    public function getAreaLayoutObject()
    {
        if ($this->arLayoutID) {
            $arLayout = AreaLayout::getByID($this->arLayoutID);
            $b = $this->getBlockObject();
            if (is_object($arLayout) && is_object($b)) {
                $arLayout->setBlockObject($b);
            }
            return $arLayout;
        }
    }
}


Please let me know if that works for you.
nthorpe replied on at Permalink Reply
Great - that seems to be working, thanks! Though you need a use statement in there. Full code:

<?php
namespace Application\Block\CoreAreaLayout;
use Concrete\Core\Area\Layout\Layout as AreaLayout;
class Controller extends \Concrete\Block\CoreAreaLayout\Controller {
    public function getAreaLayoutObject()
    {
        if ($this->arLayoutID) {
            $arLayout = AreaLayout::getByID($this->arLayoutID);
            $b = $this->getBlockObject();
            if (is_object($arLayout) && is_object($b)) {
                $arLayout->setBlockObject($b);
            }
            return $arLayout;
        }
    }
A3020 replied on at Permalink Reply
A3020
Ah yeah, I didn't test it. Glad to hear you got it working.
bvcreative replied on at Permalink Reply
bvcreative
Hi All

I just experienced this issue as well unfortunately. I fixed it by adding the controller as described here as well. However I also had to override the view for core_area_layout by adding a new file in /application/blocks/core_area_layout/view.php with the following content otherwise I then got a new error saying could not call getLayoutContainerHtmlObject on a non object:

<?php
defined('C5_EXECUTE') or die("Access Denied.");
$a = $b->getBlockAreaObject();
if(isset($formatter)) {
   $container = $formatter->getLayoutContainerHtmlObject();
   foreach($columns as $column) {
      $html = $column->getColumnHtmlObject();
      $container->appendChild($html);
   }
   print $container;
}


Having a fix to stop the errors is one thing, but we need to ensure that this doesn't happen again. Does anyone know how or why this issue occurs and is there any investigation happening into the route of the problem?

Many thanks
David
felixb101 replied on at Permalink Reply
felixb101
5.7.5.13 fixed it for me
JohntheFish replied on at Permalink Reply
JohntheFish
I have seen this error today when saving block edits on v8., v8.0 and v8.0.3. It happens randomly and a subsequent save is usually successful. So perhaps the fix is not 100% reliable.
tabercreative replied on at Permalink Reply
tabercreative
Just happened to me in 8.1.

After hours of trying to get it fixed, I ended up having to delete the whole page and re-created it from scratch. The error somehow wiped-out the blocks contained within the layout areas.
ob7dev replied on at Permalink Reply
ob7dev
I'm also getting this error in 8.1 ... I'm trying to figure out if its my block code or if something else is going on.
duurainen replied on at Permalink Reply
Did you figure this out? I am having the same issue. All a sudden out of nowhere it started happening.
duurainen replied on at Permalink Reply
Did you figure this out? I am having the same issue. All a sudden out of nowhere it started happening.
noogen replied on at Permalink Reply
@duurainen did you try bvcreative fix?
tabercreative replied on at Permalink Reply
tabercreative
I tried and it had no effect. I was not able to fix the problem and was forced to recreate the page.