silverstripe-framework/forms/Tab.php
Ingo Schommer 8cc5625708 ENHANCEMENT Ability to add title constructor arguments to Tab and TabSet classes to resolve i18n issues with untranslated or unreferencable Tabs (see #2359)
ENHANCEMENT Support for $field_labels in relation tabs created by DataObject->addScaffoldRelationFields()
ENHANCEMENT Type checking and user errors for Tab and TabSet constructor arguments
ENHANCEMENT Supporting titles in FieldSet->findOrMakeTab()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64073 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-10-10 16:00:50 +00:00

63 lines
1.5 KiB
PHP
Executable File

<?php
/**
* Implements a single tab in a {@link TabSet}.
* @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->id() . '_' . $this->id;
}
public function Fields() {
return $this->children;
}
public function setTabSet($val) {
$this->tabSet = $val;
}
/**
* Returns the named field
*/
public function fieldByName($name) {
foreach($this->children as $child) {
if($name == $child->Name()) return $child;
}
}
}
?>