This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

jordan.brierley
jordan.brierley

Hey,

I am trying to extend the Users plugin with a nested relationship, what I need to do is to be able to add Packages as a tab for each user and for each Package add a PackageItem similar to how this video shows http://octobercms.com/support/article/ob-21

I have the relationship set up and can show Packages in a new tab when editing the users but in the partial which shows the PackageItem, because I dont want to change or add any files to the user plugin when add the handler onLoadCreatePackageRowForm to the add new button it looks in the Users controller for this, is there anyway of adding this handler to the Package controller or extending the Users controller to include this function in my Plugin.php?

<div id="packageItems">
    <?= $this->makePartial('~/plugins/author/module/controllers/package/_package_item_list.htm', ['package_items' => $model->package_items]) ?>
</div>

<p>
    <a
        href="nojavascript...;"
        class="btn btn-secondary oc-icon-plus"
        data-control="popup"
        data-handler="onLoadCreatePackageItemForm"
        data-size="large">
        Add Item
    </a>
</p>

Hope this makes sense, if anyone needs anymore info or anymore snippets just let me know

Last updated

jordan.brierley
jordan.brierley

Managed to find a work around for this for anyone interested, I created a dynamic method to use as the ajax handler when extending the user controller which creates another instance of my package controller which then calls a method from there so I can keep all the code in my controller eg:

public function boot()
{
    UsersController::extend(function($controller){
        $controller->addDynamicMethod('onLoadCreatePackageRowForm', function() {
            $servicePackage = new ServicePackage;
            $itemFormWidget = $servicePackage->onLoadCreatePackageRowForm();
            return $itemFormWidget;
        });
    }
}

I'm open to suggestions if anyone has found a better way

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.