Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stojg opened this issue Oct 8, 2012 · 17 comments
Open

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

stojg opened this issue Oct 8, 2012 · 17 comments

Comments

@stojg
Copy link

stojg commented Oct 8, 2012

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');
    ):
}
@ghost ghost assigned stojg Oct 8, 2012
@MattyBalaam
Copy link
Contributor

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

@stojg
Copy link
Author

stojg commented Oct 31, 2012

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
Copy link
Contributor

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
Copy link

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
Copy link

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

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

@ShiftedBit
Copy link

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
Copy link

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
Copy link

g4b0 commented Dec 12, 2013

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
Copy link

Multiselect Module does not work inside widget

@nguyenhoanglong1331
Copy link

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

@robbieaverill
Copy link
Contributor

@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
Copy link

nguyenhoanglong1331 commented Jul 18, 2018

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
Copy link
Contributor

Thank you @nguyenhoanglong1331

@gdelavil
Copy link

gdelavil commented Aug 2, 2018

+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
Copy link

xini commented Aug 2, 2018

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

@grandcreation
Copy link

grandcreation commented Sep 10, 2018

  
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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests