public static function installBlockType($btHandle, $pkg = false)
    {
        $app = Application::getFacadeApplication();
        $em = $app->make(EntityManagerInterface::class);
        $pkgHandle = (string) (is_object($pkg) ? $pkg->getPackageHandle() : $pkg);
        $class = static::getBlockTypeMappedClass($btHandle, $pkgHandle);
        $bta = $app->build($class);

        $locator = $app->make(FileLocator::class);
        if ($pkgHandle !== '') {
            $locator->addLocation(new FileLocator\PackageLocation($pkgHandle));
        }
        $path = dirname($locator->getRecord(DIRNAME_BLOCKS . '/' . $btHandle . '/' . FILENAME_BLOCK_DB)->getFile());

        //Attempt to run the subclass methods (install schema from db.xml, etc.)
        $bta->install($path);

        // Prevent the database records being stored in wrong language
        $loc = $app->make(Localization::class);
        $loc->pushActiveContext(Localization::CONTEXT_SYSTEM);
        try {
            //Install the block
            $bt = new BlockTypeEntity();
            $bt->loadFromController($bta);
            if (is_object($pkg)) {
                $bt->setPackageID($pkg->getPackageID());
            }
            $bt->setBlockTypeHandle($btHandle);
        } finally {
            $loc->popActiveContext();
        }

        $em->persist($bt);
        $em->flush();

        if ($bta->getBlockTypeDefaultSet()) {
            $set = Set::getByHandle($bta->getBlockTypeDefaultSet());
            if ($set !== null) {
                $set->addBlockType($bt);
            }
        }

        return $bt;
    }