Generate $app->make in 5.7

Permalink
I am working on a package that is to be compatible with 5.7 and 5.8.

As core::make is now deprecated, I am trying to use $app->make. I am getting errors when testing in 5.7, but it works in 5.8.

However, I understand that I need to generate $app. How do I do this?

PineCreativeLabs
View Replies:
JohntheFish replied on at Permalink Reply
JohntheFish
Controller on_start() method.
if (!is_object($this->app)){
    $this->app = new ...... etc (as per deprecated code guide)
}


The code can also be run in a __construct() method, but if you do that be sure to get the parameters right and call the parent.
PineCreativeLabs replied on at Permalink Reply
PineCreativeLabs
This is what I currently have in my block controller:

public function on_start() {
        $this->set('app', $this->app);
    }


It works in 5.8, but not 5.7. In the error console, this is throwing the error:

return (empty($linkToC) || $linkToC->error) ? '' : $this->app->make('helper/navigation')->getLinkToCollection($linkToC);
JohntheFish replied on at Permalink Reply
JohntheFish
That is because $this->app is not defined in 5.7, hence the condition above which essentially says if $this->app doesn't exist yet, then create it, so it adapts between v8 and 5.7.
PineCreativeLabs replied on at Permalink Reply
PineCreativeLabs
I'm lost. Here's what I have for the on_start:

public function on_start() {
      if(!is_object($this->app)){
         $this->app = new $this->app->make('helper/navigation');
      }
    }

I've also tried:
public function on_start() {
      if(!is_object($this->app)){
         $this->app = new $this->set('app', $this->app);
      }
    }


To be honest, I have no idea what to do here.
Parasek replied on at Permalink Reply
Parasek
Try:

$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();

https://documentation.concrete5.org/developers/appendix/concrete5-ve...
mnakalay replied on at Permalink Reply
mnakalay
public function on_start() {
    if(!is_object($this->app)){
        $this->app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
        $this->set('app', $this->app);
    }
}
PineCreativeLabs replied on at Permalink Reply
PineCreativeLabs
This works fine in 5.7, but it fails in 5.8. In 5.8 when trying to edit a block, the form dialog never loads and doesn't open.

I think I will just stick with Core::make, since it works just fine on both versions.
mnakalay replied on at Permalink Reply
mnakalay
I use this in several packages compatible with both 5.7 and 8 (there is no 5.8) and it works just fine, you might have something else at play here? Check your Logs for an exact error message.

As far as the PRB is concerned, I don't think getting rid of Core is open to discussion. We've been making everybody get rid of it.

I can be wrong though, better check in the PRB.
BinaryBlocks replied on at Permalink Reply
BinaryBlocks
I had to change the code in order to get the 'app' variable sent to the form.

This is the change I made:

public function on_start() {
      if(!is_object($this->app)){
        $this->app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
      }
      $this->set('app', $this->app);
    }