Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 86 lines (73 sloc) 2.192 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
<?php
/**
* Implements a single tab in a {@link TabSet}.
*
* Here is a simple implementation of a Tab. Obviously, you can include as much fields
* inside as you want. A tab can contain other tabs as well.
*
* <code>
* new Tab(
* $title='Tab one',
* new HeaderField("A header"),
* new LiteralField("Lipsum","Lorem ipsum dolor sit amet enim.")
* )
* </code>
*
* @package forms
* @subpackage fields-structural
*/
class Tab extends CompositeField {
protected $tabSet;

/**
* @uses FormField::name_to_label()
*
* @param string $name Identifier of the tab, without characters like dots or spaces
* @param string $title Natural language title of the tab. If its left out,
* the class uses {@link FormField::name_to_label()} to produce a title from the {@link $name} parameter.
* @param FormField All following parameters are inserted as children to this tab
*/
public function __construct($name) {
$args = func_get_args();

$name = array_shift($args);
if(!is_string($name)) user_error('TabSet::__construct(): $name parameter to a valid string', E_USER_ERROR);
$this->name = $name;

$this->id = preg_replace('/[^0-9A-Za-z]+/', '', $name);

// Legacy handling: only assume second parameter as title if its a string,
// otherwise it might be a formfield instance
if(isset($args[0]) && is_string($args[0])) {
$title = array_shift($args);
}
$this->title = (isset($title)) ? $title : FormField::name_to_label($name);

parent::__construct($args);
}

public function id() {
return ($this->tabSet) ? $this->tabSet->id() . '_' . $this->id : $this->id;
}

public function Fields() {
return $this->children;
}

public function setTabSet($val) {
$this->tabSet = $val;
return $this;
}

/**
* Returns the named field
*/
public function fieldByName($name) {
foreach($this->children as $child) {
if($name == $child->getName()) return $child;
}
}

public function extraClass() {
return implode(' ', (array)$this->extraClasses);
}

public function getAttributes() {
return array_merge(
$this->attributes,
array(
'id' => $this->id(),
'class' => 'tab ' . $this->extraClass()
)
);
}
}

Something went wrong with that request. Please try again.