Skip to content

Commit

Permalink
Adjust for removed Reference::refModel() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Mar 5, 2024
1 parent 1e2484d commit 1801e88
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@ public function controlFactory(Field $field, $controlSeed = []): Control

if ($field->type === 'json' && $field->hasReference()) {
$limit = ($field->getReference() instanceof ContainsMany) ? 0 : 1;
$model = $field->getReference()->refModel($this->model);
$model = $field->getReference()->createTheirModel();
$fallbackSeed = [Control\Multiline::class, 'model' => $model, 'rowLimit' => $limit, 'caption' => $model->getModelCaption()];
} elseif ($field->type !== 'boolean') {
if ($field->enum !== null) {
$fallbackSeed = [Control\Dropdown::class, 'values' => array_combine($field->enum, $field->enum)];
} elseif ($field->values !== null) {
$fallbackSeed = [Control\Dropdown::class, 'values' => $field->values];
} elseif ($field->hasReference()) {
$fallbackSeed = [Control\Lookup::class, 'model' => $field->getReference()->refModel($this->model)];
$fallbackSeed = [Control\Lookup::class, 'model' => $field->getReference()->createTheirModel()];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Form/Control/Multiline.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ protected function getLookupProps(Field $field): array

public function setLookupOptionValue(Field $field, string $value): void
{
$model = $field->getReference()->refModel($this->model);
$model = $field->getReference()->createTheirModel();
$entity = $model->tryLoadBy($field->getReference()->getTheirFieldName($model), $this->getApp()->uiPersistence->typecastLoadField($field, $value));
if ($entity !== null) {
$option = ['key' => $value, 'text' => $entity->get($model->titleField), 'value' => $value];
Expand Down Expand Up @@ -614,7 +614,7 @@ protected function getFieldItems(Field $field, ?int $limit = 10): array
if ($field->values !== null) {
$items = array_slice($field->values, 0, $limit, true);
} elseif ($field->hasReference()) {
$model = $field->getReference()->refModel($this->model);
$model = $field->getReference()->createTheirModel();
$model->setLimit($limit);

$theirFieldName = $field->getReference()->getTheirFieldName($model);
Expand Down
4 changes: 2 additions & 2 deletions src/Form/Control/ScopeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ protected function getFieldItems(Field $field, ?int $limit = 250): array
if ($field->values !== null) {
$items = array_slice($field->values, 0, $limit, true);
} elseif ($field->hasReference()) {
$model = $field->getReference()->refModel($this->model);
$model = $field->getReference()->createTheirModel();
$model->setLimit($limit);

foreach ($model as $item) {
Expand Down Expand Up @@ -689,7 +689,7 @@ protected function getConditionOption(string $type, $value, Condition $condition
case 'lookup':
$condField = $condition->getModel()->getField($condition->field);
$reference = $condField->getReference();
$model = $reference->refModel($condField->getOwner());
$model = $reference->createTheirModel();
$fieldName = $reference->getTheirFieldName($model);
$entity = $model->tryLoadBy($fieldName, $value);
if ($entity !== null) {
Expand Down

0 comments on commit 1801e88

Please sign in to comment.