Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationLatte
      • ApplicationTracy
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsLatte
      • Framework
      • HttpTracy
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • none
  • Tracy

Classes

  • Container
  • ControlGroup
  • Form
  • Helpers
  • Rule
  • Rules

Interfaces

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