Skip to content

Commit

Permalink
Fix #215 and minor cleanup in Field
Browse files Browse the repository at this point in the history
  • Loading branch information
romaninsh committed Feb 10, 2017
1 parent 7fe8fa5 commit 0c7dcaf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/sql.rst
Expand Up @@ -93,7 +93,7 @@ SQL Reference
$model->hasOne('account_id', new Account())
->addFields([
[
['opening_balance', 'ui'=>['caption'=>'The Opening Balance']],
['opening_balance', 'caption'=>'The Opening Balance'],
'account_balance'=>'balance'
], ['type'=>'money']);

Expand Down Expand Up @@ -123,7 +123,7 @@ SQL Reference
You may pass defaults::

$model->hasOne('country_id', new Country())
->addTitle(['ui'=>['caption'=>'Country Name']]);
->addTitle(['caption'=>'Country Name']);

Returns new field object.

Expand Down
26 changes: 25 additions & 1 deletion src/Field.php
Expand Up @@ -12,7 +12,8 @@
class Field
{
use TrackableTrait;
// use \atk4\core\HookTrait;

// {{{ Properties

/**
* Default value of field.
Expand Down Expand Up @@ -88,6 +89,15 @@ class Field
*/
public $read_only = false;

/**
* Defines a label to go along with this field. Use getCaption() which
* will always return meaningfull label (even if caption is null). Set
* this property to any string.
*
* @var string
*/
public $caption = null;

/**
* Array with UI flags like editable, visible and hidden.
*
Expand Down Expand Up @@ -157,6 +167,9 @@ class Field
*/
public $dateTimeZoneClass = 'DateTimeZone';

// }}}

// {{{ Core functionality
/**
* Constructor. You can pass field properties as array.
*
Expand Down Expand Up @@ -306,6 +319,9 @@ public function set($value)
return $this;
}

// }}}

// {{{ Handy methods used by UI
/**
* Returns if field should be editable in UI.
*
Expand Down Expand Up @@ -338,6 +354,14 @@ public function isHidden()
return isset($this->ui['hidden']) ? $this->ui['hidden'] : false;
}

public function getCaption()
{
return isset($this->caption) ? $this->ui['caption'] :
ucwords(str_replace('_', ' ', $this->short_name));
}

// }}}

// {{{ Debug Methods

/**
Expand Down

0 comments on commit 0c7dcaf

Please sign in to comment.