From 945d6b97eb6473409ce1a08dcef0306d16f75c01 Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Wed, 5 Aug 2020 16:16:25 +0200 Subject: [PATCH] [update] move to onlyField group of methods --- src/Model.php | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/Model.php b/src/Model.php index 2aa8108e2b..38a564db21 100644 --- a/src/Model.php +++ b/src/Model.php @@ -577,19 +577,22 @@ public function allFields() return $this; } - private function checkOnlyFieldsField(string $field) + private function checkOnlyFieldsField(string $fieldName) { - $this->getField($field); // test if field exists + $field = $this->getField($fieldName); // test if field exists - if ($this->only_fields) { - if (!in_array($field, $this->only_fields, true) && !$this->getField($field)->system) { - throw (new Exception('Attempt to use field outside of those set by onlyFields')) - ->addMoreInfo('field', $field) - ->addMoreInfo('only_fields', $this->only_fields); - } + if (!$this->isOnlyFieldsField($fieldName) && !$field->system) { + throw (new Exception('Attempt to use field outside of those set by onlyFields')) + ->addMoreInfo('field', $fieldName) + ->addMoreInfo('only_fields', $this->only_fields); } } + public function isOnlyFieldsField(string $fieldName) + { + return !$this->only_fields || in_array($fieldName, $this->only_fields, true); + } + /** * Will return true if specified field is dirty. */ @@ -619,16 +622,16 @@ public function getFields($filter = null): array $filterPresets = [ 'system' => function (Field $field) { - return $this->isOnlyField($field->short_name) && $field->system; + return $this->isOnlyFieldsField($field->short_name) && $field->system; }, 'not system' => function (Field $field) { - return $this->isOnlyField($field->short_name) && !$field->system; + return $this->isOnlyFieldsField($field->short_name) && !$field->system; }, 'editable' => function (Field $field) { - return $this->isOnlyField($field->short_name) && $field->isEditable(); + return $this->isOnlyFieldsField($field->short_name) && $field->isEditable(); }, 'visible' => function (Field $field) { - return $this->isOnlyField($field->short_name) && $field->isVisible(); + return $this->isOnlyFieldsField($field->short_name) && $field->isVisible(); }, 'persisting' => function (Field $field) { if ($field->never_persist) { @@ -636,7 +639,7 @@ public function getFields($filter = null): array } if (!$field->system) { - return $this->isOnlyField($field->short_name); + return $this->isOnlyFieldsField($field->short_name); } return true; @@ -663,11 +666,6 @@ public function getFields($filter = null): array }, ARRAY_FILTER_USE_BOTH); } - public function isOnlyField($fieldName) - { - return !$this->only_fields || in_array($fieldName, $this->only_fields, true); - } - /** * Set field value. *