public function deleteBlockType(SuperTable_BlockTypeModel $blockType) { $transaction = craft()->db->getCurrentTransaction() === null ? craft()->db->beginTransaction() : null; try { // First delete the blocks of this type $blockIds = craft()->db->createCommand()->select('id')->from('supertableblocks')->where(array('typeId' => $blockType->id))->queryColumn(); $this->deleteBlockById($blockIds); // Now delete the block type fields $originalFieldColumnPrefix = craft()->content->fieldColumnPrefix; craft()->content->fieldColumnPrefix = 'field_'; foreach ($blockType->getFields() as $field) { craft()->fields->deleteField($field); } craft()->content->fieldColumnPrefix = $originalFieldColumnPrefix; // Delete the field layout craft()->fields->deleteLayoutById($blockType->fieldLayoutId); // Finally delete the actual block type $affectedRows = craft()->db->createCommand()->delete('supertableblocktypes', array('id' => $blockType->id)); if ($transaction !== null) { $transaction->commit(); } return (bool) $affectedRows; } catch (\Exception $e) { if ($transaction !== null) { $transaction->rollback(); } throw $e; } }