<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\KuferTools\Utils\WssField;


class WssFieldKnr extends WssField
{
  protected function getFieldNichtBearbeitbar($datamodulWert, $isFormular, string $requestPrefix = '')
  {
    $result = parent::getFieldNichtBearbeitbar($datamodulWert, $isFormular);
    $result .= $this->getHiddenInput($datamodulWert);

    return $result;
  }

  
  private function getHiddenInput($datamodulWert)
  {
    $name = $this->getDatamodulAndFieldName();
    $value = $datamodulWert->knr;

    return '<input type="hidden" name="' . $name . '" value="' . $value . '">';
  }

  public function getDefaultMaxLength(): ?int
  {
    return 10;
  }

  public function getValueFromPost(string $requestPrefix = '')
  {
    $value = parent::getValueFromPost($requestPrefix);

    return \StringOperations::substr($value, 0, 10);
  }
}