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.

Customising the CMS /

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

New Admin Module


Go to End
Reply


14 Posts   3839 Views

Avatar
Tonyair

Community Member, 81 Posts

24 September 2010 at 5:44am

Requirements isn't working for getCMSFields =(
class Product:

	public function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->removeByName('Content');
		$fields->addFieldToTab('Root.Main', new MyCustomField('Content'));

		return $fields;
	}

But if u add them to ProductsAdmin::init() works fine.

Avatar
Martijn

Community Member, 271 Posts

24 September 2010 at 7:33am

Can you post your code with the Requirements?

This does work for me:

function getCMSFields(){
		$f = parent::getCMSFields();
		Requirements::javascript('articles/javascript/articles.js');
		return $f;
	}

Avatar
Tonyair

Community Member, 81 Posts

24 September 2010 at 8:59am

class CkEditField extends HtmlEditorField {
	public static function include_js($name) {
		Requirements::block('sapphire/thirdparty/tinymce/tiny_mce_src.js'); // <-- don't work
		Requirements::javascript('mysite/ckeditor/ckeditor.js'); // <-- don't work
	}
	function Field() {
		...
		Requirements::customScript($CKEditor->generateJS(), 'CkEditorConfig'); // <-- don't work
		return $CKEditor->editor($this->name, $value->getContent()); // <-- that's string returned and included
	}
	public function __construct($name, $title = null, $rows = 30, $cols = 20, $value = '', $form = null) {
		parent::__construct($name, $title, $rows, $cols, $value, $form);
		
		$this->include_js($name);
	}
...
}

Avatar
Martijn

Community Member, 271 Posts

24 September 2010 at 9:31am

And this works in ModelAdmin?

Avatar
Tonyair

Community Member, 81 Posts

24 September 2010 at 10:59am

It works in Content and popup window, but in PanelAdmin u have to add it manually and of course i have changed JS to replace tinymce.

Also that thing isn't working http://www.silverstripe.org/general-questions/show/292626?showPost=292632
So i think something wrong with PanelAdmin's parsing fields functions

Avatar
Martijn

Community Member, 271 Posts

24 September 2010 at 11:35am

I created a CustomTextField and these includes work:

<?php

class CustomTextField extends TextField {
	
	function __construct($name, $title = null, $value = "", $maxLength = null, $form = null){
		
		$this->include_js($name);
		parent::__construct($name, $title, $value, $maxLength, $form);
	}
	
	public static function include_js($name){
		Requirements::javascript('productadmin/testcode/test.js'); // <--- works
	}
	
	function Field() {
		$attributes = array(
			'type' => 'text',
			'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''),
			'id' => $this->id(),
			'name' => $this->Name(),
			'value' => $this->Value(),
			'tabindex' => $this->getTabIndex(),
			'maxlength' => ($this->maxLength) ? $this->maxLength : null,
			'size' => ($this->maxLength) ? min( $this->maxLength, 30 ) : null 
		);
		
		if($this->disabled) $attributes['disabled'] = 'disabled';
		Requirements::javascript('productadmin/testcode/test.js');	// <--- works	
		return $this->createTag('input', $attributes);
	}
}

The customScript in Field() does not work, but neither in ModelAdmin:

Requirements::customScript("var test = 'test';", 'UniqueID');

Go to Top