Version: current

     1 <?php
     2 /**
     3  * This is a form decorator (a class that wraps around a form) providing us with some functions
     4  * to display it in a Tabular style.
     5  * @package forms
     6  * @subpackage transformations
     7  */
     8 class TabularStyle extends ViewableData {
     9     protected $form;
    10
    11     /**
    12      * Represent the given form in a tabular style
    13      * @param form The form to decorate.
    14      */
    15     function __construct($form) {
    16         $this->form = $form;
    17         $this->failover = $form;
    18         parent::__construct();
    19     }
    20
    21     /**
    22      * Return a representation of this form as a table row
    23      */
    24     function AsTableRow() {
    25         return "<tr class=\"addrow\">{$this->CellFields()}<td class=\"actions\">{$this->CellActions()}</td></tr>";
    26     }
    27
    28     function CellFields() {
    29         $result = "";
    30         $hiddenFields = '';
    31         foreach($this->form->Fields() as $field) {
    32             if(!$field->is_a('HiddenField')) {
    33                 $result .= "<td>" . $field->Field() . "</td>";
    34             } else {
    35                 $hiddenFields .= $field->Field();
    36             }
    37         }
    38
    39         // Add hidden fields in the last cell
    40         $result = substr($result,0,-5) . $hiddenFields . substr($result,-5);
    41
    42         return $result;
    43     }
    44
    45     function CellActions() {
    46         $actions = "";
    47         foreach($this->form->Actions() as $action) {
    48             $actions .= $action->Field();
    49         }
    50         return $actions;
    51     }
    52
    53
    54
    55     /**
    56      * This is the 'wrapper' aspect of the code
    57      */
    58     function __call($func, $args) {
    59         return call_user_func_array(array(&$this->form, $func), $args);
    60     }
    61     function __get($field) {
    62         return $this->form->$field;
    63     }
    64     function __set($field, $val) {
    65         $this->form->$field = $val;
    66     }
    67 }
    68 ?>

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -