concrete/src/Page/Collection/Collection.php
public function addBlock($bt, $a, $data)
    {
        $db = Loader::db();

        // first we add the block to the system
        $nb = $bt->add($data, $this, $a);

        // now that we have a block, we add it to the collectionversions table

        $arHandle = (is_object($a)) ? $a->getAreaHandle() : $a;
        $cID = $this->getCollectionID();
        $vObj = $this->getVersionObject();

        if ($bt->includeAll()) {
            // normally, display order is dependant on a per area, per version basis. However, since this block
            // is not aliased across versions, then we want to get display order simply based on area, NOT based
            // on area + version
            $newBlockDisplayOrder = $this->getCollectionAreaDisplayOrder(
                                         $arHandle,
                                         true
            ); // second argument is "ignoreVersions"
        } else {
            $newBlockDisplayOrder = $this->getCollectionAreaDisplayOrder($arHandle);
        }

        $cbRelationID = $db->GetOne('select max(cbRelationID) as cbRelationID from CollectionVersionBlocks');
        if (!$cbRelationID) {
            $cbRelationID = 1;
        } else {
            ++$cbRelationID;
        }

        $v = [
            $cID,
            $vObj->getVersionID(),
            $nb->getBlockID(),
            $arHandle,
            $cbRelationID,
            $newBlockDisplayOrder,
            1,
            (int) ($bt->includeAll()),
        ];
        $q = 'insert into CollectionVersionBlocks (cID, cvID, bID, arHandle, cbRelationID, cbDisplayOrder, isOriginal, cbIncludeAll) values (?, ?, ?, ?, ?, ?, ?, ?)';

        $res = $db->Execute($q, $v);

        $controller = $nb->getController();
        $features = $controller->getBlockTypeFeatureObjects();
        if (count($features) > 0) {
            foreach ($features as $fe) {
                $fd = $fe->getFeatureDetailObject($controller);
                $fa = CollectionVersionFeatureAssignment::add($fe, $fd, $this);
                $db->Execute(
                   'insert into BlockFeatureAssignments (cID, cvID, bID, faID) values (?, ?, ?, ?)',
                   [
                       $this->getCollectionID(),
                       $this->getVersionID(),
                       $nb->getBlockID(),
                       $fa->getFeatureAssignmentID(),
                   ]
                );
            }
        }

        return Block::getByID($nb->getBlockID(), $this, $a);
    }
public function addBlock($bt, $a, $data)
    {
        $db = Loader::db();

        // first we add the block to the system
        $nb = $bt->add($data, $this, $a);

        // now that we have a block, we add it to the collectionversions table

        $arHandle = (is_object($a)) ? $a->getAreaHandle() : $a;
        $cID = $this->getCollectionID();
        $vObj = $this->getVersionObject();

        if ($bt->includeAll()) {
            // normally, display order is dependant on a per area, per version basis. However, since this block
            // is not aliased across versions, then we want to get display order simply based on area, NOT based
            // on area + version
            $newBlockDisplayOrder = $this->getCollectionAreaDisplayOrder(
                                         $arHandle,
                                         true
            ); // second argument is "ignoreVersions"
        } else {
            $newBlockDisplayOrder = $this->getCollectionAreaDisplayOrder($arHandle);
        }

        $cbRelationID = $db->GetOne('select max(cbRelationID) as cbRelationID from CollectionVersionBlocks');
        if (!$cbRelationID) {
            $cbRelationID = 1;
        } else {
            ++$cbRelationID;
        }

        $v = [
            $cID,
            $vObj->getVersionID(),
            $nb->getBlockID(),
            $arHandle,
            $cbRelationID,
            $newBlockDisplayOrder,
            1,
            (int) ($bt->includeAll()),
        ];
        $q = 'insert into CollectionVersionBlocks (cID, cvID, bID, arHandle, cbRelationID, cbDisplayOrder, isOriginal, cbIncludeAll) values (?, ?, ?, ?, ?, ?, ?, ?)';

        $res = $db->Execute($q, $v);

        $controller = $nb->getController();
        $features = $controller->getBlockTypeFeatureObjects();
        if (count($features) > 0) {
            foreach ($features as $fe) {
                $fd = $fe->getFeatureDetailObject($controller);
                $fa = CollectionVersionFeatureAssignment::add($fe, $fd, $this);
                $db->Execute(
                   'insert into BlockFeatureAssignments (cID, cvID, bID, faID) values (?, ?, ?, ?)',
                   [
                       $this->getCollectionID(),
                       $this->getVersionID(),
                       $nb->getBlockID(),
                       $fa->getFeatureAssignmentID(),
                   ]
                );
            }
        }

        return Block::getByID($nb->getBlockID(), $this, $a);
    }
public function addBlock ( $ bt , $ a , $ data ) { $ db = Loader :: db ( ) ; // first we add the block to the system $ nb = $ bt -> add ( $ data , $ this , $ a ) ; // now that we have a block, we add it to the collectionversions table $ arHandle = ( is_object ( $ a ) ) ? $ a -> getAreaHandle ( ) : $ a ; $ cID = $ this -> getCollectionID ( ) ; $ vObj = $ this -> getVersionObject ( ) ; if ( $ bt -> includeAll ( ) ) { // normally, display order is dependant on a per area, per version basis. However, since this block // is not aliased across versions, then we want to get display order simply based on area, NOT based // on area + version $ newBlockDisplayOrder = $ this -> getCollectionAreaDisplayOrder ( $ arHandle , true ) ; // second argument is "ignoreVersions" } else { $ newBlockDisplayOrder = $ this -> getCollectionAreaDisplayOrder ( $ arHandle ) ; } $ cbRelationID = $ db -> GetOne ( 'select max(cbRelationID) as cbRelationID from CollectionVersionBlocks' ) ; if ( ! $ cbRelationID ) { $ cbRelationID = 1 ; } else { ++ $ cbRelationID ; } $ v = [ $ cID , $ vObj -> getVersionID ( ) , $ nb -> getBlockID ( ) , $ arHandle , $ cbRelationID , $ newBlockDisplayOrder , 1 , ( int ) ( $ bt -> includeAll ( ) ) , ] ; $ q = 'insert into CollectionVersionBlocks (cID, cvID, bID, arHandle, cbRelationID, cbDisplayOrder, isOriginal, cbIncludeAll) values (?, ?, ?, ?, ?, ?, ?, ?)' ; $ res = $ db -> Execute ( $ q , $ v ) ; $ controller = $ nb -> getController ( ) ; $ features = $ controller -> getBlockTypeFeatureObjects ( ) ; if ( count ( $ features ) > 0 ) { foreach ( $ features as $ fe ) { $ fd = $ fe -> getFeatureDetailObject ( $ controller ) ; $ fa = CollectionVersionFeatureAssignment :: add ( $ fe , $ fd , $ this ) ; $ db -> Execute ( 'insert into BlockFeatureAssignments (cID, cvID, bID, faID) values (?, ?, ?, ?)' , [ $ this -> getCollectionID ( ) , $ this -> getVersionID ( ) , $ nb -> getBlockID ( ) , $ fa -> getFeatureAssignmentID ( ) , ] ) ; } } return Block :: getByID ( $ nb -> getBlockID ( ) , $ this , $ a ) ; }
Add a new block to a specific area of the currently loaded collection version.

@param \Concrete\Core\Entity\Block\BlockType\BlockType $bt the type of block to be added
@param string|\Concrete\Core\Area\Area $a the area instance (or its handle) to which the block should be added to
@param array $data The data of the block. This data depends on the specific block type. Common values are: 'uID' to specify the ID of the author (if not specified: we'll use the current user), 'bName' to specify the block name.

@return \Concrete\Core\Block\Block
Add a new block to a specific area of the currently loaded collection version .