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

szuurveld13359
szuurveld13359

I've created a plugin that inserts a few images uploaded into a slider. I'm using the fileupload widget for this and I'm also using the title and description to display on my slides. However, I've been asked to add another option to my slides, like for example insert a color code to set as the background color of the div of that particular slide. Therefore, I'd like to extend the System\Models\File upload widget.

So my question is, is there a neat way to do this?

DMeganoski
DMeganoski

Sure. Create your own widget and have it's class just extend that class. Then, in your plugin, instead of referencing the original class, reference your custom one.

szuurveld13359
szuurveld13359

Awesome, thanks

So I created my own widget plugin, copied the exact october fileupload plugin except changed the classnames. Then I referenced it into my plugin, but it keeps saying this:

"Missing argument 1 for Backend\Classes\FormWidgetBase::__construct(), called in /home/ubuntu/workspace/vendor/october/rain/src/Database/Model.php on line 910 and defined" on line 70 of /home/ubuntu/workspace/modules/backend/classes/FormWidgetBase.php

I am using the class in my widget model as follows:

<?php namespace Creator\Client\FormWidgets;

use Backend\FormWidgets\FileUpload as FileUploadBase;

use Str; use Input; use Validator; use System\Models\File; use System\Classes\SystemException; use Backend\Classes\FormField; use Backend\Classes\FormWidgetBase; use October\Rain\Support\ValidationException; use Exception;

class FileUploader extends FileUploadBase

I am using it in my plugin model like this:

public $attachMany = [
  'images' => ['Creator\Client\FormWidgets\FileUploader', 'order' => 'sort_order'],
];

and in my Plugin.php registering it like this:

public function registerFormWidgets() { return [ 'Creator\Client\FormWidgets\FileUploader' => [ 'label' => 'FileUploader', 'code' => 'FileUploader' ], ]; }

Any idea what I'm missing?

DMeganoski
DMeganoski

I believe your mistake is in the definition of the relationship.

You are defining a relationship to a widget, when you should be relating to a model.

https://octobercms.com/docs/database/attachments

try using 'System\Models\File' as the related model, see if that works.

1-4 of 4

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