Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • None
  • PHP

Classes

  • Container
  • ControlGroup
  • Form
  • Rule
  • Rules

Interfaces

  • IControl
  • IFormRenderer
  • ISubmitterControl
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: namespace Nette\Forms;
 13: 
 14: use Nette;
 15: 
 16: 
 17: /**
 18:  * A user group of form controls.
 19:  *
 20:  * @author     David Grudl
 21:  *
 22:  * @property-read array $controls
 23:  * @property-read array $options
 24:  */
 25: class ControlGroup extends Nette\Object
 26: {
 27:     /** @var \SplObjectStorage */
 28:     protected $controls;
 29: 
 30:     /** @var array user options */
 31:     private $options = array();
 32: 
 33: 
 34:     public function __construct()
 35:     {
 36:         $this->controls = new \SplObjectStorage;
 37:     }
 38: 
 39: 
 40:     /**
 41:      * @return self
 42:      */
 43:     public function add()
 44:     {
 45:         foreach (func_get_args() as $num => $item) {
 46:             if ($item instanceof IControl) {
 47:                 $this->controls->attach($item);
 48: 
 49:             } elseif ($item instanceof \Traversable || is_array($item)) {
 50:                 foreach ($item as $control) {
 51:                     $this->controls->attach($control);
 52:                 }
 53: 
 54:             } else {
 55:                 throw new Nette\InvalidArgumentException("Only IFormControl items are allowed, the #$num parameter is invalid.");
 56:             }
 57:         }
 58:         return $this;
 59:     }
 60: 
 61: 
 62:     /**
 63:      * @return array IFormControl
 64:      */
 65:     public function getControls()
 66:     {
 67:         return iterator_to_array($this->controls);
 68:     }
 69: 
 70: 
 71:     /**
 72:      * Sets user-specific option.
 73:      * Options recognized by DefaultFormRenderer
 74:      * - 'label' - textual or Html object label
 75:      * - 'visual' - indicates visual group
 76:      * - 'container' - container as Html object
 77:      * - 'description' - textual or Html object description
 78:      * - 'embedNext' - describes how render next group
 79:      *
 80:      * @param  string key
 81:      * @param  mixed  value
 82:      * @return self
 83:      */
 84:     public function setOption($key, $value)
 85:     {
 86:         if ($value === NULL) {
 87:             unset($this->options[$key]);
 88: 
 89:         } else {
 90:             $this->options[$key] = $value;
 91:         }
 92:         return $this;
 93:     }
 94: 
 95: 
 96:     /**
 97:      * Returns user-specific option.
 98:      * @param  string key
 99:      * @param  mixed  default value
100:      * @return mixed
101:      */
102:     final public function getOption($key, $default = NULL)
103:     {
104:         return isset($this->options[$key]) ? $this->options[$key] : $default;
105:     }
106: 
107: 
108:     /**
109:      * Returns user-specific options.
110:      * @return array
111:      */
112:     final public function getOptions()
113:     {
114:         return $this->options;
115:     }
116: 
117: }
118: 
Nette Framework 2.0.12 API API documentation generated by ApiGen 2.8.0