Skip to content

Commit

Permalink
closes #1888 closes #1887
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Nov 28, 2018
1 parent d6a1235 commit ee0952a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
5 changes: 5 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ All notable changes to this project will be documented in this file. This projec

## 1.0.15 (in progress)

### Added

+ [#1887](https://github.com/luyadev/luya/issues/1887) Add attribute hints assign option for dynamic model.

### Fixed

+ [#1888](https://github.com/luyadev/luya/issues/1888) Fixed issue with ranger values which can have float values.
+ [#1876](https://github.com/luyadev/luya/issues/1876) Fixed the url generation without module context when using language switcher.

## 1.0.14 (17. November 2018)
Expand Down
36 changes: 29 additions & 7 deletions core/base/DynamicModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,34 @@
/**
* DynamicModel extends from yii\base\Dynamic Model.
*
* Additional Dynamic Model to provide attribute labels.
* Additional Dynamic Model to provide attribute labels and attribute hints.
*
* ```php
* $model = new DynamicModel(['query']);
* $model->attributeLabels = ['query' => 'Search term'];
* $model->attributeHints = ['query' => 'Enter a search term in order to find articles.'];
* $model->addRule(['query'], 'string');
* $model->addRule(['query'], 'required');
* ```
*
* @author Basil Suter <[email protected]>
* @since 1.0.0
*/
class DynamicModel extends \yii\base\DynamicModel
{
/**
* @var array An array with key value pairing where key is the attribute and value the label.
* @since 1.0.15
*/
public $attributeHints = [];

/**
* @var array Assignable attributes by array where key is the label key value the label for the key.
*/
public $attributeLabels = [];

/**
* In addition to the attributeLabels() values can also be be passed by propertie and run trough Yii::t process.
*
* @inheritDoc
*
* @see \yii\base\Model::attributeLabels()
* @return array
* {@inheritDoc}
*/
public function attributeLabels()
{
Expand All @@ -36,4 +45,17 @@ public function attributeLabels()

return $labels;
}

/**
* {@inheritDoc}
*/
public function attributeHints()
{
$hints = [];
foreach ($this->attributeHints as $key => $value) {
$hints[$key] = Yii::t('app', $value);
}

return $hints;
}
}

0 comments on commit ee0952a

Please sign in to comment.