SugarCRM customization of Basic template - templates

I need to add a field in basic template. Can anyone help me how can i add another field in include/SugarObjects/templates/basic/vardefs.php in upgrade safe manner.
In VardefManager's function addTemplate not like general standards of Sugar it is not requiring the custom paths
include/SugarObjects/VardefManager.php near line 107 SugarCE6.5.5:
if(empty($templates[$template])){
$path = 'include/SugarObjects/templates/' . $template . '/vardefs.php';
if(file_exists($path)){
require($path);
$templates[$template] = $vardefs;
}else{
$path = 'include/SugarObjects/implements/' . $template . '/vardefs.php';
if(file_exists($path)){
require($path);
$templates[$template] = $vardefs;
}
}
}
Really waiting for awesome responses.

Create a file at the path custom/include/SugarObjects/VardefManager.php with the name VardefManager.php and in that file include your mail file it is include/SugarObjects/VardefManager.php.
Here you will create a class with same and and create a function with the name
static function addTemplate
with same the arguments pass in the main file. and override the method here with your custom code (as you want to add some lines of code in that).
This will be upgrade safe and will be workable to you.

Related

How to change file url in drupal

I have a file field. On page it render like
9.doc
I want to make it lock like
9.doc
1 :( I already try to copy core/themes/bartik/templates/classy/field/file-link.html.twig to my theme and rename as FILE NAME SUGGESTIONS to file--link--user-checklist.html.twig but still have core template to render
2 :( I try to change url by checklistheme_preprocess_file_link but $variables['link']['#url']->setFileUri($my_url); but have error this method not exist
3 :( T try to add custom element to checklist_preprocess_paragraph(&$variables) but it no show up
I don't know what else I can do
Find myself
function MYTHEME_preprocess_file_link(&$variables) {
$file = \Drupal\Core\Url::fromUri('some_url');
$variables['link']['#url'] = $file;
}

Get frontend PHTML template's output inside a model method in Magento

In short: I want to call a frontend block inside a model to get the output of the PHTML template.
I have a test.phtml template which generates content of a specific HTML file for my module. This HTML has to be generated only on administrator request so I call it inside a controller. And that controller calls model:
public function generateAction()
{
Mage::getSingleton('helloworld/sample')->doSomething();
}
Model looks like this:
class My_Helloworld_Model_Sample Mage_Core_Model_Abstract
{
public function doSomething()
{
$templatePath = 'helloworld/test.phtml';
$output = Mage::app()->getLayout()
->createBlock("core/template")
->setData('area','frontend')
->setTemplate($templatePath)
->toHtml();
//write $output in HTML file
}
//...
}
It calls block, gets the output of the test.phtml template file and writes it in HTML file.
Why I don't generate that HTML inside one of the models methods? Two reasons:
- user needs to have easy access to that file
- .phtml file is much more readable for user/designer
That's why I want to create a block to get its output. But the problem is that when I try to create that block, I get this error:
CRIT (2): Not valid template
file:frontend/base/default/template/test.phtml
Magento searches for the template inside the "base" theme. If I put that file there (frontend/base/default/template/test.phtml), then all works fine. But I'd like to keep that template inside the current theme's directory (where I keep the rest of the module's template files):
frontend/package/theme/template/test.phtml
How could I achieve this?
EDIT:
I'm sorry, I wanted to simplify the code to make it more readable. Here's where the template file is actually located:
frontend\default\modern\template\mymodule\test.phtml
After the button in the admin panel is clicked, controller calls model:
public function generateAction()
{
//Get model and call the method to generate HTML
Mage::getSingleton('mymodule/sample')->doSomething();
}
Model creates block to get output of the test.phtml template:
class My_Mymodule_Model_Sample Mage_Core_Model_Abstract
{
public function doSomething()
{
$templatePath = 'mymodule' . DS . 'test.phtml';
$output = Mage::app()->getLayout()
->createBlock("core/template")
->setData('area','frontend')
->setTemplate($templatePath)
->toHtml();
//write $output in HTML file
}
//...
}
Until now all works fine. But when the block is created, Magento can't find the template file, and gives me this error:
CRIT (2): Not valid template
file:frontend\ base\default \template\mymodule\test.phtml
After I added Mage::log in app/code/core/Mage/Core/Model/Design/Package.php, I got this info in the system.log file:
2012-09-06T09:40:55+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\ frontend\default\default \template\mymodule\test.phtml
2012-09-06T09:40:55+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\frontend\default\default\template\mymodule\test.phtml
2012-09-06T09:40:55+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\frontend\default\default\template\mymodule\test.phtml
2012-09-06T09:40:55+00:00 CRIT (2): Not valid template
file:frontend\base\default\template\mymodule\test.phtml
2012-09-06T09:40:56+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\adminhtml\default\default\layout\local.xml
2012-09-06T09:40:56+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\adminhtml\default\default\layout\local.xml
2012-09-06T09:40:56+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\adminhtml\default\default\layout\local.xml
If I modify the model method like this (comment out reference to frontend):
class My_Mymodule_Model_Sample Mage_Core_Model_Abstract
{
public function doSomething()
{
$templatePath = 'mymodule' . DS . 'test.phtml';
$output = Mage::app()->getLayout()
->createBlock("core/template")
//->setData('area','frontend') // <--removed
->setTemplate($templatePath)
->toHtml();
//write $output in HTML file
}
//...
}
I get this info in the system.log file:
2012-09-06T09:44:46+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\ adminhtml\default\default \template\mymodule\test.phtml
2012-09-06T09:44:46+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\adminhtml\default\default\template\mymodule\test.phtml
2012-09-06T09:44:46+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\adminhtml\default\default\template\mymodule\test.phtml
2012-09-06T09:44:46+00:00 CRIT (2): Not valid template
file:adminhtml\base\default\template\mymodule\test.phtml
2012-09-06T09:44:47+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\adminhtml\default\default\layout\local.xml
2012-09-06T09:44:47+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\adminhtml\default\default\layout\local.xml
2012-09-06T09:44:47+00:00 DEBUG (7):
E:\webserver\xampp\htdocs\magento\app\design\adminhtml\default\default\layout\local.xml
It seems that Magento doesn't care what theme is currently enabled and searches for the template in base theme. Is there any way to "tell" Magento which template should be used?
You've already have the answer, you've just misidentified the problem.
Magento only looks in the base package once it's looked for a file in the current theme. So first Magento will check
frontend/package/theme/template/test.phtml
THEN it will check
frontend/base/default/template/test.phtml
and if it still doesn't find anything, then it logs the error.
If you want to debug where Magento is trying to load the initial file from, add some temporary var_dump or Mage::Log debugging code to the design package file
#File: app/code/core/Mage/Core/Model/Design/Package.php
public function validateFile($file, array $params)
{
$fileName = $this->_renderFilename($file, $params);
$testFile = (empty($params['_relative']) ? '' : Mage::getBaseDir('design') . DS) . $fileName;
if (!file_exists($testFile)) {
var_dump($testFile);
Mage::Log($testFile);
return false;
}
return $fileName;
}
Also, include the actual code you're using on your system here and people will be better able to help you. There's a discrepancy between what you say you're setting your template path as
helloworld/test.phtml
and what you're actually setting is as (per the Magento errors)
test.phtml
Update: Based on what's in the additional logging, it looks like something is adding spaces to your template path, which means Magento can't find your template in it's initial location
E:\webserver\xampp\htdocs\magento\app\design\ frontend\default\default \template\mymodule\test.phtml
ex.
design\ frontend
\default \template
Also, I don't think it's the root cause, but don't use DS in template paths. PHP will take care of that fore you.

Codeigniter + Dwoo

I got problem when implementing my CMS using Codeigniter 1.7.2 and Dwoo. I use Phil Sturgeon Dwoo library. My problem is I want user create template from the admin panel, it means all template will be stored into database including all Dwoo variable and functions.My questions:
Is it possible to load dwoo template from database?
How to parse dwoo variable or function from database? I tried to load content from database which is include dwoo var and function inside it, and i have tried to do evaluation using dwoo eval() function and phil sturgeon string_parse() but still have no luck.
for example:
my controller
$data['header'] = "<h1>{$header}</h1>"; --> this could be loaded from database
$this->parser->parse('header',$data);
my view
{$header}
This is the error message:
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Undefined index: header_title</p>
<p>Filename: compiled/805659ab5e619e094cac7deb9c8cbfb5.d17.php</p>
<p>Line Number: 11</p>
header_title is dwoo variable that loaded from DB.
Thank you,
It is definitely possible to do this, but for performance reasons it would probably be faster to store the templates as files on the filesystem, even if they're edited by users. If you're smart with file naming you can avoid most hits to the database.
Anyway, if you really want to do it with the database, the following should work:
// rendering the header
$template = '<h1>{$header}</h1>'; // loaded from db, don't use double-quotes for examples or $header will be replaced by nothing
$data = array('header' => 'Hello'); // loaded from db as well I assume
$headerOutput = $this->parser->parse_string($template, $data, true); // true makes it return the output
// now rendering the full page (if needed?)
$data = array('header' => $headerOutput);
$this->parser->parse('header', $data); // no 'true', so goes straight to output
The view would then contain {$header} and the output from the header template is passed to that variable.
Now I'm not sure how CI works so it might be better to just output the result of the first template and skip the second one entirely, but I'll leave that up to you.

Why is php_template_preprocess_page function not called in Drupal 6x?

From another forum I found the following example:
"I was looking for a way to pull node data via ajax and came up with the following solution for Drupal 6. After implementing the changes below, if you add ajax=1 in the URL (e.g. mysite.com/node/1?ajax=1), you'll get just the content and no page layout.
in the template.php file for your theme:
function phptemplate_preprocess_page(&$vars) {
if ( isset($_GET['ajax']) && $_GET['ajax'] == 1 ) {
$vars['template_file'] = 'page-ajax';
}
}
then create page-ajax.tpl.php in your theme directory with this content:
<?php print $content; ?>
"
This seems like the logical way to do it and I did this, but the phptemplate_preprocess_page function is never called ... any suggestions?
I figured it out for myself from a Drupal Support Theme Development page:
"Maybe this helps
leahcim.2707 - May 29, 2008 - 05:40
I was trying to get the same thing done and for me this works, but I'm not sure if it is the correct way as I'm still new to Drupal:
in "template.php" I added the following function:
function phptemplate_preprocess_page(&$vars)
{
$css = $vars['css'];
unset($css['all']['module']['modules/system/system.css']);
unset($css['all']['module']['modules/system/defaults.css']);
$vars['styles'] = drupal_get_css($css);
}
I think after adding the function you need to go to /admin/build/themes so that Drupal recognises the function."
The part in bold is what did the trick ... you have to re-save the configuration so it recognizes that you've added a new function to the template.

Go for Zend framework or Django for a modular web application?

I am using both Zend framework and Django, and they both have they strengths and weakness, but they are both good framworks in their own way.
I do want to create a highly modular web application, like this example:
modules:
Admin
cms
articles
sections
...
...
...
I also want all modules to be self contained with all confid and template files.
I have been looking into a way to solve this is zend the last days, but adding one omer level to the module setup doesn't feel right. I am sure this could be done, but should I? I have also included Doctrine to my zend application that could give me even more problems in my module setup!
When we are talking about Django this is easy to implement (Easy as in concept, not in implementation time or whatever) and a great way to create web apps. But one of the downsides of Django is the web hosing part. There are some web hosts offering Django support, but not that many..
So then I guess the question is what have the most value; rapid modular development versus hosting options!
Well, comments are welcome!
Thanks
You can implement sub-modules with relatively little effort in ZF. Let's say you have directory structure such as:
application/
modules/
admin/
cms/
controllers/
views/
controllers/
views/
You'd register the modules like this in your bootstrap (sub-modules use _ to separate the sub-module from the main module):
$frontController->setControllerDirectory(array(
'default' => APPLICATION_PATH . '/modules/default/controllers',
'admin' => APPLICATION_PATH . '/modules/admin/controllers',
'admin_cms' => APPLICATION_PATH . '/modules/admin/cms/controllers'
));
The issue with this is that it would actually use an underline in the URL instead of a slash, so eg: "admin_cms/conteroller/action" instead of "admin/cms/controller/action". While this "works", it's not pretty. One way to solve the issue is to provide your own route for the default route. Since the default Zend_Controller_Router_Route_Module does it almost right, you can simply extend from it and add the wanted behavior:
<?php
class App_Router_Route_Module extends Zend_Controller_Router_Route_Module
{
public function __construct()
{
$frontController = Zend_Controller_Front::getInstance();
$dispatcher = $frontController->getDispatcher();
$request = $frontController->getRequest();
parent::__construct(array(), $dispatcher, $request);
}
public function match($path)
{
// Get front controller instance
$frontController = Zend_Controller_Front::getInstance();
// Parse path parts
$parts = explode('/', $path);
// Get all registered modules
$modules = $frontController->getControllerDirectory();
// Check if we're in default module
if (count($parts) == 0 || !isset($modules[$parts[0]]))
array_unshift($parts, $frontController->getDefaultModule());
// Module name
$module = $parts[0];
// While there are more parts to parse
while (isset($parts[1])) {
// Construct new module name
$module .= '_' . $parts[1];
// If module doesn't exist, stop processing
if (!isset($modules[$module]))
break;
// Replace the parts with the new module name
array_splice($parts, 0, 2, $module);
}
// Put path back together
$path = implode('/', $parts);
// Let Zend's module router deal with the rest
return parent::match($path);
}
}
And in your bootstrap:
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addRoute('default', new App_Router_Route_Module);
What this does is traverse the path as long as it finds a module, and transparently rewrites the path so that the default Zend_Controller_Router_Route_Module can do the real work. For example the following path: "/admin/cms/article/edit" will be transformed into "/admin_cms/article/edit", which allows the standard convention of the ZF's ":module/:controller/:action" do the magic.
This allows you to have nice modular structure with self-contained modules, while still use pretty, logical URLs. One thing you want to make note of is that if you use Zend_Navigation and specify the navigation items using module/controller/action parameters, you need to tell ZF how to correctly build the URL using "/" instead of "_" in module names (by default ZF uses the :module/:controller/:action spec when it builds the URLs). You can do this by implementing your own Zend_Controller_Action_Helper_Url, like this:
<?php
class App_Router_Helper_Url extends Zend_Controller_Action_Helper_Url
{
public function url($urlOptions = array(), $name = null, $reset = false, $encode = false)
{
// Replace the _ with / in the module name
$urlOptions['module'] = str_replace('_', '/', $urlOptions['module']);
// Let the router do rest of the work
return $this->getFrontController()->getRouter()->assemble($urlOptions, $name, $reset, $encode);
}
}
And in your bootstrap:
Zend_Controller_Action_HelperBroker::addHelper(new App_Router_Helper_Url);
Now Zend_Navigation works nicely with your sub-module support as well.
I (despite of being happy ZF user) would go for Django. In ZF the "fully-modular" application is kind of holly grail. It's nearly impossible (or at least without extreme effort) to create selfcontained modules, instalable like "copy this folder into your modules directory" :) Not sure about Django, but from what I head it's simplier there...