Adding Blocks to Sidebar
Permalink 2 users found helpful
Hi, When we are installing a block from a package how do we put it into one of the categories in the sidebar, like Navagation, and how do we add a category in the side bar?
thanks
thanks
Awesome, thanks Andrew, found everyting I needed now
Pretty cool that you can add these to sets as Andrew has pointed to above. Did you figure out how to add your own set from a package? Just having a look over the code now to see how to do it...
This worked for me:
use BlockTypeSet; BlockTypeSet::add('handle', 'Name', $pkg);
Yep that did it - nice one.
Nice!
When I use this in the block controller, I get an error.
An example:
This results in:
An unexpected error occurred.
When I look in the database (concrete5 »Table: BlockTypeSets) the btsName and btsHandle have been created. I can go back into the controller, comment out "use BlockTypeSet; BlockTypeSet::add('gallery', 'Gallery', $pkg);" and the error goes away.
Another thing is that the newly created btsID for the new entry isn't always the next available integer. The last entry might have a btsID of 7 and the new one might be 11. When the next available integer isn't used (e.g. 8), when you click add, the sidebar of blocks is blank.
This is not a big deal at all and an end user will never fiddle with this anyway. I was just curious if I was doing something wrong.
use BlockTypeSet; BlockTypeSet::add('handle', 'Name', $pkg);
An example:
use BlockTypeSet; BlockTypeSet::add('gallery', 'Gallery', $pkg);
This results in:
An unexpected error occurred.
An exception occurred while executing 'insert into BlockTypeSets (btsHandle, btsName, pkgID) values (?, ?, ?)' with params ["gallery", "Gallery", 0]: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'gallery' for key 'btsHandle'
When I look in the database (concrete5 »Table: BlockTypeSets) the btsName and btsHandle have been created. I can go back into the controller, comment out "use BlockTypeSet; BlockTypeSet::add('gallery', 'Gallery', $pkg);" and the error goes away.
Another thing is that the newly created btsID for the new entry isn't always the next available integer. The last entry might have a btsID of 7 and the new one might be 11. When the next available integer isn't used (e.g. 8), when you click add, the sidebar of blocks is blank.
This is not a big deal at all and an end user will never fiddle with this anyway. I was just curious if I was doing something wrong.
Looks like it is saying you have a duplicate i.e. it may already exist for some reason.
Maybe consider wrapping the code in a test like so:
Hopefully will avoid any duplication and error.
Maybe consider wrapping the code in a test like so:
if(!BlockTypeSet::getByHandle('gallery')) { BlockTypeSet::add('gallery', 'Gallery', $pkg); }
Hopefully will avoid any duplication and error.
That worked - thank you, formigo
One thing I found was if you are changing the BlockTypeSet of a block that has already been installed. You have to remove the block, then reinstall it.
One thing I found was if you are changing the BlockTypeSet of a block that has already been installed. You have to remove the block, then reinstall it.
protected $btDefaultSet = 'social';
Where 'social' is the name of the BlockTypeSet handle (check the database) that will place the block in the appropriate set. We don't have a UI yet for managing the order or grouping of these block types, and we don't yet have documentation on creating your own sets (but this is possible, if you look at the code.)