1. Setup
We've added two layout dropdown fields to the page_list block's edit screen by overriding:
- db.xml
- page_list_form.php
- Adding the fields to the view
2. In db.xml we've added:
<field name="gridSize" type="C" size="255">
</field>
<field name="gridPaddingStyle" type="C" size="255">
</field>
3. In page_list_form.php
We've added the slect fields to the block edit screen like this:
<div class="ccm-block-field-group">
<h2><? echo t('Grid layout')?></h2>
<p><? echo t('Grid size')?></p>
<?php
$gridSize = array(
'1up' => 'grid-list-item-single grid-unit-1',
'2up' => 'grid-unit-2',
'3up' => 'grid-unit-3',
'4up' => 'grid-unit-4',
'5up' => 'grid-unit-5',
'6up' => 'grid-unit-6'
);
if (is_array($gridSize)) :
?>
<select name="gridSize" id="selectGridSize">
<? foreach ($gridSize as $gridItem => $value) : ?>
<option value="<?= $value ?>" <?php if ($gridSize == $value) { ?> selected <?php } ?>>
<?= $gridItem ?>
</option>
<? endforeach; ?>
</select>
<? endif; ?>
<p><? echo t('Grid padding style')?></p>
<?php
$gridPaddingStyle = array(
'Padding' => '',
'No padding' => 'grid-no-padding',
'Hairline' => 'grid-hairline'
);
if (is_array($gridPaddingStyle)) :
?>
<select name="gridPaddingStyle" id="selectPaddingSize">
<? foreach ($gridPaddingStyle as $gridPaddingStyleItem => $value) : ?>
<option value="<?= $value ?>" <?php if ($gridPaddingStyle == $value) { ?> selected <?php } ?>>
<?= $gridPaddingStyleItem ?>
</option>
<? endforeach; ?>
</select>
<? endif; ?>
</div>
4. In the view.php we've added:
$gridSize = $controller->gridSize;
$gridPadding = $controller->gridPaddingStyle;
Which obviously pulls the data out of the database for use when we output the markup.
Everything works great except when we come to re-edit the block - essentially the values previously set for our custom fields don't get read and the dropdowns revert back to the first items in the select lists.
5. Question
How do we get the page_list edit screen to read the values previously set in the database?
Any pointers in the right direction would be much appreciated (sorry, can't work out how to get syntax highlighting working - wish the markdown was the same ad Github issues).
Cheers
Ben