Skip to content

Commit

Permalink
HasManyLocal: getInstance() method, logic for setModel() from getInst…
Browse files Browse the repository at this point in the history
…ance() for manually use
  • Loading branch information
sngrl committed May 17, 2021
1 parent 6d7ecf8 commit 184eab4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Form/Related/Forms/HasManyLocal.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,17 @@ protected function emptyElement($element)
// call_user_func($this->emptyElementCallback, $el);
// }

/**
* Write this in your Section if you want to provide model instance directly
* or use uploadable (like image) fields inside your hasManyLocal element:
* ->setInstance($model)
*
* You can get model instance inside onEdit() via $this->getModelValue()
*/
if ($this->getInstance()) {
$el->setModel($this->getInstance());
}

return $el;
}

Expand All @@ -308,9 +319,24 @@ public function setModel(Model $model)
}
}

/**
* @return Model
*/
public function getInstance()
{
return $this->instance;
}

/**
* @param $instance
*
* @return $this
*/
public function setInstance($instance)
{
$this->instance = $instance;

return $this;
}

/**
Expand Down

0 comments on commit 184eab4

Please sign in to comment.