In my experience working with stuff like this, I've found edit and add
functionality to be almost identical always. So what I typically do is:

Add:
$entity = new foobar():
// set any values that apply only to add mode and not edit
Add_edit_foobar($entity);

Edit:
$entity = // load the entity by id
// set any values that apply only to edit mode and not add (usually none)
Add_edit_foobar(entity);

Add_edit_foobar:
// set any values that are sent on both add and edit mode and submit
// if errors exist or not submitted, show the edit form
// else return true on success
On Mar 16, 2014 2:18 PM, "Matt Friedman" <notifications@github.com> wrote:

> In controller/admin_controller.php:
>
> > +			{
> > +				$errors[] = $this->user->lang['RULE_TITLE_EMPTY'];
> > +			}
> > +
> > +			if (empty($errors))
> > +			{
> > +				// Initiate a rule entity
> > +				$entity = $this->phpbb_container->get('phpbb.boardrules.entity');
> > +
> > +				// Grab the form's message parsing options (possible values: 1 or 0)
> > +				$message_parse_options = array(
> > +					'bbcode' => $this->request->variable('enable_bbcode', 0),
> > +					'magic_url' => $this->request->variable('enable_magic_url', 0),
> > +					'smilies' => $this->request->variable('enable_smilies', 0),
> > +				);
> > +
>
> I would just avoid anything that would require passing the $entity around
> between functions.
>
> --
> Reply to this email directly or view it on GitHub<https://github.com/phpbb-extensions/boardrules/pull/80/files#r10641103>
> .
>