Skip to content

Commit

Permalink
Add Choice field type - closes #574
Browse files Browse the repository at this point in the history
  • Loading branch information
claar committed Jan 30, 2019
2 parents c60a32e + 3f3f03d commit d8cf68f
Show file tree
Hide file tree
Showing 8 changed files with 1,951 additions and 16 deletions.
488 changes: 488 additions & 0 deletions src/Former/Form/Fields/Choice.php

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions src/Former/Former.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,14 @@ public function __call($method, $parameters)
}

// Checking for any supplementary classes
$classes = explode('_', $method);
$method = array_pop($classes);

$modifiers = explode('_', $method);
$method = array_pop($modifiers);
// Dispatch to the different Form\Fields
$framework = isset($this->app['former.form.framework']) ? $this->app['former.form.framework'] : $this->app['former.framework'];
$field = $this->dispatch->toFields($method, $parameters);

if ($field instanceof Field) {
$field = $framework->getFieldClasses($field, $classes);
}

$field->setModifiers($modifiers);
$field->addClass('');

// Else bind field
$this->app->instance('former.field', $field);

Expand Down
14 changes: 8 additions & 6 deletions src/Former/Traits/Checkable.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public function render()
{
$html = null;

$this->setFieldClasses();

// Multiple items
if ($this->items) {
unset($this->app['former']->labels[array_search($this->name, $this->app['former']->labels)]);
Expand Down Expand Up @@ -166,29 +168,29 @@ public function on($on)
/**
* Set the checkables as inline
*/
public function inline()
public function inline($isInline = true)
{
$this->inline = true;
$this->inline = $isInline;

return $this;
}

/**
* Set the checkables as stacked
*/
public function stacked()
public function stacked($isStacked = true)
{
$this->inline = false;
$this->inline = !$isStacked;

return $this;
}

/**
* Set the checkables as grouped
*/
public function grouped()
public function grouped($isGrouped = true)
{
$this->grouped = true;
$this->grouped = $isGrouped;

return $this;
}
Expand Down
45 changes: 45 additions & 0 deletions src/Former/Traits/FormerObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ abstract class FormerObject extends Element
*/
protected $injectedProperties = array('name');

/**
* The field's modifiers from method call
*
* @var string
*/
protected $modifiers;

////////////////////////////////////////////////////////////////////
/////////////////////////// ID AND LABELS //////////////////////////
////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -83,6 +90,19 @@ protected function getUniqueId($name)
return $name;
}

/**
* Runs the frameworks getFieldClasses method on this
*
* @return $this
*/
protected function setFieldClasses()
{
$framework = isset($this->app['former.form.framework']) ? $this->app['former.form.framework'] : $this->app['former.framework'];
$framework->getFieldClasses($this, $this->modifiers);

return $this;
}

/**
* Render the FormerObject and set its id
*
Expand All @@ -93,6 +113,10 @@ public function render()
// Set the proper ID according to the label
$this->setId();

if($this instanceof Field) {
$this->setFieldClasses();
}

// Encode HTML value
$isButton = ($this instanceof Field) ? $this->isButton() : false;
if (!$isButton and is_string($this->value)) {
Expand Down Expand Up @@ -153,4 +177,25 @@ public function isOfType()

return in_array($this->type, $types);
}

/**
* Set the modifiers from initial method call
*
* @return $this
*/
public function getModifiers()
{
return $this->modifiers;
}

/**
* Set the modifiers from initial method call
*
* @return $this
*/
public function setModifiers($modifiers)
{
$this->modifiers = $modifiers;
return $this;
}
}
Loading

0 comments on commit d8cf68f

Please sign in to comment.