module/FzyCommon/src/FzyCommon/Service/Update/Base.php
protected function attachToMainEntity($tag, $entities, $mainEntitySetter, $afterAttachCallable = null, $mainEntityGetter = null)
    {
        $mainEntity = $entities[static::MAIN_TAG];
        $self = $this;
        $this->getEventManager()
            ->attach(self::EVENT_CONFIGURE_FORM.$tag, function (Event $e) use ($tag, $mainEntity, $mainEntitySetter, $afterAttachCallable, $self, $mainEntityGetter) {
                /* @var $form \Zend\Form\Form */
                $form = $e->getParam('form');
                // attach main entity to the entity generated by the form for this tag
                /**
                 * IMPORTANT: can't use the address entity as this may be a null object. Once it has been
                 * run through entity-to-form, the form generates a non-null entity it will save to. The
                 * office entity will need to attach to that
                 */
                $mainEntity->$mainEntitySetter($form->getObject());
                // if this entity changed, update the entities array on this service
                $self->swapEntity($tag, $form->getObject());
                if (empty($mainEntityGetter)) {
                    $mainEntityGetter = 'g'.substr($mainEntitySetter, 1);
                }
                // map this generated form in the main entity form
                // so any configuration changes are reflected when rendered
                $self->setFormMapEntry($mainEntityGetter, $form);

                if (is_callable($afterAttachCallable)) {
                    call_user_func($afterAttachCallable, $form->getObject(), $form, $mainEntity, $tag);
                }
            });

        return $this;
    }
protected function attachToMainEntity($tag, $entities, $mainEntitySetter, $afterAttachCallable = null, $mainEntityGetter = null)
    {
        $mainEntity = $entities[static::MAIN_TAG];
        $self = $this;
        $this->getEventManager()
            ->attach(self::EVENT_CONFIGURE_FORM.$tag, function (Event $e) use ($tag, $mainEntity, $mainEntitySetter, $afterAttachCallable, $self, $mainEntityGetter) {
                /* @var $form \Zend\Form\Form */
                $form = $e->getParam('form');
                // attach main entity to the entity generated by the form for this tag
                /**
                 * IMPORTANT: can't use the address entity as this may be a null object. Once it has been
                 * run through entity-to-form, the form generates a non-null entity it will save to. The
                 * office entity will need to attach to that
                 */
                $mainEntity->$mainEntitySetter($form->getObject());
                // if this entity changed, update the entities array on this service
                $self->swapEntity($tag, $form->getObject());
                if (empty($mainEntityGetter)) {
                    $mainEntityGetter = 'g'.substr($mainEntitySetter, 1);
                }
                // map this generated form in the main entity form
                // so any configuration changes are reflected when rendered
                $self->setFormMapEntry($mainEntityGetter, $form);

                if (is_callable($afterAttachCallable)) {
                    call_user_func($afterAttachCallable, $form->getObject(), $form, $mainEntity, $tag);
                }
            });

        return $this;
    }
Attaches a subentity to the main entity in several ways:

During form generation, some subentities may be null on the main entity, the form
will create a new doctrine entity to represent its data, the main entity needs to use
the specified 'setter' to set the main entity's relation to this newly generated entity
additionally, the entry for this new entity at 'tag' in the Update service's '$entities' array
will be modified.

Finally, the main entity will have a mapping set to this configured form so- on render- your configured
subform will be used

@param $tag
@param $entities
@param $mainEntitySetter
@param  null  $afterAttachCallable
@param  null  $mainEntityGetter
@return $this