Provide methods to handle text fields.
Inheritance: extends Widget
 /**
  * Check custom setting 'require_input', which implements custom mandatory handling possibility
  * @return string
  */
 public function generateLabel()
 {
     if ($this->require_input && $this->value == '') {
         $this->required = true;
     }
     return parent::generateLabel();
 }
 /**
  * @param mixed $varInput
  * @return mixed
  */
 protected function validator($varInput)
 {
     $this->rgxp = 'digit';
     $varInput = $this->encode($varInput);
     if ($this->unsigned && $varInput < 0) {
         $varInput = $varInput * -1;
     }
     return parent::validator(trim($varInput));
 }
 /**
  * @param mixed $varInput
  * @return mixed
  */
 protected function validator($varInput)
 {
     // Get language id
     $intId = $this->activeRecord ? $this->activeRecord->{$this->strName} : $GLOBALS['TL_CONFIG'][$this->strName];
     // Check if translation fields should not be empty saved
     if (!$GLOBALS['TL_CONFIG']['dontfillEmptyTranslationFields']) {
         // Fill all empty fields with the content of the fallback field
         $varInput = WidgetUtil::addFallbackValueToEmptyField($varInput);
         parent::validator($varInput);
     } else {
         // Check only the first field
         parent::validator($varInput[key($varInput)]);
     }
     // Check if array
     if (is_array($varInput)) {
         if (!parent::hasErrors()) {
             // Save values and return fid
             return TranslationFieldsModel::saveValuesAndReturnFid($varInput, $intId);
         }
     }
     return $intId;
 }
 /**
  * Test that the attribute can be instantiated.
  *
  * @param string $type   The date type.
  *
  * @param string $format The format string.
  *
  * @param string $value  The text value to use as post data.
  *
  * @return void
  *
  * @dataProvider dataProvider
  */
 public function testDateTime($type, $format, $value)
 {
     // Detect the widget bug and mark test skipped if encountered.
     if ($type === 'time') {
         try {
             $this->setConfigValue('timeFormat', $format);
             @TextField::getAttributesFromDca(array('eval' => array('rgxp' => 'time')), 'test', '11:22:33');
         } catch (\OutOfBoundsException $exception) {
             $this->markTestSkipped('Widget bug detected? See https://github.com/contao/core/pull/7721');
             return;
         }
     }
     $attribute = $this->getAttribute(array('timetype' => $type));
     $fieldDefinition = array_replace_recursive($attribute->getFieldDefinition(), array('eval' => array('submitOnChange' => false, 'allowHtml' => false, 'rte' => false, 'preserveTags' => false, 'encrypt' => false, 'nullIfEmpty' => false), 'activeRecord' => null, 'options_callback' => null, 'options' => null));
     $this->setConfigValue('dateFormat', 'd-m-Y');
     $this->setConfigValue('timeFormat', 'h:i');
     $this->setConfigValue('datimFormat', 'd-m-Y h:i');
     $this->setConfigValue($type . 'Format', $format);
     $this->setConfigValue('timeZone', 'GMT');
     $dateTime = new \DateTime($value, new \DateTimeZone(date_default_timezone_get()));
     $timeStamp = $dateTime->getTimestamp();
     $converted = $attribute->valueToWidget($timeStamp);
     $prepared = TextField::getAttributesFromDca($fieldDefinition, 'test', $value);
     $widget = $this->getMock('Contao\\TextField', array('getPost'), array($prepared));
     $widget->expects($this->any())->method('getPost')->will($this->returnValue($value));
     /** @var TextField $widget */
     $widget->validate();
     $text = $widget->value;
     $this->assertEquals($converted, $timeStamp);
     $converted = $attribute->widgetToValue($text, 1);
     $this->assertEquals(date($format, $timeStamp), date($format, $converted), date('d-m-Y h:i', $timeStamp) . ' <> ' . date('d-m-Y h:i', $converted));
 }