how to disconnect a block from it's master collection on page defaults programmatically
Permalink
Hi all...
I'm building a new single page composer with it's own controller to edit some of my specialized page for some specific users. Those pages have some default blocks already set up on it via the page type defaults.
All I want is to edit the content of Content Block via my new single page edit form. That Content Block is already predefined on the page type defaults. It's placed as the first block on the Main Area.
For that, I made a function on my controller like this
I thought that simple function should be enough to make it work just like what I want. But apparently it's not. the $b->update($data) function seems to be updating the master block on its page type defaults, not only this particular block on this particular page I'm editing. So it update all of my pages which contain that defaults Content Block.
So how can I really disconnect that block from it's master default. So that I could edit it just for this particular page. The built in concrete5 block editing functionality is able to disconnect the block. But I can't find any clue or documentation anywhere about how to disconnect that block. I also have no clue what concrete5 core files to dig to find out how to disconnect it.
I'm building a new single page composer with it's own controller to edit some of my specialized page for some specific users. Those pages have some default blocks already set up on it via the page type defaults.
All I want is to edit the content of Content Block via my new single page edit form. That Content Block is already predefined on the page type defaults. It's placed as the first block on the Main Area.
For that, I made a function on my controller like this
/* $p = the page object that I want to edit */ private function saveData($p){ $blocks = $p->getBlocks('Main'); $data = array('content' => $this->post('contentBody')); $bt = BlockType::getByHandle('content'); foreach( $blocks as $b){ $b->update($data); } }
I thought that simple function should be enough to make it work just like what I want. But apparently it's not. the $b->update($data) function seems to be updating the master block on its page type defaults, not only this particular block on this particular page I'm editing. So it update all of my pages which contain that defaults Content Block.
So how can I really disconnect that block from it's master default. So that I could edit it just for this particular page. The built in concrete5 block editing functionality is able to disconnect the block. But I can't find any clue or documentation anywhere about how to disconnect that block. I also have no clue what concrete5 core files to dig to find out how to disconnect it.
http://www.concrete5.org/community/forums/customizing_c5/programati...
which solved my problem.
Basically you duplicate the block, delete the original and then update the duplicate.