Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Add field to UploadField iframe


Go to End


7 Posts   2105 Views

Avatar
MarijnKampf

Community Member, 176 Posts

13 September 2013 at 3:55am

I'm trying to add an additional field to the UploadField assets Edit section from SS3.0. The fields I've added are shown in the assets editor /site/admin/assets/EditForm/field/File/item/16/edit but they are not shown in the inline / iframe form of an UploadField /site/admin/pages/edit/EditForm/field/hibImages/item/16/edit.

Anyone any suggestions on what I'm missing?

Class:

class hibImage extends DataExtension {
	static $belongs_many_many = array (
		'HeaderImageBanners' => 'HeaderImageBanner'
	);
	
	function hibCroppedImage() {
		return $this->owner->croppedImage(HeaderImageBanner::$hibWidth, HeaderImageBanner::$hibHeight);
	}
	
	function random() {
		return rand();
	}

	public function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->push(new LiteralField("Literal", "<p>Test getCMSFields</p>"));
		return $fields;
	}

	// Shown 
	public function updateFormFields(FieldList $fields) {
		$fields->push(new LiteralField("Literal", "<p>Test updateFormFields</p>"));
		return $fields;
	}

	public function updateCMSFields(FieldList $fields) {
		$fields->push(new LiteralField("Literal", "<p>Test updateCMSFields</p>"));
		return $fields;
	}

	public function updateFrontEndFields(FieldList $fields) {
		$fields->push(new LiteralField("Literal", "<p>Test updateFrontEndFields</p>"));
		return $fields;
	}
}

Which is added to the mysite/_config.php with:

Object::add_extension('Image', 'hibImage');

Avatar
Naren

Community Member, 21 Posts

20 September 2013 at 5:27am

Hi MarijnKampf,

Please guide me a little, I have added headerimagebanner on my silverstripe site. Everything is working fine but slider is not working only one slide is visible.

Please let me know how to activate that.

Thanks in advance.

Avatar
MarijnKampf

Community Member, 176 Posts

20 September 2013 at 5:56pm

Hi Naren,

Can you give me a bit more info?
1. What SS version are you running?
2. Which version of the headerimagebanner are you using?
3. How many images have you added to the slider?
4. Are you getting any getting any JavaScript errors?

Marijn.

Avatar
George Vartanov

Community Member, 1 Post

15 November 2013 at 9:30pm

Hi, MarijnKampf!

Do You solve your this probblem??? I have same probblem and can't find answer. )))) Please reply me, how you solve it. Thx

Avatar
MarijnKampf

Community Member, 176 Posts

16 November 2013 at 12:02am

Sorry George, I haven't been able to find a solution for this so far.

Avatar
kinglozzer

Community Member, 187 Posts

16 November 2013 at 12:51am

I've achieved something similar (without using a DataExtension) in 3.1, not sure if it'll work in 3.0:

<?php

class LogoImage extends Image {

	private static $db = array(
		'ExternalURL' => 'Text'
	);

	private static $belongs_many_many = array(
		'Page' => 'Page'
	);

	/**
	 * @return FieldList 
	 */
	public function getCMSFields() {
		$fields = parent::getCMSFields();
	
		$fields->addFieldToTab('Root.Main', new TextField('ExternalURL', 'URL'));
	
		return $fields;
	}

}

There were some changes to how the EditForm is built:

3.0: https://github.com/silverstripe/silverstripe-framework/blob/3.0/forms/UploadField.php#L842-L879
3.1: https://github.com/silverstripe/silverstripe-framework/blob/3.1/forms/UploadField.php#L1445-L1462

Hope this helps

Avatar
Althegreat

Community Member, 1 Post

16 December 2016 at 10:22pm

I finally got it to work!

You need to add the field in the updateCMSFields() by using addFieldToTab() and add it to Root.Main tab.

Also you need to create a new tab in the updateCMSFields() before the field or otherwise if you try to edit the file info directly, Silverstripe will throw an error saying :
[User Error] FieldList::addFieldToTab() Tried to add a tab to object 'FieldList' - 'Root' didn't exist.

I found how to do it in this thread: https://www.silverstripe.org/community/forums/general-questions/show/21391

Here's an example of what the DataExtension class might look like :

class FileExtension extends DataExtension
{
    private static $db = array(
        'ImageAltText' => 'HTMLText',
    );

    public function updateCMSFields(FieldList $fields)
    {
        $fields->push(new TabSet("Root", $mainTab = new Tab("Main")));
        $mainTab->setTitle(_t('SiteTree.TABMAIN', "Main"));

        $imageAltTextField = new TextField('ImageAltText', 'Image Alt Text');

        $fields->addFieldToTab('Root.Main', $imageAltTextField);
    }
}

Then extend the File class with the new extension in config.yml and you should see the new field in the iframe

File:
  extensions:
    - FileExtension