How to move a block to a certain position within an area of another page
Permalink
Hi all!
I wonder if it is possible to move a block to a certain position within another page's area.
The block move() method just allows to append
a block.
Modifying the display order after moving a block just does not work at all.
I do not see any provisions within the API to accomplish this (and when it comes to programmatically altering the order, block's setDisplayOrder method is a rather crude way, as it only allows moving up/down one step).
Is there any best practice way of setting/changing the display order.
Thanks for your help!
I wonder if it is possible to move a block to a certain position within another page's area.
The block move() method just allows to append
a block.
Modifying the display order after moving a block just does not work at all.
I do not see any provisions within the API to accomplish this (and when it comes to programmatically altering the order, block's setDisplayOrder method is a rather crude way, as it only allows moving up/down one step).
Is there any best practice way of setting/changing the display order.
Thanks for your help!
u would like to know this as well
I encountered a similar problem when trying to modify the appending behaviour (e.g. when a user/editor inserts a new block into an area). Quite often, a new block has to be inserted at the top, not the end as it is the most recent.
It can get quite cumbersome to be forced to manually move the block to the top.
I got the impression that there is too much user-level behaviour hardcoded as there seems to be no API method that will allow to easily modify the display position without core hacking. The only method in this regard is Block::setBlockDisplayOrder(), which only allows incrementing/decrementing the display order (provided that it is called in the right context).
Am I missing something important here?
It can get quite cumbersome to be forced to manually move the block to the top.
I got the impression that there is too much user-level behaviour hardcoded as there seems to be no API method that will allow to easily modify the display position without core hacking. The only method in this regard is Block::setBlockDisplayOrder(), which only allows incrementing/decrementing the display order (provided that it is called in the right context).
Am I missing something important here?
I finally found an answer, that works satisfactory.
I overwrite the Block class by putting
models/block.php in the top-level
models directory, adding following
method:
This allows prepending the block at the top position.
Additionally the jquery ajax functionality needs to be tweaked, as the appending behaviour is hard coded and the page needs to be refreshed to show the block displayed at the top position.
I overwrite the Block class by putting
models/block.php in the top-level
models directory, adding following
method:
function moveTop($nc, $area) { $db = Loader::db(); $cID = $this->getBlockCollectionID(); $cvID = $nc->getVersionID(); $newBlockDisplayOrder = $nc->getCollectionAreaDisplayOrder($area->getAreaHandle()); $v = array($nc->getCollectionID(), $area->getAreaHandle(), $cvID); $db->Execute('update CollectionVersionBlocks set cbDisplayOrder = cbDisplayOrder +1 where cID = ? and arHandle = ? and cvID = ?', $v); $newBlockDisplayOrder = 0; $v = array($nc->getCollectionID(), $nc->getVersionID(), $area->getAreaHandle(), $newBlockDisplayOrder, $cID, $this->arHandle); $db->Execute('update CollectionVersionBlocks set cID = ?, cvID = ?, arHandle = ?, cbDisplayOrder = ? where cID = ? and arHandle = ? and isOriginal = 1', $v); }
This allows prepending the block at the top position.
Additionally the jquery ajax functionality needs to be tweaked, as the appending behaviour is hard coded and the page needs to be refreshed to show the block displayed at the top position.