Dynamic Singlepages with Area

Permalink
Hello,

i have a little Problem with a current project and need some advice.

i have a singlepage called „Details“. The controller of the singlepage loads product which id/slug is given by the first get param.

public function view($slug = null) {
        $seo = \Core::make("helper/seo");
        $productId = ProductManager::getInstance()->getProductIdBySlug($slug);
        if ($productId !== false) {
           $productEntity = ProductManager::getInstance()->getProductEntity($productId);
            $seo->addTitleSegment($productEntity->getName());
            $this->set("product", $productEntity);
        } else {
            $this->redirect("page_not_found");
        }
    }


The view renders the found product item.

Now i want to add an area into the view, so that i can add/edit blocks by concrete5.

I have tried to add this Code to the page view:
<?php
    $c = new Area('Main');
    $c->enableGridContainer();
    $c->display();
?>


And here is the problem.

If i click on „Edit page“ the get parameter which contains the url slug will be removed. So there is no more association which product should be edited.

Is it possible to pass custom get params when i click on „edit page“ ?

fabianbitter
 
hutman replied on at Permalink Reply
hutman
Are you trying to add different blocks to the page based on which slug was passed into the controller? If so I do not believe this is possible. Also, you shouldn't use $c for your area, because that is the global page variable.
fabianbitter replied on at Permalink Reply
fabianbitter
Hi hutman, thanks for your reply. Yes thats exactly what i am trying to do...
hutman replied on at Permalink Reply
hutman
I'm sorry to tell you I don't think that this is going to be possible. The areas are specific to the page, not the url.

Maybe another member of the community would have another idea of how to do this, but it's not going to be as easy as adding an area to a normal page.
fabianbitter replied on at Permalink Reply
fabianbitter
okay thank you well.
My first idea was (if it is possible to pass the slug param) to add the block container like this:

$c = new Area('Main_'. $slug);
hutman replied on at Permalink Reply
hutman
That would probably work, what you could do is to put the slug into the session when the page loads and then if $slug is blank (edit mode) pull it from the session instead.
fabianbitter replied on at Permalink Reply
fabianbitter
Thats a good idea. that should be work :)
fabianbitter replied on at Permalink Reply
fabianbitter
Using a Session was a good advice. Here is my POC. It is working fine. Only bug: If you exit the edit mode the action + params can't be restored...

Code for Controller:
<?php
/**
 * @author     Fabian Bitter
 * @copyright  (C) 2016 Bitter Webentwicklung
 */
use \Concrete\Core\Page\Controller\PageController;
use \Symfony\Component\HttpFoundation\Session\Session as SymfonySession;
use Request;
use Area;
class MyPageController extends PageController {
    /**
     * Returns an inique id based on the the action + params of the page.
     * 
     * @return String
     */


In the View you have to use the wrapper method $this->controller->getArea(...) instead of using new Area(...)

Example Code for the View:

<?php
        $a = $this->controller->getArea("My Test Area");
        $a->enableGridContainer();
        $a->display();
    ?>