-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Herold
committed
Jan 8, 2015
1 parent
3d0a386
commit 2162c6a
Showing
35 changed files
with
617 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace hemio\form\Abstract_; | ||
|
||
use hemio\form\exception; | ||
|
||
/** | ||
* | ||
*/ | ||
abstract class FormElement extends \hemio\form\Container { | ||
|
||
protected $name = ''; | ||
|
||
/** | ||
* Is active value in the form correct. | ||
* | ||
* @return boolean | ||
*/ | ||
abstract public function dataValid(); | ||
|
||
/** | ||
* Has the value changed with respective to the stored or default value. | ||
* @return boolean | ||
*/ | ||
abstract public function changed(); | ||
|
||
/** | ||
* Get the form to which this element belongs | ||
* | ||
* @return Abstract_\Form | ||
* @throws exception\NotLazyEnough | ||
*/ | ||
public function getForm() { | ||
if ($this->existsInheritableAppendage('_FORM')) | ||
return $this->getInheritableAppendage('_FORM'); | ||
else { | ||
#print_r(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); | ||
|
||
throw new exception\NotLazyEnough( | ||
'No Form for FormElement found. Maybe not yet a child of a Form.'); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @return string | ||
*/ | ||
public function getName() { | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* | ||
* @param array $extraKeys | ||
* @return string | ||
*/ | ||
public function getHtmlName(array $extraKeys = []) { | ||
return $this->getForm()->getHtmlName() . | ||
'_' . $this->getName() . implode('_', $extraKeys); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<?php | ||
|
||
namespace hemio\form\Abstract_; | ||
|
||
use hemio\form as form_; | ||
use hemio\form\exception; | ||
use hemio\html; | ||
|
||
/** | ||
* | ||
* | ||
*/ | ||
abstract class FormFieldDefault extends FormField { | ||
|
||
use form_\Trait_\MaintainsFilters; | ||
|
||
/** | ||
* | ||
* @var string | ||
*/ | ||
public $title = ''; | ||
|
||
/** | ||
* | ||
* @var boolean | ||
*/ | ||
protected $filled = false; | ||
|
||
/** | ||
* | ||
* @var html\Interface_\Submittable | ||
*/ | ||
protected $control; | ||
|
||
/** | ||
* | ||
* @var string | ||
*/ | ||
protected $defaultValue = ''; | ||
|
||
/** | ||
* | ||
* @param mixed $value | ||
*/ | ||
public function setDefaultValue($value) { | ||
$this->defaultValue = $value; | ||
} | ||
|
||
/** | ||
* @return mixed Default value | ||
*/ | ||
public function getValueDefault() { | ||
return $this->getFiltered($this->defaultValue); | ||
} | ||
|
||
/** | ||
* | ||
* @param string $name | ||
* @param string $title | ||
* @param html\Interface_\Submittable $control | ||
*/ | ||
public function init($name, $title, $control) { | ||
$this->name = $name; | ||
$this->title = $title; | ||
$this->control = $control; | ||
} | ||
|
||
public function getValueToUse() { | ||
if ($this->getValueUser() !== null) | ||
return $this->getValueUser(); | ||
else if ($this->getValueStored() !== null) | ||
return $this->getValueStored(); | ||
else | ||
return $this->getValueDefault(); | ||
} | ||
|
||
public function getValueUser() { | ||
$value = $this->getForm()->getValueUser($this->getHtmlName()); | ||
if ($value === null) | ||
return null; | ||
else | ||
return $this->getFiltered($value); | ||
} | ||
|
||
public function getValueStored() { | ||
return $this->getFiltered( | ||
$this->getForm()->getValueStored($this->getName())); | ||
} | ||
|
||
public function changed() { | ||
return $this->getValueStored() != $this->getValueUser(); | ||
} | ||
|
||
/** | ||
* | ||
* @return TemplateFormField | ||
* @throws exception\NotLazyEnough | ||
* @throws exception\AppendageTypeError | ||
*/ | ||
public function getFieldTemplateClone($special = null) { | ||
|
||
$appendageName = form_\FormPost::FORM_FIELD_TEMPLATE . '_' . $special; | ||
|
||
if (!$this->existsInheritableAppendage($appendageName)) { | ||
$appendageName = form_\FormPost::FORM_FIELD_TEMPLATE; | ||
} | ||
|
||
$template = $this->getInheritableAppendage($appendageName); | ||
|
||
if ($template instanceof TemplateFormField) { | ||
return clone $template; | ||
} elseif ($template === null) { | ||
throw new exception\NotLazyEnough( | ||
sprintf( | ||
'There is no "%s" available for this Input', $appendageName | ||
) | ||
); | ||
} else { | ||
throw new exception\AppendageTypeError( | ||
sprintf( | ||
'Not an istance of TemplateFormFieldSingle "%s"', $appendageName | ||
) | ||
); | ||
} | ||
} | ||
|
||
public function describe() { | ||
return 'INPUT'; | ||
} | ||
|
||
/** | ||
* | ||
* @return string | ||
*/ | ||
public function __toString() { | ||
if (!$this->filled) | ||
$this->fill(); | ||
|
||
return parent::__toString(); | ||
} | ||
|
||
abstract public function fill(); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.