Skip to content
This repository has been archived by the owner on Mar 2, 2020. It is now read-only.

Commit

Permalink
Field refactore UI modifiers to trait
Browse files Browse the repository at this point in the history
  • Loading branch information
MarceauKa committed Nov 12, 2016
1 parent 6591625 commit ca95e43
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 121 deletions.
124 changes: 3 additions & 121 deletions src/Fields/Field.php
Expand Up @@ -3,6 +3,7 @@
namespace Akibatech\Crud\Fields;

use Akibatech\Crud\Services\CrudFields;
use Akibatech\Crud\Traits\FieldHasUiModifiers;
use Illuminate\View\View;

/**
Expand All @@ -12,6 +13,8 @@
*/
abstract class Field
{
use FieldHasUiModifiers;

/**
* @var string
*/
Expand All @@ -27,16 +30,6 @@ abstract class Field
*/
protected $identifier;

/**
* @var string
*/
protected $label;

/**
* @var string
*/
protected $placeholder;

/**
* @var array
*/
Expand Down Expand Up @@ -139,45 +132,6 @@ public function getIdentifier()
return $this->identifier;
}

/**
* Set a custom label for the field.
*
* @param string $name
* @return self
*/
public function withLabel($name)
{
$this->label = $name;

return $this;
}

/**
* Defines a placeholder for the field.
*
* @param string $placeholder
* @return self
*/
public function withPlaceholder($placeholder)
{
$this->placeholder = $placeholder;

return $this;
}

/**
* Appends an help message to the input.
*
* @param string $help
* @return self
*/
public function withHelp($help)
{
$this->help = $help;

return $this;
}

/**
* Render the field form.
*
Expand Down Expand Up @@ -271,38 +225,6 @@ public function getError()
return null;
}

/**
* Returns the field's placeholder.
*
* @param void
* @return string
*/
public function getPlaceholder()
{
if (empty($this->placeholder))
{
return null;
}

return $this->placeholder;
}

/**
* Returns the field's help.
*
* @param void
* @return string
*/
public function getHelp()
{
if (empty($this->help))
{
return null;
}

return $this->help;
}

/**
* Checks if the field has a previous value.
*
Expand Down Expand Up @@ -330,22 +252,6 @@ public function getOld()
return null;
}

/**
* Returns the field's label.
*
* @param void
* @return string
*/
public function getLabel()
{
if (empty($this->label))
{
return title_case($this->identifier);
}

return $this->label;
}

/**
* Get the field value.
*
Expand Down Expand Up @@ -394,28 +300,4 @@ public function getRules()
{
return $this->rules;
}

/**
* Return fields specific scripts files from public folder.
* Example: ['js/field.js']
*
* @param void
* @return array
*/
public function getScripts()
{
return [];
}

/**
* Return fields specific stylesheets files from public folder.
* Example: ['css/field.css']
*
* @param void
* @return array
*/
public function getCss()
{
return [];
}
}
137 changes: 137 additions & 0 deletions src/Traits/FieldHasUiModifiers.php
@@ -0,0 +1,137 @@
<?php

namespace Akibatech\Crud\Traits;

/**
* Class FieldHasUiModifiers
*
* @package Akibatech\Crud\Traits
*/
trait FieldHasUiModifiers
{
/**
* @var string
*/
protected $label;

/**
* @var string
*/
protected $placeholder;

/**
* @var string
*/
protected $help;

/**
* Set a custom label for the field.
*
* @param string $name
* @return self
*/
public function withLabel($name)
{
$this->label = $name;

return $this;
}

/**
* Defines a placeholder for the field.
*
* @param string $placeholder
* @return self
*/
public function withPlaceholder($placeholder)
{
$this->placeholder = $placeholder;

return $this;
}

/**
* Appends an help message to the input.
*
* @param string $help
* @return self
*/
public function withHelp($help)
{
$this->help = $help;

return $this;
}

/**
* Returns the field's label.
*
* @param void
* @return string
*/
public function getLabel()
{
if (empty($this->label))
{
return title_case($this->identifier);
}

return $this->label;
}

/**
* Returns the field's placeholder.
*
* @param void
* @return string
*/
public function getPlaceholder()
{
if (empty($this->placeholder))
{
return null;
}

return $this->placeholder;
}

/**
* Returns the field's help.
*
* @param void
* @return string
*/
public function getHelp()
{
if (empty($this->help))
{
return null;
}

return $this->help;
}

/**
* Return fields specific scripts files from public folder.
* Example: ['js/field.js']
*
* @param void
* @return array
*/
public function getScripts()
{
return [];
}

/**
* Return fields specific stylesheets files from public folder.
* Example: ['css/field.css']
*
* @param void
* @return array
*/
public function getCss()
{
return [];
}
}

0 comments on commit ca95e43

Please sign in to comment.