Using the attribute render method
Permalink
I am creating a block that will pull out a list of, let's say, pages and I want this block to list attributes that are of a select box type so you can filter based on that type. The reason I say that these are "mypages" are because they are infact a list of items that use a the built in attributes model, but are not in fact pages.
So I have written a method in the block's controller that returns all the select type attributes for the pages:
And bring them through to the add/edit block form like so:
Now, when the form is submitted I write to the database table for the block the bID etc and also to another database table to remember what key and values are required for the filter.
My question is, when I am editing the block I want the drop down for the select boxes to preselect the chosen filter, so I somehow have to create a value object($v) (?) and pass it to the render method:
How do I create this object from the information in btMypagesListFilter ?
Hope I am clear enough. Any help is appreciated.
So I have written a method in the block's controller that returns all the select type attributes for the pages:
public function getSelectAttributes() { Loader::model('attribute/categories/mypages'); $atkeys = array(); $attributeKeys = MypagesAttributeKey::getList(); if (is_array($attributeKeys)) { foreach($attributeKeys as $key) { if ($key->atHandle === 'select') { $atkeys[] = $key; } } return $atkeys; } return false; }
And bring them through to the add/edit block form like so:
$selectAttr = $this->controller->getSelectAttributes(); if (is_array($selectAttr)) { ?> <div class="ccm-block-field-group"> <h4><?php echo t('Filter Attributes')?></h4><br/> <?php foreach ($selectAttr as $attr) { if (is_object($attr)) { ?> <div class="clearfix"> <div class="input"> <?php $attr->render('form', $v, false); ?> </div>
Viewing 15 lines of 23 lines. View entire code block.
Now, when the form is submitted I write to the database table for the block the bID etc and also to another database table to remember what key and values are required for the filter.
btMypagesListFilter: bID akID avID 1 2 1 2 5 1 3 2 2 4 5 2
My question is, when I am editing the block I want the drop down for the select boxes to preselect the chosen filter, so I somehow have to create a value object($v) (?) and pass it to the render method:
$attr->render('form', $v, false);
How do I create this object from the information in btMypagesListFilter ?
Hope I am clear enough. Any help is appreciated.