Suitecrm custom template for custom module - sugarcrm

I built a custom module using the module builder.
I want to modify templates of my module (edit, detail, subpanel).
How can I tell Suitecrm to use an other template?
Thanks
(Suitecrm 7.7)

it's work for me.
<?php
require_once('include/MVC/View/SugarView.php');
class AccountsViewEdit extends SugarView {
private $smarty;
public function __construct() {
}
public function display() {
$this->smarty = new Sugar_Smarty();
$data = ['a'=> 'a', 'b'=>'b'];
$this->smarty->assign($data);
$this->smarty->display('path/custom/template.tpl');
}
}

You need to create a SugarView in the module and then override the display() method to return the path to your custom template. The convention is keep your templates in a 'tpl' folder in the module.
For example if you look at the 'modules/Accounts/views/view.edit.php' you would just need to add
class AccountsViewEdit extends ViewEdit
{
public function __construct()
{
parent::__construct();
$this->useForSubpanel = true;
$this->useModuleQuickCreateTemplate = true;
}
public function display() {
parent::display(); // TODO: Change the autogenerated stub
return $this->ss->fetch('path/to/your/smarty/template.tpl');
}
}
it's almost the same for the subpanels except the location is in the Dashlets folder. Take a look at modules/Accounts/Dashlets/MyAccountsDashlet/MyAccountsDashlet.php for example.

Related

I can't pass parameters to the component Wire Elements Modal

I can't pass parameters to the component.
I have 3 files:
Inside Livewire/test.blade.php
...............
onclick='Livewire.emit("openModal", "test-modal", {{ json_encode(["id_code" => $client->id_code]) }})'>
Inside /Http/Livewire/TestModal.php
namespace App\Http\Livewire;
use LivewireUI\Modal\ModalComponent;
use App\Models\Client;
class TestModal extends ModalComponent
{
public $id_code;
public function render($id_code)
{
dd($id_code);
return view('livewire.test-modal');
}
}
And livewire.test-modal which displays the content of the modal window.
But I can't get the id_code.
Let's see if someone can help me with this. Thanks.
So I had the same issue pretty much.
I solved it by adding the $id_code to the mount method. I hope it helps
namespace App\Http\Livewire;
use LivewireUI\Modal\ModalComponent;
use App\Models\Client;
class TestModal extends ModalComponent
{
public $id_code;
public function mount($id_code){
$this->id_code = $id_code
}
public function render()
{
$elCliente = Client::where("erp_code", $this->id_code)->first();
dd($elCliente);
return view('livewire.test-modal');
}
}
Livewire.emit("openModal") will emit an event that you can listen to in your components. The render() method in Livewire does not accept a parameter, so instead you need to listen to that event, and do your actions in a separate method instead.
By adding
protected $listeners = ['openModal' => 'openModal'];
the component will now listen to the event openModal (key in the array) being dispatched, and then fire the method openModal() (value in the array). Since you pass in two parameters, "test-modal" and a JSON parameter, you can accept those in that method.
namespace App\Http\Livewire;
use LivewireUI\Modal\ModalComponent;
use App\Models\Client;
class TestModal extends ModalComponent
{
public $id_code;
protected $listeners = ['openModal' => 'openModal'];
public function openModal($name, $data)
{
$this->id_code = $data['id_code'];
}
public function render()
{
return view('livewire.test-modal');
}
}

NatTable - how to implement custom CopyDataToClipboardSerializer

in CopyDataToClipboardSerializer I need to override copiedCells variable.
I do use NatTableFactory.class where I create table, register new CopyDataCommandHandler, override table style and so on. But I do not know how to override CopyDataToClipboardSerializer. Or should I register new one and create own class?
I don't know your NatTableFactory class. So I am not sure what you are doing inside that class.
If you need a custom serializer to for example replace line breaks in a text to a space to avoid breaking the table structure, you need to create a custom implementation and use that.
class MyCopyDataCommandHandler extends CopyDataCommandHandler {
public MyCopyDataCommandHandler(SelectionLayer selectionLayer, ILayer columnHeaderLayer, ILayer rowHeaderLayer) {
super(selectionLayer, columnHeaderLayer, rowHeaderLayer);
}
#Override
protected void internalDoCommand(CopyDataToClipboardCommand command, ILayerCell[][] assembledCopiedDataStructure) {
ISerializer serializer = new MyCopyDataToClipboardSerializer(assembledCopiedDataStructure, command);
serializer.serialize();
}
}
class MyCopyDataToClipboardSerializer extends CopyDataToClipboardSerializer {
public MyCopyDataToClipboardSerializer(ILayerCell[][] copiedCells, CopyDataToClipboardCommand command) {
super(copiedCells, command);
}
#Override
protected String getTextForCell(ILayerCell cell) {
return super.getTextForCell(cell).replace('\n', ' ');
}
}
Then register the custom MyCopyDataCommandHandler like this if the headers should be exported too:
CopyDataCommandHandler copyHandler =
new MyCopyDataCommandHandler(
selectionLayer,
columnHeaderDataLayer,
rowHeaderDataLayer);
gridLayer.registerCommandHandler(copyHandler);

Trying to disable layout in zend

I try to disable layout in zend action in this way:
$this->_helper->layout->disableLayout();
But it doesn't work:
Fatal error: Call to undefined method Application_Controller_Helper_Layout::disableLayout() in application/controllers/AssetController.php on line 18
I reckon that its, because I made my own helper.
Bootsrap.php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initMyActionHelpers()
{
$this->bootstrap('frontController');
$layout = Zend_Controller_Action_HelperBroker::getStaticHelper('Layout');
Zend_Controller_Action_HelperBroker::addHelper($layout);
}
}
application.ini
resources.frontController.actionhelperpaths.Application_Controller_Helper = APPLICATION_PATH "/controllers/helpers"
and my helper
class Application_Controller_Helper_Layout extends Zend_Controller_Action_Helper_Abstract
{
public function preDispatch()
{
}
}
Thanks!
If you want to rewrite Zend default layout helper, please extend Zend_Layout_Controller_Action_Helper_Layout.
class Application_Controller_Helper_Layout extends Zend_Layout_Controller_Action_Helper_Layout
Then you will still be able to use default disableLayout() function if you are not overwriting it in your own helper.
Try testing it using:
class Application_Controller_Helper_Layout extends Zend_Layout_Controller_Action_Helper_Layout
{
public function preDispatch(){}
public function disableLayout(){
echo "I won't disable layout anymore, because I overwrote the action with displaying this string.";
}
}

Get route params in RESTful controller

In my RestController which extends AbstractRestfulController, I can get the route params in the implemented functions such as...
public function create($data)
{
$entity = $this->params()->fromRoute('entity');
}
... but when I do the same in the constructor like this
public function __construct()
{
$entity = $this->params()->fromRoute('entity');
}
I get Call to a member function getParam() on a non-object.
Why is that? How can I get the route parameters in the constructor?
What I am trying to do
Since I'm trying to create a generic controller, there is a part of the restful route that is shared for all actions (resp. verbs). The entity for which the request is made. I'd like to store this in a class parameter for convenience.
Normally you'd write a method to proxy to whatever value you need, and just call that method, it's only a little more expensive to call $this->getEntity() than it is to call $this->entity, which, as far as I can tell is the stated aim
class RestController
{
protected $entity;
public function getEntity()
{
if (!$this->entity) {
$this->entity = $this->params()->fromRoute('entity');
}
return $this->entity;
}
}
If you really do want to pre-populate the entity property, the simplest method is to use an initializer, and move the code from your __constructor to init(). Have your controller implement \Zend\Stdlib\InitializableInterface
use Zend\Stdlib\InitializableInterface;
class RestController extends AbstractRestfulController implements InitializableInterface
{
protected $entity;
public function init() {
$this->entity = $this->params()->fromRoute('entity');
}
}
Add an initializer to the controller loader in your module boostrap
use Zend\Stdlib\InitializableInterface;
class Module
{
public function onBootstrap(MvcEvent $e)
$sm = $e->getApplication()->getServiceManager();
$controllers = $sm->get('ControllerLoader');
$controllers->addInitializer(function($controller, $cl) {
if ($controller instanceof InitializableInterface) {
$controller->init();
}
}, false); // false tells the loader to run this initializer after all others
}
}
That would not make any sense as the route is matched to a particular action.
You can't route to a constructor, therefore how could you get route parameters there?
If you give an idea of what you are trying to do then I could suggest a better/nicer way to do it

can't access helper file

My helper file Acl.php is in library/Helper and I have included it in bootstrap file as below:-
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initPlugins()
{
$helper= new Helper_Acl();
// $helper->setRoles();
// $helper->setResources();
// $helper->setPrivilages();
// $helper->setAcl();
}
}
but its giving error, Saying -> Fatal error: Class 'Helper_Acl' not found in Bootstrap.php.
Below is my helper file
class Helper_Acl
{
public $acl;
public function __construct()
{
$this->acl = new Zend_Acl();
}
}
in the bootstrap.php , try this , provided your class is in a Helper folder in the library :
protected function _initHelpers() {
Zend_Controller_Action_HelperBroker::addPrefix("Helper_");
}
if it doesnt work tell me , there are other methods.
You need to add Helper_ to your autoloadernamespaces. Typically, this is done in application/configs/application.ini:
autoloadernamespaces[] = "Helper_"