Remove Module Lists in SugarCRM Custom Module - sugarcrm

I want to remove the Modules Tab (module list and sub-module list) from my custom module.
I have tried some solutions but in vain. e-g:
options['show_header'] = false;
It removes all header but I want to remove Logo and Global Links.
Disable all modules and change "tab=>false" in manifest.php file of custom module.

There's not an official way to do this through the configuration or anything, but you could use a custom logic hook for this to inject some javascript to hide the module list.
Say your custom module is abc_CustomModule, create a logic_hooks.php or add to it if it doesn't exist custom/modules/abc_CustomModule/logic_hooks.php
<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['after_ui_frame'] = Array();
$hook_array['after_ui_frame'][] = Array(1, 'Hide Modules', 'custom/modules/abc_CustomModule/abc_CustomModule_custom.php','abc_CustomModule_custom', 'hide_modules');
At the end of each page load for your custom module, it'll run the following code in custom/modules/abc_CustomModule/abc_CustomModule_custom.php
<?php
class abc_CustomModule_custom
{
function hide_modules($bean, $event)
{
echo "<script>$('#ajaxHeader').hide()</script>";
}
}
This simply outputs some javascript that will hide the div that contains the modules.

Related

TYPO3 set template view for controller action

I want to use the view template of the list action for my listByYear action. I tried setTemplatePathAndFilename without success. It still cannot find the template.
Sorry, the requested view was not found.
The technical reason is: No template was found. View could not be
resolved for action "listByYear" in class
"XXX\YYY\Controller\EventController".
/**
* action listByYear
* #param \XXX\YYY\Domain\Model\Event $event
*
* #return void
*/
public function listByYearAction(\XXX\YYY\Domain\Model\Event $event)
{
$date = $event->getStart();
$events = $this->eventRepository->findByYear($date->format('Y'));
$this->view->setTemplatePathAndFilename(
'typo3conf/ext/' .
$this->request->getControllerExtensionKey() .
'/Resources/Private/Templates/Event/List.html'
);
debug('typo3conf/ext/' .
$this->request->getControllerExtensionKey() .
'/Resources/Private/Templates/Event/List.html');
$this->view->assign('events', $events);
}
How do I make it use the template for the list?
The very short answer is, you can't. The view will already have been initialised and asked to resolve a template well before your action fires, indeed well before any point where you can affect the template filename that it would look for.
The template file that by convention would be resolved must always exist. This is what allows your controller action to render. You can then, but I would not recommend that you do, override the template file by setting the template name (the action).
Overall recommendation: use the default template naming logic. If you need to re-use templates, consider refactoring the template parts you need to reuse, placing them in partial templates.
// Do not forget the use in the header ...,
// or write fully qualified class path..
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
// then add something like this in your action before the assign...
// or maybe create a Standalone view: search the web for "Extbase Standaloneview"
// have a look at: /typo3/sysext/about/Classes/Controller/AboutController.php
$this->view = GeneralUtility::makeInstance(StandaloneView::class);
$this->view->setTemplate('ActionName');
$this->view->setTemplateRootPaths(['EXT:your_ext/Resources/Private/Templates']);
$this->view->setPartialRootPaths(['EXT:your_ext/Resources/Private/Partials']);
$this->view->setLayoutRootPaths(['EXT:your_ext/Resources/Private/Layouts']);
$this->view->assignMultiple([
'whatever' => $whatever,
'youLike' => $youLike,
]);

Adding Scripts to Nop Commerce plugin

I am trying to add bootstrap to a Payment Plugin that I am developing and I do not know why it's not including the files in OnePageChekout page that includes the PaymentInfo.cshtml partial view...
Code:
#model Nop.Plugin.Payments.PluginName.Domain.PluginModel
#{
Layout = "";
Html.AddScriptParts("~/Plugins/Payments.PluginName/Scripts/bootstrap.min.js");
Html.AddCssFileParts("~/Plugins/Payments.PluginName/Content/bootstrap.min.css");
}
#using Nop.Web.Framework.UI
Tried this as well:
#model Nop.Plugin.Payments.PluginName.Domain.PluginModel
#{
Layout = "";
Html.AddScriptParts(ResourceLocation.Foot,"~/Plugins/Payments.PluginName/Scripts/bootstrap.min.js", true);
Html.AddCssFileParts(ResourceLocation.Head, "~/Plugins/Payments.PluginName/Content/bootstrap.min.css");
}
#using Nop.Web.Framework.UI
Tried to use Html.AppendCssFileParts and Html.AppendScriptFileParts and it did not worked.
When debugging...the code calls this functions and it's adding the file references to the _scriptsParts and _cssParts variables.
But at that moment it adds my scripts those variables do not have any more scripts which I think it's odd.
Also it never calls the GenerateCssFiles function which I think is the function that adds the scripts to the bundle because this is only called after the page (OnePageCheckout.cshtml) is loaded and never when a partial view is loaded in the main view.
Am I right in this assumptions ? How can I add scripts dynamically to the PaymentInfo.cshtml page ?

Adding panels to editviewdefs.php via manifest file

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

sugarcrm disabling search page for module

I have two custom modules: cm_product, cm_item
with one to many relationship: cm_product -> cm_item
I want to disable the search page for cm_item, so the only way to see the items for customer is through it's parent reference: cm_product.
I need to accomplish it through the code.
This is my temporary solution if somebody interested in, file - custom/modules/cm_item/views/view.list.php:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once 'include/MVC/View/views/view.list.php';
class cm_itemViewList extends ViewList
{
public function preDisplay() { }
public function display() {
echo <<<HTML
<h1>Por favor seleccione la Oportunidad para ver sus correspondientes ventas e items.</h1>
HTML;
}
function prepareSearchForm(){ }
function listViewProcess(){ }
}
SugarCRM VersiĆ³n 6.5.11 (Build 8754) Pro edition.
it can be possible via add the blank array line at the end of file i.e.
custom/modules/cm_item/metadata/searchdefs.php
$searchdefs[$module_name] = array();
It sounds like you really just need the module tab for cm_item that links to the search and list view to not be displayed so that cm_items are only accessible through the subpanel of a cm_product. To do that you don't need code (unless you are doing it in a distributable module). Simply drag the cm_item module to the Hidden Modules list in Admin->Display Modules and Subpanels. If you are mass distributing the module then you would set tab to true in the beans definition in your manifest.php (see http://support.sugarcrm.com/04_Find_Answers/03_Developers/Module_Loader/Introduction_to_the_Manifest_File#tab)
You can remove the top module menu link by making sure the module isn't listed in the global array $moduleList

Zend Framework's Action helper doesn't use a ViewRenderer

I'm trying to execute an action from the view using the Action helper like but although the action is been executed the output isn't displayed.
Here's part of my .phtml file:
<div id="active-users">
<?php echo $this->action('active', 'Users') ?>
</div>
The action works like this:
class UsersController extends Zend_Controller_Action
{
function activeAction()
{
$model = new UsersModel();
$this->view->users = $model->getActiveUsers();
}
}
And there's another .phtml file that renders the list of users. The action works fine when called directly from /users/active but doesn't display anything when called from inside another .phtml file.
I've tracked the problem to the ViewRenderer not been available when called with action() helper... or at least not working as usual (automatically rendering the default .phtml file).
The content is displayed if I explicitly render the view inside the action but I need the ViewRender behaviour because I don't control the code of some of the actions I need to use.
Is there anyway to turn the ViewRenderer on while using the action() view helper? I'm open to replace the action() view helper if needed.
I forgot: I'm using PHP 5.2.8, Zend Framework 1.7.5, Apache 2.2 on Windows Vista.
Thanks
i think you should asign the active users from the controller or if you want you can use singleton on the models an use the directly in the views
$this->view = UsersModel::instance()->getActiveUsers();
Are you using _forward() o redirect on your action? Actions that result in a _forward() or redirect are considered invalid, and will return an empty string.
Update: I test it, and it works, try writing 'users' instead of 'Users' in the controllers param.
<div id="active-users">
<?php echo $this->action('active', 'users') ?>
</div>