Skip to content

Commit

Permalink
[update] introduce Model::FIELD_FILTER_ONLY_FIELDS and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehristov committed Aug 6, 2020
1 parent 5857342 commit 0d962c3
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Model implements \IteratorAggregate
public const FIELD_FILTER_EDITABLE = 'editable';
/** @const string */
public const FIELD_FILTER_PERSIST = 'persist';
/** @const string */
public const FIELD_FILTER_ONLY_FIELDS = 'only fields';

// {{{ Properties of the class

Expand Down Expand Up @@ -644,6 +646,9 @@ public function getFields($filter = null): array
self::FIELD_FILTER_VISIBLE => function (Field $field) {
return $this->isOnlyFieldsField($field->short_name) && $field->isVisible();
},
self::FIELD_FILTER_ONLY_FIELDS => function (Field $field) {
return $this->isOnlyFieldsField($field->short_name);
},
self::FIELD_FILTER_PERSIST => function (Field $field) {
if ($field->never_persist) {
return false;
Expand Down Expand Up @@ -811,16 +816,8 @@ public function get(string $field = null)
if ($field === null) {
// Collect list of eligible fields
$data = [];
if ($this->only_fields) {
// collect data for actual fields
foreach ($this->only_fields as $field) {
$data[$field] = $this->get($field);
}
} else {
// get all fields
foreach ($this->getFields() as $field => $f) {
$data[$field] = $this->get($field);
}
foreach ($this->getFields(self::FIELD_FILTER_ONLY_FIELDS) as $field) {
$data[$field->short_name] = $this->get($field->short_name);
}

return $data;
Expand Down

0 comments on commit 0d962c3

Please sign in to comment.