/**
  * Generate the field ID value
  *
  * @param FormField
  *
  * @return string
  */
 public function generateFieldID($field)
 {
     if ($form = $field->getForm()) {
         return sprintf("%s_%s", $this->generateFormID($form), Convert::raw2htmlid($field->getName()));
     }
     return Convert::raw2htmlid($field->getName());
 }
 /**
  * @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));
 }
 /**
  * Tests {@link Convert::raw2htmlid()}
  */
 public function testRaw2HtmlID()
 {
     $val1 = 'test test 123';
     $this->assertEquals('test_test_123', Convert::raw2htmlid($val1));
     $val1 = 'test[test][123]';
     $this->assertEquals('test_test_123', Convert::raw2htmlid($val1));
     $val1 = '[test[[test]][123]]';
     $this->assertEquals('test_test_123', Convert::raw2htmlid($val1));
 }
 /**
  * Gets the list of options to render in this formfield
  * 
  * @return ArrayList
  */
 public function getOptions()
 {
     $selectedValues = $this->getValueArray();
     $defaultItems = $this->getDefaultItems();
     // Generate list of options to display
     $odd = 0;
     $formID = $this->ID();
     $options = new ArrayList();
     foreach ($this->getSource() as $itemValue => $title) {
         $itemID = Convert::raw2htmlid("{$formID}_{$itemValue}");
         $odd = ($odd + 1) % 2;
         $extraClass = $odd ? 'odd' : 'even';
         $extraClass .= ' val' . preg_replace('/[^a-zA-Z0-9\\-\\_]/', '_', $itemValue);
         $itemChecked = in_array($itemValue, $selectedValues) || in_array($itemValue, $defaultItems);
         $itemDisabled = $this->isDisabled() || in_array($itemValue, $defaultItems);
         $options->push(new ArrayData(array('ID' => $itemID, 'Class' => $extraClass, 'Name' => "{$this->name}[{$itemValue}]", 'Value' => $itemValue, 'Title' => $title, 'isChecked' => $itemChecked, 'isDisabled' => $itemDisabled)));
     }
     $this->extend('updateGetOptions', $options);
     return $options;
 }
 /**
  * @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));
 }
 /**
  * Get extra classes for each item in the list
  *
  * @param string $value Value of this item
  * @param bool $odd If this item is odd numbered in the list
  * @return string
  */
 protected function getOptionClass($value, $odd)
 {
     $oddClass = $odd ? 'odd' : 'even';
     $valueClass = ' val' . Convert::raw2htmlid($value);
     return $oddClass . $valueClass;
 }