# Custom block type set

**URL:** https://forums.concretecms.org/t/custom-block-type-set/4920
**Category:** Developing with Concrete
**Created:** [January 28, 2023, 4:17pm UTC](https://forums.concretecms.org/t/custom-block-type-set/4920 "2023-01-28T16:17:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Junglebob](https://forums.concretecms.org/user_avatar/forums.concretecms.org/junglebob/32/3794_2.png) [@Junglebob](https://forums.concretecms.org/u/Junglebob)
#### Post date: [January 28, 2023, 4:17pm UTC](https://forums.concretecms.org/t/custom-block-type-set/4920/1 "2023-01-28T16:17:45Z")

</div>

Hello, I want to create a custom bloc type set (like ‘Basic’, ‘Navigation’, ‘Form’, …) in order to group all my custom blocks together.  
I created a package for my theme and created the _page-theme.php_ with the code below, but it doesn’t work.  
Any ideas ?  
Is the _page-theme.php_ the best choice to execute this code ?  
Is there a method to remove a bloc type set programmatically ?

```auto

<?php  
namespace Concrete\Package\Sfgs;
defined('C5_EXECUTE') or die('Access Denied.');

use \Concrete\Core\Package\Package;
use BlockTypeSet;

class Controller extends Package
{
    ... code with the package handle, version, description, ...

	
    public function makeMyBlockSet($handle,$name){
		if (!BlockTypeSet::getByHandle($handle)) {
			BlockTypeSet::add($handle, $name, $pkg);
		}
	}

    public function install()
    {
        parent::install();
		
		$this->makeMyBlockSet('myblocset_handle','My Block Set');

                $this->installContentFile('install/theme.xml');
		$this->installContentFile('install/block_types.xml');		
    }

    public function upgrade()
    {
        parent::upgrade();
    	$this->installContentFile('install/theme.xml');
	$this->installContentFile('install/block_types.xml');
    }
}

```

 ![Snap8](https://forums.concretecms.org/uploads/default/original/2X/f/f4262e8004d6adf0ef8d3318c6cacf50423a8650.jpeg)

---

<div class="post-metadata">

### Author: ![Junglebob](https://forums.concretecms.org/user_avatar/forums.concretecms.org/junglebob/32/3794_2.png) [@Junglebob](https://forums.concretecms.org/u/Junglebob)
#### Post date: [January 28, 2023, 4:48pm UTC](https://forums.concretecms.org/t/custom-block-type-set/4920/2 "2023-01-28T16:48:46Z")

</div>

> [@Junglebob](#):
>
> ```auto
> public function makeMyBlockSet($handle,$name){
> if (!BlockTypeSet::getByHandle($handle)) {
> BlockTypeSet::add($handle, $name, $pkg);
> }
> 
> ```

I solved the problem by myself : _$pkg_ variable has to be removed from the function

```auto
public function makeMyBlockSet($handle,$name){
		if (!BlockTypeSet::getByHandle($handle)) {
			BlockTypeSet::add($handle, $name);
		}

```

The question how to remove the set programmatically is still open however 🤔

---

<div class="post-metadata">

### Author: ![enlil](https://forums.concretecms.org/user_avatar/forums.concretecms.org/enlil/32/3526_2.png) [@enlil](https://forums.concretecms.org/u/enlil)
#### Post date: [January 28, 2023, 6:59pm UTC](https://forums.concretecms.org/t/custom-block-type-set/4920/3 "2023-01-28T18:59:47Z")

</div>

@Junglebob This is how I do it in package controller, calling this method from uninstall()

```auto
private function cleanBlockTypeSets() {
		$blockTypeSet = BlockTypeSet::getByHandle('set_handle');
		$blockTypes = $blockTypeSet->getBlockTypes();
		$count = 0;
		foreach ($blockTypes as $blockType) {
			if ($blockType) {
				// Ignore block types in this package.
				if ($blockType->getBlockTypeHandle() == 'block_type_handle') { continue; }
				$count++;
			}
			if ($count == 1) { break; } // Another block type needs the BlockTypeSet, bail out of loop.
		}
		// Clear, then delete set if otherwise empty.
		if ($count == 0) { $blockTypeSet->clearBlockTypes(); $blockTypeSet->delete(); }
	}

```

---

<div class="post-metadata">

### Author: ![Junglebob](https://forums.concretecms.org/user_avatar/forums.concretecms.org/junglebob/32/3794_2.png) [@Junglebob](https://forums.concretecms.org/u/Junglebob)
#### Post date: [January 29, 2023, 9:53am UTC](https://forums.concretecms.org/t/custom-block-type-set/4920/4 "2023-01-29T09:53:56Z")

</div>

Many thanks, it helped me much !

---

<div class="post-metadata">

### Author: ![EvanCooper](https://forums.concretecms.org/user_avatar/forums.concretecms.org/evancooper/32/4597_2.png) [@EvanCooper](https://forums.concretecms.org/u/EvanCooper)
#### Post date: [February 2, 2023, 11:35pm UTC](https://forums.concretecms.org/t/custom-block-type-set/4920/5 "2023-02-02T23:35:54Z")

</div>

@Junglebob glad that resolved it - can you go ahead and mark @enlil’s response as the solution for the thread? Thanks!
