/** * Create a new selection group. * * @param string $name The field name of the selection group. * @param array $items The list of {@link SelectionGroup_Item} * @param mixed $value */ public function __construct($name, $items, $value = null) { if ($value !== null) { $this->setValue($value); } $selectionItems = array(); foreach ($items as $key => $item) { if ($item instanceof SelectionGroup_Item) { $selectionItems[] = $item; } else { // Convert legacy format if (strpos($key, '//') !== false) { list($key, $title) = explode('//', $key, 2); } else { $title = null; } $selectionItems[] = new SelectionGroup_Item($key, $item, $title); } } parent::__construct($selectionItems); $this->setName($name); }
/** * @uses FormField::name_to_label() * * @param string $name Identifier of the tab, without characters like dots or spaces * @param string|FormField $titleOrField Natural language title of the tabset, or first tab. * If its left out, the class uses {@link FormField::name_to_label()} to produce a title * from the {@link $name} parameter. * @param FormField ...$fields All following parameters are inserted as children to this tab */ public function __construct($name, $titleOrField = null, $fields = null) { if (!is_string($name)) { throw new InvalidArgumentException('Invalid string parameter for $name'); } // Get following arguments $fields = func_get_args(); array_shift($fields); // Detect title from second argument, if it is a string if ($titleOrField && is_string($titleOrField)) { $title = $titleOrField; array_shift($fields); } else { $title = static::name_to_label($name); } // Remaining arguments are child fields parent::__construct($fields); // Assign name and title (not assigned by parent constructor) $this->setName($name); $this->setTitle($title); $this->setID(Convert::raw2htmlid($name)); }
/** * @param string $name Identifier * @param string|Tab|TabSet $titleOrTab Natural language title of the tabset, or first tab. * If its left out, the class uses {@link FormField::name_to_label()} to produce a title * from the {@link $name} parameter. * @param Tab|TabSet ...$tabs All further parameters are inserted as children into the TabSet */ public function __construct($name, $titleOrTab = null, $tabs = null) { if (!is_string($name)) { throw new InvalidArgumentException('Invalid string parameter for $name'); } // Get following arguments $tabs = func_get_args(); array_shift($tabs); // Detect title from second argument, if it is a string if ($titleOrTab && is_string($titleOrTab)) { $title = $titleOrTab; array_shift($tabs); } else { $title = static::name_to_label($name); } // Normalise children list if (count($tabs) === 1 && (is_array($tabs[0]) || $tabs[0] instanceof FieldList)) { $tabs = $tabs[0]; } // Ensure tabs are assigned to this tabset if ($tabs) { foreach ($tabs as $tab) { if ($tab instanceof Tab || $tab instanceof TabSet) { $tab->setTabSet($this); } else { throw new InvalidArgumentException("TabSet can only contain instances of other Tab or Tabsets"); } } } parent::__construct($tabs); // Assign name and title (not assigned by parent constructor) $this->setName($name); $this->setTitle($title); $this->setID(Convert::raw2htmlid($name)); }
/** * Create a new field group. * * Accepts any number of arguments. * * @param mixed $titleOrField Either the field title, list of fields, or first field * @param mixed ...$otherFields Subsequent fields or field list (if passing in title to $titleOrField) */ public function __construct($titleOrField = null, $otherFields = null) { $title = null; if (is_array($titleOrField) || $titleOrField instanceof FieldList) { $fields = $titleOrField; // This would be discarded otherwise if ($otherFields) { throw new InvalidArgumentException('$otherFields is not accepted if passing in field list to $titleOrField'); } } else { if (is_array($otherFields) || $otherFields instanceof FieldList) { $title = $titleOrField; $fields = $otherFields; } else { $fields = func_get_args(); if (!is_object(reset($fields))) { $title = array_shift($fields); } } } parent::__construct($fields); if ($title) { $this->setTitle($title); } }
/** * @inheritdoc * * @param string $name * @param string $title * @param array|FieldList $children */ public function __construct($name, $title, $children) { parent::__construct($children); $this->setName($name); $this->setTitle($title); }