This repository has been archived by the owner on Mar 2, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Field refactore UI modifiers to trait
- Loading branch information
Showing
2 changed files
with
140 additions
and
121 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,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 []; | ||
} | ||
} |