This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Update: The correct way apparently is to use _relation_viewPath.htm in your controller folder. So in my example all I had to do was create _relation_button_predict.htm. This isn't documented in the OctoberCMS documentation yet and hence this post to another trying to figure it out.
Aliter/Old Post:
In RelationController you can only use 'add', 'create', 'update', 'delete', 'remove', 'link', 'unlink' as the buttons and if you write a custom one it will throw an error that the view is not found. Even if you add the view to the relation controller folder as _button_myaction.htm it will not accept and will throw an error because it only looks at one viewPath which is modules/backend/behaviors/relationcontroller/partials
. There is a github issue to address using a customViewPath
config field to overcome this but that does not solve the problem effectively because now you cannot use the existing 'add', 'create', etc. as that would need to be recreated in this new viewPath which means a lot of copy paste of the existing code.
The workaround is to redefine relationMakePartial
in your relation controller with this code:
public function relationMakePartial($partial, $params = [])
{
$inbuiltPartials = ['add', 'create', 'update', 'delete', 'remove', 'link', 'unlink'];
if (substr($partial, 0, strlen('button_')) == 'button_') {
$action = substr($partial, strlen('button_'));
if(!in_array($action, $inbuiltPartials)) {
$contents = $this->makePartial($partial, $params + $this->vars, false);
return $contents;
}
}
return parent::relationMakePartial($partial, $params);
}
Now you can write your own custom buttons. For example, I'm currently using toolbarButtons: create|delete|predict
and I simply had to create a file called _button_predict.htm in my controller folder and used this code to render my button:
<a
data-control="popup"
data-size="huge"
data-handler="onRelationPredict"
href="nojavascript...;"
class="btn btn-sm btn-secondary oc-icon-clock-o">
Predict
</a>
Now I can write my own custom popup as well. This works because I'm moving the view search to my controller folder and using the parent as a fallback. Hope this helps anyone looking to achieve this!
Last updated
1-2 of 2