In
SugarCRM installable changes in detailview
the question was asked about how to add a panel, using the Module Installer's manifest file to add to the the editview/detailview of an existing module without wiping out customizations previously made in the custom directory.
The answer was provided how to add fields, but not panels.
I know you could use a post_execute function called from the manifest file to edit the editviewdefs.php and detailviewdefs.php files in the
/custom/modules//metadata/
directory, but that involves making some guesses about what already exists in those files.
Does anyone know how to add panels via the manifest file (or post_execute) that incrementally adds the panel, without using php code to manually edit the editviewdefs.php and detailviewdefs.php files?
You're after the ParserFactory class, which can be used from a post_install or similar script executed as your module/package is installed. My understanding is that ParserFactory will call custom files if they're there, or stock files and adjust them appropriately and safely if not.
In your module's directory, create a subdirectory called 'scripts' and create 'post_install.php' which contains a single function post_install(). Your package dir will look something like this:
~$ find .
/LICENSE.txt
/manifest.php
/scripts/post_install.php
You use the ParserFactory like this:
<?php
function post_install(){
// $parser becomes an associative array for the metadata, similar to editviewdefs.php
require_once('modules/ModuleBuilder/parsers/ParserFactory.php');
$parser = ParserFactory::getParser('detailview', 'Accounts');
// finding the panels (which contain their fields), you can
// now add fields or additional arrays to this array, creating new panels
// (you could manipulate $parser->_viewdefs directly, but I find this easier)
$panels = array_keys ( $parser->_viewdefs [ 'panels' ] );
// place your panels back into the $parser and save
$parser->_viewdefs['panels'] = $panels;
$parser->handleSave(false);
};
Bingo - and Thank you to Matthew
I did not know where to find this and on the Sugar forum, no-one seemed to know so thank you Matthew.
So yes, it is very easy to add panels to an existing module in SugarCRM using the code that Matthew pointed out
To add a Panel called Events, in
/custom/modules/Accounts/language/en_us.lang.php
(add to this or create new file if you prefer)
add
$mod_strings = array ('LBL_DETAILVIEW_PANEL1' => 'Events',);
and then in the post_install.php file in the /scripts directory of the install package put
<?php
function post_install()
{
// Debug point - checking to see if get to post_install script
echo "Made it to the post_install script.<br />";
// Use the ParserFactory to edit the view arrays
// Fetch the existing view into an array called $view_array
require_once('modules/ModuleBuilder/parsers/ParserFactory.php');
$view_array = ParserFactory::getParser('detailview','Accounts');
// Declare the additional content
$new_content = array
(
0 => array
(
0 => array
(
'name' => 'created_by_name',
'label' => 'LBL_CREATED',
),
1 => array
(
'name' => 'modified_by_name',
'label' => 'LBL_MODIFIED_NAME',
),
),
);
// Add the new content to the desired section of the view array
$view_array->_viewdefs['panels']['lbl_detailview_panel1'] = $new_content;
//Save the layout
$view_array->handleSave(false);
return;
}
?>
(I have just put two existing fields in the new panel but you can just as easily place newly created fields (from the manifest file) into the new panel as well
Related
I created a model in SugarCRM and I need to print the details view. But this must be printed with a different layout.
It must have the company logo for example, if I just wanted do print the bean information, the default print would be sufficient, but I need something closer to a report, because this info will be given to the costumer.
I would like to know if there is a way to create a printing template, and if there is, how can I create one?
Thanks for your help, if you need more information please comment.
rfnpinto
Even in SugarCRM CE you can leverage the included Sugarpdf class, which is an extension of TCPDF.
If you have SugarCRM Professional you can find examples of this in the Quotes module. If not, you're flying blind, so I can give you the gist of it.
Using the Contacts module as an example, create /custom/modules/Contacts/views/view.sugarpdf.php with contents like the following:
<?php
require_once('include/MVC/View/views/view.sugarpdf.php');
/**
* this defines the view that will drive which PDF Template we use
*/
class CustomContactsViewSugarpdf extends ViewSugarpdf{
public function display(){
$this->sugarpdfBean->process();
$this->sugarpdfBean->Output($this->sugarpdfBean->fileName,'D');
sugar_die('');
}
}
Create /custom/modules/Contacts/sugarpdf/sugarpdf.pdfout.php with contents like the following:
$contact = BeanFactory::getBean($_REQUEST['record_id']);
if(empty($contact->id)){
sugar_die('Could not load contact record');
}
$name_str = "<p><strong>Name: {$contact->name}</strong></p>";
$this->writeHTML($name_str);
$this->drawLine();
}
function buildFileName(){
$this->fileName = 'ContactPDFOut.pdf';
}
}
From there, you can print a PDF document per your format if you hit the URI index.php?module=Contacts&action=sugarpdf&sugarpdf=pdfout&record_id=1234
Once that's working in the way you want, you can add a button the Contacts Detailview to access that URI more easily. Dig into /custom/modules/Contacts/metadata/detailviewdefs.php and find the existing buttons array. It'll look something like this:
'buttons'=>array('EDIT', 'DUPLICATE', 'DELETE', 'FIND_DUPLICATES'
Just enhance this with your own button and hidden input
'buttons'=>array('EDIT', 'DUPLICATE', 'DELETE', 'FIND_DUPLICATES',array(
'sugar_html'=>array(
'type' => 'submit',
'value' => '(Wrongfully Hardcoded Label) Print PDf',
'htmlOptions'=>array(onclick => 'this.form.action.value=\'sugarpdf\';this.form.sugarpdf.value=\'pdfout\'')
)
)
...
The hidden array should be part of $viewdefs['Meetings']['DetailView']['templateMeta']['form'] and defined like so:
'hidden' => array('<input type="hidden" name="sugarpdf">'),
I haven't tested this recently but this is the general idea of adding custom Print PDF abilities to any particular screen within SugarCRM. TCPDF options are pretty extensive and forming the template just right is going to be very tedious, but I think once the "plumbing" is working here you'll figure that bit out, but feel free to ask followup questions.
I have been attempting to create a form where a user can simply press a button and the form will add a new field for the user to use. I have 2 of these dynamically added field types.
Firstly a field where a user can upload files, by pressing the add button another field is pasted underneath the current field and is ready for use.
I have followed an old guide on how to get this done with a bit of ajax and jQuery.
This guide to be exact: http://www.jeremykendall.net/2009/01/19/dynamically-adding-elements-to-zend-form/
As you can see it's from 2009 and a bit outdated yet it still works under the current Zend Framework version 1.11.11
The problem however arises now that i want an edit / update version of the form. I need to populate it's fields but first of all i need to create enough fields for the data to be stored in. So when there's 3 files that have been uploaded it should create 2 additional fields and place the 3 file names in these fields ready to be edited and updated. Simply using $form->populate($stuff) is not going to work
I just have no idea how to accomplish this and the tutorial on dynamically added fields only goes as far as the addAction and not how to create the editAction under these conditions.
Is there any tutorial out there on how to create and manage forms such as these? I'm sure i am not the only one who's had the idea to builds these kind of forms?
I can add my code if there's a request for it but it's the same as the example from the guide, just a different set of elements in the form.
Adding a small example of it's use.
A user adds an item with 3 files, these files are uploaded along with a filename so in the database it appears like this : File_Id : '1' , File_Name : 'SomeFile' , File_location : 'somewhere/on/my/pc/SomeFile.txt'.
Now the user realizes he forgot a file or wants to delete a file from that list, he goes to the edit page and here i want the form to display the previously added filenames. So if there's 3 files it shows 3 and when there's 2 it shows 2 etc. How do i build a form to dynamically add fields based on the number of uploaded files and then populate them?
Any advice on how to handle this is well appreciated :)
You can make use of the semi-magic setXxx() methods of the form.
Inside the form:
public function setFiles($files) {
foreach ($files as $file) {
$this->addElement(/* add a file element */);
//do other stuff, like decorators to show the file name, etc.
}
}
In your controller:
$files = $model->getFiles();
$form = new Form_EditFiles(array('files' => $files));
By passing an array with key files you will make the form try to call the method named setFiles(), which you have conveniently provided above.
This should push you in the right direction, or so I hope at least.
If I understand you correctly you want to populate file upload fields, which is not possible because of security reasons.
Edit:
You can add Elements inside of the Controller via $form->addElement() (basicly just like the $this->addElement() statements in the Tutorial)
This is for SugarCRM v6.3
I need to add a "More Info" icon to the History subpanel, which, when moused-over, displays the relevant module's Description field, similar to how the More Info icon works in the Accounts ListView.
For starters I added new "History/metadata" folders to custom/modules/ and copied the subpaneldefs.php file from the core History/metadata folder.
In the subpaneldefs file, at the end of each of the module's column definitions, I added this as a test:
array ( 'customCode' => '<img src="themes/Sugar/images/info_inline.png"></img>', ),
That didn't seem to affect anything at all.
Not sure if it was just that I needed more than an image for the column to show, I then tried adding all of the code I thought was supposed to go there:
array (
'name' => 'nothing',
'module' => 'Notes',
'related_fields' => array ('id'),
'customCode' => '<a id="adspan_{$ID}" href="index.php?module=Notes&action=DetailView&record={$ID}" onmouseover="return SUGAR.util.getAdditionalDetails(\'Notes\',\'{$ID}\',\'adspan_{$ID}\');" onmouseout="return SUGAR.util.clearAdditionalDetailsCall()"><img src="themes/Sugar/images/info_inline.png"></img></a>'
),
This is, as you can see, intended for the Notes in the History subpanel, and I changed it accordingly for each of the other modules' column definitions in the subpaneldefs.php file. I modeled the code after some custom code I found that someone else here at work did for a dashlet, which shows details when an account name is moused over.
Unfortunately, that didn't work, either.
How do I accomplish this?
The only way to do this is by defining a new SugarWidget field for the field in question. Here's a good guide I found for it:
http://www.mediaart.lt/programming/sugarcrm-adding-custom-field-in-subpanel/
am new in Zend framework.
I have one .phtml file, includes menus section. i need to add that .phtml file in to the views i.e views/scripts/index.phtml page.
how can refer that
please advice
thanks in advance
You can use the render helper:
<?=$this->render('menu.phtml')?>
If you want to pass specific variables to the rendered script, use the partial helper:
<?=$this->partial('menu.phtml', array("varname" => "value"))?>
The menu.phtml file must be in the search path, which usually is the path to the current module's scripts directory ( view/scripts ). You can either place the menu.phtml file in this directory, or add a directory to the search path using the addScriptPath() method on the view object.
Try this
echo $this->partial('path/file.phtml', 'ModuleName')
Is there any easy way to disable translation of some of the Zend Navigation elements?
e.g. in this case
$page = new Zend_Navigation_Page_Mvc(
array(
'label' => $blogPost->alreadyTranslatedTitleFromDb
// ...
)
);
$container->addPage($page);
Now, when I use:
$page->getLabel();
the label is translated twice. The same for breadcrumbs, sitemaps etc.
I wrote a patch with unit tests for this:
http://framework.zend.com/issues/browse/ZF-10948
If you want only some specific elements to be disabled, i think that only way is to use a partial view script and create your own logic for the menu.
You may add custom properties to the pages. Example: add a property doNotTranslate and in your view script check for this property to know if element should be translated or not.
More info about partial view script is available at http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.navigation.menu