Print on Details Screen


(Nic Hubbard) #1

I need a little help here. I am trying to understand how to print HTML onto the Details screen of an asset in the Admin interface. This may sound simple, but I am getting confused here.


Editing the …_edit_fns.inc file is what I am pretty sure needs to be edited. Is there a process of "painting" the contents with a special function? Trying to add my own function here and having it echo something inside is proving to not work.



Does the construct always need to be added to that file?


    	function __construct()
    	{
    		parent::__construct();
    
    	}//end constructor

(Peter Sheppard) #2

Isn't it done through the interfaces xml files?


(Mark Brydon) #3

[quote]I need a little help here. I am trying to understand how to print HTML onto the Details screen of an asset in the Admin interface. This may sound simple, but I am getting confused here.


Editing the …_edit_fns.inc file is what I am pretty sure needs to be edited. Is there a process of "painting" the contents with a special function? Trying to add my own function here and having it echo something inside is proving to not work.



Does the construct always need to be added to that file?[/quote]

A customised paint function will be required in the …_edit_fns.inc file. An asset with a "Details" screen configured in this manner is the Form Section asset (files under packages/cms/form/form_section). There are a couple of files that will need to be modified in your asset to get this to work:


  • ..._edit_fns.inc : a paint...() function to render your fields or other HTML. Please refer to the Form Section edit functions for the correct function signature
    [*]edit_interface_screen_details.xml : A <function_call> XML declaration to point to your paint function
    [*]locale/en/lang_screen_details.xml : A similar <function_call> declaration in this file
The _construct() declaration is only required if further values need to be set when creating your asset, for example, to control whether a certain screen is locked immediately after creation (see Matrix site: Creating an Asset).

If the interface being painted needs to perform processing, a process...() function will also need to be included and set up in a similar manner.

The compile_locale script will need to be run to associate the XML changes with your asset.

(Nic Hubbard) #4

[quote]A customised paint function will be required in the …_edit_fns.inc file. An asset with a "Details" screen configured in this manner is the Form Section asset (files under packages/cms/form/form_section). There are a couple of files that will need to be modified in your asset to get this to work:


  • ..._edit_fns.inc : a paint...() function to render your fields or other HTML. Please refer to the Form Section edit functions for the correct function signature
    [*]edit_interface_screen_details.xml : A <function_call> XML declaration to point to your paint function
    [*]locale/en/lang_screen_details.xml : A similar <function_call> declaration in this file
The _construct() declaration is only required if further values need to be set when creating your asset, for example, to control whether a certain screen is locked immediately after creation (see Matrix site: Creating an Asset).

If the interface being painted needs to perform processing, a process...() function will also need to be included and set up in a similar manner.

The compile_locale script will need to be run to associate the XML changes with your asset.[/quote]

Thank you Mark, very very helpful! I thought that I was missing something.

I will get to work using your suggestions, and post back here if I run into problems.

Thanks again!

(Mark Brydon) #5

[quote]Thank you Mark, very very helpful! I thought that I was missing something.


I will get to work using your suggestions, and post back here if I run into problems.



Thanks again![/quote]

No worries. B)


(Nic Hubbard) #6

Ok, I looked through the examples…


Is it possible to do processing as well as print a text field? Something like:


    		
    			
    				
    				
    			
    		


Combined with something like:

    		
    			
    		



So that processing can happening with a text field? Would it be to just add an attribute (attribute="name") to the <field> tag that is surrounding the function call?

(Mark Brydon) #7

[quote]Is it possible to do processing as well as print a text field? Something like:

    		
    			
    				
    				
    			
    		


Combined with something like:

    		
    			
    		



So that processing can happening with a text field? Would it be to just add an attribute (attribute="name") to the <field> tag that is surrounding the function call?[/quote]
The form element (text field etc.) would need to be printed and handled in the paint...() and process...() functions in the ..._edit_fns.inc file.
In this case, saving the attribute itself from POST vars using the setAttributeValue() and saveAttributes() functions will also need to be done there, just like paint/processQuestionLinks() does now.

Only the <field><function_call>... block is required as the interface for the attribute will be handled manually in the ...edit_fns.inc file.

(Huan Nguyen) #8

Unfortunately you would have to do the displaying and saving in your paint** and process** function.
So you would have to do something like

    paint {
     $o->openField('name')
       echo $name;
     $o->closeField();
     $o->note('The name of the field');
     
    }
    
    process {
     // Check $_POST var
     // if different, 
     $asset->setAttrValue('name', $new_name);
     $asset->saveAttributes();
    }


You can have a look at
/core/assets/files/image_variety/image_variety_edit_fns.inc
It's a bit more complicated that what you are doing, but you would get the idea.

(Nic Hubbard) #9

Ok, you guys have been a huge help, and I have gotten much further. I have managed to print the field using my function, but I still think there is something wrong, as changing the fields content, and committing does not save it. Is this where the process function needs to happen in order to save that value? I am not entirely positive I have the correct arguments for the paint function, and I have no idea what arguments to use for the process function.


Here is what I have:


    	function paintMp3Attributes(MP3_File $asset, Backend_Outputter $o)
    	{
    		//Paint the album field
    		$o->openField('Album');
    			$text_edit_params = new SimpleXMLElement('');
    			$attr = $asset->getAttribute('album');
    			$attr->setEditParams($text_edit_params);
    			$attr->paint($attr->album);
    			unset($album);
    		$o->note('The name of the Album or Event');
    		$o->closeField();
    	}


From this, I am getting the following error:

    PHP Notice
    File:	[SYSTEM_ROOT]/packages/custom_assets/mp3_file/mp3_file_edit_fns.inc	Line:	46
    Message:	Undefined property: Asset_Attribute_Text::$album
    Backtrace:	Show


Edit: I fixed this. :)

(Nic Hubbard) #10

Ok, got the error to go away, by doing:

    $attr->paint($attr->name);


For some reason, the field stays as an input field even when the locks are released...

EDIT: I found out what was wrong. :)

(Nic Hubbard) #11

One last thing here. I still am not able to input values into a field that was created with a function and have it be saved when you click commit. It always just stays blank, or reverts of what was there. I know that it is not being overwritten each time but the function. The field name is in the correct format as the other field painted by the .xml file, but for some reason, those painted with my function just won't save attributes unless I save them using the function.


Any ideas what this would be?


(Greg Sherwood) #12

[quote]One last thing here. I still am not able to input values into a field that was created with a function and have it be saved when you click commit. It always just stays blank, or reverts of what was there. I know that it is not being overwritten each time but the function. The field name is in the correct format as the other field painted by the .xml file, but for some reason, those painted with my function just won't save attributes unless I save them using the function.


Any ideas what this would be?[/quote]



If you use your own function, you need to do all the hard work, like saving, yourself. You need to call setAttrValue('attr_name', 'value') on the asset to set the value and extract the value ($asset-attr('attr_name')) to populate the existing fields.


(Nic Hubbard) #13

Thanks, I got it working. :)