public function getCMSFields()
 {
     //Fetch curret fields and store in Fields
     $fields = parent::getCMSFields();
     //Remove Fields
     $fields->removeFieldFromTab("Root.Main", array("SortOrder", "CalendarID", "Title", "Content", "StartDate", "StartTime", "EndDate", "EndTime", "Location"));
     //Event Title
     $Title = new TextField("Title", "Event Title");
     $Title->setRightTitle("Enter the event title. i.e. sports day.");
     //Start Date & Time
     $StartDate = new DateField("StartDate", "Start Date");
     $StartDate->setConfig('showcalendar', 1);
     $StartDate->setConfig('dateformat', 'dd/MM/YYYY');
     $StartTime = new TimeField("StartTime", "Start Time (Optional)");
     $StartTime->setConfig('use_strtotime', 1);
     //End Date & Time
     $EndDate = new DateField("EndDate", "End Date (Optional)");
     $EndDate->setConfig('showcalendar', 1);
     $EndDate->setConfig('dateformat', 'dd/MM/YYYY');
     $EndTime = new TimeField("EndTime", "End Time (Optional)");
     $StartTime->setConfig('use_strtotime', 1);
     //Location
     $Location = new AddressTextField("Location", "Event Location", "AIzaSyA-folYpPWGiFcpBZURJpf610nO6FJtqqQ");
     $Location->SetRightTitle("Optional. Begin typing and you will see address suggestions (Beta). Powered by Google.");
     $Location->addExtraClass("text");
     //Event Description
     $Description = new HTMLEditorField("Content", "Event Description");
     //Group Start and End Date & Time Fields
     $Times = FieldGroup::create($StartDate, $StartTime, $EndDate, $EndTime)->setTitle('Timings');
     //Add Fields to the CMS
     $fields->addFieldsToTab("Root.Main", array($Title, $Times, $Location, $Description));
     //Return Fields to the CMS
     return $fields;
 }
Пример #2
0
 public function testSetValueWithUseStrToTime()
 {
     $f = new TimeField('Time', 'Time');
     $f->setValue('11pm');
     $this->assertEquals($f->dataValue(), '23:00:00', 'Setting value to "11pm" parses with use_strtotime enabled');
     $this->assertTrue($f->validate(new RequiredFields()));
     $f = new TimeField('Time', 'Time');
     $f->setConfig('use_strtotime', false);
     $f->setValue('11pm');
     $this->assertEquals($f->dataValue(), null, 'Setting value to "11pm" parses with use_strtotime enabled');
     $this->assertFalse($f->validate(new RequiredFields()));
     $f = new TimeField('Time', 'Time');
     $f->setValue('11pm');
     $this->assertEquals($f->dataValue(), '23:00:00');
     $f = new TimeField('Time', 'Time');
     $f->setValue('11:59pm');
     $this->assertEquals($f->dataValue(), '23:59:00');
     $f = new TimeField('Time', 'Time');
     $f->setValue('11:59 pm');
     $this->assertEquals($f->dataValue(), '23:59:00');
     $f = new TimeField('Time', 'Time');
     $f->setValue('11:59:38 pm');
     $this->assertEquals($f->dataValue(), '23:59:38');
     $f = new TimeField('Time', 'Time');
     $f->setValue('23:59');
     $this->assertEquals($f->dataValue(), '23:59:00');
     $f = new TimeField('Time', 'Time');
     $f->setValue('23:59:38');
     $this->assertEquals($f->dataValue(), '23:59:38');
 }
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->addFieldsToTab('Root.Text', array(new ReadonlyField('Readonly', 'ReadonlyField'), new TextareaField('Textarea', 'TextareaField - 8 rows', 8), new TextField('Text', 'TextField'), new HtmlEditorField('HTMLField', 'HtmlEditorField'), new EmailField('Email', 'EmailField'), new PasswordField('Password', 'PasswordField'), new AjaxUniqueTextField('AjaxUniqueText', 'AjaxUniqueTextField', 'AjaxUniqueText', 'BasicFieldsTestPage')));
     $fields->addFieldsToTab('Root.Numeric', array(new NumericField('Number', 'NumericField'), new CurrencyField('Price', 'CurrencyField'), new PhoneNumberField('PhoneNumber', 'PhoneNumberField'), new CreditCardField('CreditCard', 'CreditCardField')));
     $fields->addFieldsToTab('Root.Option', array(new CheckboxField('Checkbox', 'CheckboxField'), new CheckboxSetField('CheckboxSet', 'CheckboxSetField', TestCategory::map()), new DropdownField('DropdownID', 'DropdownField', TestCategory::map()), new GroupedDropdownField('GroupedDropdownID', 'GroupedDropdown', array('Test Categorys' => TestCategory::map())), new ListboxField('ListboxFieldID', 'ListboxField', TestCategory::map(), array(), 3), new OptionsetField('OptionSetID', 'OptionSetField', TestCategory::map())));
     // All these date/time fields generally have issues saving directly in the CMS
     $fields->addFieldsToTab('Root.DateTime', array($calendarDateField = new DateField('CalendarDate', 'DateField with calendar'), new DateField('Date', 'DateField'), $dmyDateField = new DateField('DMYDate', 'DateField with separate fields'), new TimeField('Time', 'TimeField'), $timeFieldDropdown = new TimeField('TimeDropdown', 'TimeField with dropdown'), new DatetimeField('DateTime', 'DateTime'), $dateTimeShowCalendar = new DatetimeField('DateTimeWithCalendar', 'DateTime with calendar')));
     $calendarDateField->setConfig('showcalendar', true);
     $dmyDateField->setConfig('dmyfields', true);
     $timeFieldDropdown->setConfig('showdropdown', true);
     $dateTimeShowCalendar->getDateField()->setConfig('showcalendar', true);
     $dateTimeShowCalendar->getTimeField()->setConfig('showdropdown', true);
     $fields->addFieldsToTab('Root.File', array(UploadField::create('File', 'FileUploadField'), UploadField::create('Image', 'ImageUploadField'), UploadField::create('HasManyFiles', 'HasManyFilesUploadField'), UploadField::create('ManyManyFiles', 'ManyManyFilesUploadField')));
     $tabs = array('Root.Text', 'Root.Numeric', 'Root.Option', 'Root.DateTime', 'Root.File');
     foreach ($tabs as $tab) {
         $tabObj = $fields->fieldByName($tab);
         foreach ($tabObj->FieldList() as $field) {
             $disabledField = $field->performDisabledTransformation();
             $disabledField->setTitle($disabledField->Title() . ' (disabled)');
             $disabledField->setName($disabledField->getName() . '_disabled');
             $tabObj->insertAfter($disabledField, $field->getName());
             $readonlyField = $field->performReadonlyTransformation();
             $readonlyField->setTitle($readonlyField->Title() . ' (readonly)');
             $readonlyField->setName($readonlyField->getName() . '_readonly');
             $tabObj->insertAfter($readonlyField, $field->getName());
         }
     }
     $fields->addFieldToTab('Root.Text', new TextField('Text_NoLabel', false, 'TextField without label'), 'Text_disabled');
     return $fields;
 }
 public function getFormField()
 {
     switch ($this->Type) {
         case 'datetime':
             $field = new DatetimeField($this->getFormFieldName(), $this->Title);
             $field->getDateField()->setConfig('showcalendar', true);
             $field->getTimeField()->setConfig('showdropdown', true);
             break;
         case 'date':
             $field = new DateField($this->getFormFieldName(), $this->Title);
             $field->setConfig('showcalendar', true);
             break;
         case 'time':
             $field = new TimeField($this->getFormFieldName(), $this->Title);
             $field->setConfig('showdropdown', true);
             break;
     }
     if ($this->DefaultType == 'created') {
         $field->setRightTitle('The value will default to the time this record was created.');
     }
     return $field;
 }
 /**
  * Test that AM/PM is preserved correctly in various situations
  */
 public function testPreserveAMPM()
 {
     // Test with timeformat that includes hour
     // Check pm
     $f = new TimeField('Time', 'Time');
     $f->setConfig('timeformat', 'h:mm:ss a');
     $f->setValue('3:59 pm');
     $this->assertEquals($f->dataValue(), '15:59:00');
     // Check am
     $f = new TimeField('Time', 'Time');
     $f->setConfig('timeformat', 'h:mm:ss a');
     $f->setValue('3:59 am');
     $this->assertEquals($f->dataValue(), '03:59:00');
     // Check with ISO date/time
     $f = new TimeField('Time', 'Time');
     $f->setConfig('timeformat', 'h:mm:ss a');
     $f->setValue('15:59:00');
     $this->assertEquals($f->dataValue(), '15:59:00');
     // ISO am
     $f = new TimeField('Time', 'Time');
     $f->setConfig('timeformat', 'h:mm:ss a');
     $f->setValue('03:59:00');
     $this->assertEquals($f->dataValue(), '03:59:00');
 }
 /**
  * @param TField $field
  * @param bool   $showMultipleFields
  */
 protected function configureTimeField(TField $field, $showMultipleFields = true)
 {
     if ($showMultipleFields) {
         // if not set then the default will be used for the locale
         if ($format = $this->config()->get('time_field_format')) {
             $field->setConfig('timeformat', $format);
         }
     }
 }