silverstripe / silverstripe-widgets

Widgets subsystem for Silverstripe CMS
http://silverstripe.org
BSD 3-Clause "New" or "Revised" License
38 stars 55 forks source link

UploadField doesn't work with Widget::getCMSFields() #20

Open stojg opened 12 years ago

stojg commented 12 years ago

This is the error message:

Fatal error: Call to a member function FormAction() on a non-object in /framework/forms/FormField.php on line 139

To reproduce:

public function getCMSFields() {
    return new FieldList(
        $imageField = new UploadField('Image', 'Upload image');
    ):
}
MattyBalaam commented 12 years ago

I'm also getting the same error using TreeDropdownField, should I open a separate bug for this?

stojg commented 12 years ago

Hi, sorry for the late reply, I've somehow disabled my github notifications.

Please do, even though the problem is basically the same for all of the more 'advanced' gridfields, it helps testing any solutions.

I've come as far realizing that the whole getCMSFields from Admin -> Page -> WidgetArea -> Widget doesn't work, and therefore some fields can't get hold on the actually Form or Controller.

What needs to be done is to refactor the whole thing. :/

MattyBalaam commented 12 years ago

That sounds like a big project!

I've noticed that lots of page functions don't seem to work with widgets, would this be something that would be included in a refactor? For example I wanted to get the URL from a Page ID by using $FooID.Link, but I had to write a custom function using SiteTree::get()->byID($pageID)->Link() instead.

ShiftedBit commented 11 years ago

Hi!

I'am using widgets for an upcoming project, and it is a must to enable the possibility of uploading images directly on widget creation. So I wanted to know if there are any news on that issue, if there's a workaround and if I may help somehow.

Could it also be, that has_many and many_many relations on widget do not work? I found out, that the according relation tables will not be created on /dev/build/

Thanks in advance, Markus

greenbanana commented 11 years ago

Amo666, you can attach an image this way...http://pastebin.com/wKiHApmq

screen shot 2013-08-27 at 12 36 31 am

ShiftedBit commented 11 years ago

Hi! Thank's for the hint, I already did it that way, but it is not the solution I need. Our client needs a perfect usability, so a user should have the ability to upload an image directly on widget creation.

I now use "GridFieldAddNewMultiClass" from the gridfieldextensions by @ajshort for choosing different widget classes. I use the standard silverstripe forms, so I can use standard formfields like the UploadField. Further I can generate a live preview of the widget in the Grid and on creation with a LiteralField. GridFieldOrderableRows enables Drag&Drop. That works for me.

jedateach commented 11 years ago

I have created a module that somewhat encapsulates @Amo666 's idea: https://github.com/burnbright/silverstripe-widgetpages.

In a nutshell:

        $fields->removeByName("SideBar");
        $fields->addFieldToTab("Root.Widgets",
            GridField::create("SideBar","SideBar",
                $this->SideBar()->Widgets(),
                GridFieldConfig_RecordEditor::create()
                    ->removeComponentsByType("GridFieldAddNewButton")
                    ->addComponent(new GridFieldAddNewMultiClass())
                    ->addComponent(new GridFieldOrderableRows())
            )
        );
g4b0 commented 10 years ago

I have created a module that transform @jedateach in an extension, and in addition to provide a workaround for this issue it give some enhancement to the original widget module, like many_many relationship instead of the original has_many and an alternative templating strategy. Here you are the link:

http://addons.silverstripe.org/add-ons/zirak/widget-pages-extension

blpraveen commented 10 years ago

Multiselect Module does not work inside widget

nguyenhoanglong1331 commented 6 years ago

why has this important issue not been fixed for many years?

robbieaverill commented 6 years ago

@nguyenhoanglong1331 since this issue is so old I imagine parts of it are no longer relevant. If you’re still experiencing this problem could you please provide us with your composer.json contents and some steps to reproduce?

nguyenhoanglong1331 commented 6 years ago

Here is my composer.json

{
    "name": "silverstripe/installer",
    "type": "silverstripe-recipe",
    "description": "The SilverStripe Framework Installer",
    "require": {
        "php": ">=5.6.0",
        "silverstripe/recipe-plugin": "^1",
        "silverstripe/recipe-cms": "1.1.1@stable",
        "silverstripe-themes/simple": "~3.2.0",
        "unclecheese/betterbuttons": "2.x-dev",
        "silverstripe/widgets": "^2.0"
    },
    "require-dev": {
        "phpunit/phpunit": "^5.7"
    },
    "extra": {
        "branch-alias": {
            "4.x-dev": "4.2.x-dev",
            "dev-master": "5.x-dev"
        },
        "project-files-installed": [
            "mysite/.htaccess",
            "mysite/_config.php",
            "mysite/_config/mysite.yml",
            "mysite/code/Page.php",
            "mysite/code/PageController.php"
        ],
        "public-files-installed": [
            ".htaccess",
            "index.php",
            "install-frameworkmissing.html",
            "install.php",
            "web.config"
        ]
    },
    "config": {
        "process-timeout": 600
    },
    "prefer-stable": true,
    "minimum-stability": "dev"
}

and in the widget file

public function getCMSFields()
    {
        return new FieldList(
            new HTMLEditorField('Paragraph', 'Content'),
            new NumericField('MaxWidth', 'Max Width'),
            new NumericField('PaddingBottom', 'Padding Bottom'),
            new TextField('Color', 'Color'),
            new TextField('BackgroundColor', 'Background Color'),
            new UploadField('Photo','Photo')
            //UploadFiled::create('Photo','Photo')
        );
    }

All the other fileds are working good, but when i put the UploadField, it throws an error

robbieaverill commented 6 years ago

Thank you @nguyenhoanglong1331

gdelavil commented 6 years ago

+1 to this issue. I'm also using the solution with GridFieldAddNewMultiClass for now, but it'd be awesome to use the original interface, which is much nicer.

xini commented 6 years ago

Suggestion: ditch widgets and use Shea Dawson's blocks module for SS3 or elemental for SS4.

grandcreation commented 6 years ago
  
public function getSchemaDataDefaults()
    {
        $defaults = parent::getSchemaDataDefaults();
        $uploadLink = $this->Link('upload');

        $defaults['data']['createFileEndpoint'] = [
            'url' => $uploadLink,
            'method' => 'post',
            'payloadFormat' => 'urlencoded',
        ];
        $defaults['data']['maxFiles'] = $this->getAllowedMaxFileNumber();
        $defaults['data']['multi'] = $this->getIsMultiUpload();
        $defaults['data']['parentid'] = $this->getFolderID();
        $defaults['data']['canUpload'] = $this->getUploadEnabled();
        $defaults['data']['canAttach'] = $this->getAttachEnabled();

        return $defaults;
    }

The issue happen because the input can not get the form when calling $this->Link('upload') function (file SilverStripe\AssetAdmin\Forms\UploadField.php) Can anyone help me to get over it ?

robbieaverill commented 6 years ago

@grandcreation you might have more luck if you move that problem into the silverstripe-asset-admin repository