Adding custom extjs module in TYPO3 backend - typo3

I'm currently trying to create a node resolver for a TCA column. I've added a resolver and an element. The render function in the element class looks like this
public function render()
{
$resultArray = $this->initializeResultArray();
$resultArray['requireJsModules'][] = 'MyVendor/MyExtension/MyModule';
$resultArray['html'] = 'Hallo Welt';
return $resultArray;
}
The extjs modules is placed in typo3conf/ext/my_extension/Resources/Public/JavaScript/MyModule.js
When TYPO3 renders my element, it renders the html part and tries to load the extjs module with the path typo3/MyVendor/MyExtension/MyModule.js
My question now is, how can I add my custom extjs module, that is injected by require function in JavaScript?
I'm using TYPO3 7.6.15.
I'm thankful for every help :)

Just found the answer here https://forum.typo3.org/index.php/t/210780/
The module needs to have TYPO3/CMS as vendor. Than it load loaded correctly.
public function render()
{
$resultArray = $this->initializeResultArray();
$resultArray['requireJsModules'][] = 'TYPO3/CMS/MyExtension/MyModule';
$resultArray['html'] = 'Hallo Welt';
return $resultArray;
}
The module needs to be in typo3conf/ext/my_extension/Resources/Public/JavaScript/MyModule.js

Related

Create CSS classes based on user role

Working with Moodle 3.9 and a fork of the current Academi theme.
I am trying to create a css class hook on the <body> element which is based on the user's role(s). I understand that a user's role(s) are context-driven, (maybe a student in one course, and something else in another), so I would output all the roles as classes for a given context.
Based on some extensive digging on the moodle forum I have the following:
// User role based CSS classes
global $USER, $PAGE;
$context = context_system::instance();
$roles = get_user_roles($context, $USER->id, true);
if(is_array($roles)) {
foreach($roles as $role) {
$PAGE->add_body_class('role-'.$role->shortname);
}
} else {
$PAGE->add_body_class('role-none');
}
Preferably I'd like this to run on every page. From within the theme, I've tried just placing this in just about every location/function I thought could be executed early enough to modify the body element. Either I get no output at all or a warning indicating that it is too late to run add_body_class().
I've had a skim of the Page and Output APIs and I still don't have a sense of how or when to execute this code. Should this be a custom plugin instead?
Override the header() function on the core renderer of your current theme template, for instance, on theme\YOUR_THEME\classes\output\core_renderer.php:
namespace theme_YOUR_THEME\output;
defined('MOODLE_INTERNAL') || die;
use context_system;
class core_renderer extends \theme_boost\output\core_renderer {
public function header() {
global $USER;
$roles = get_user_roles(context_system::instance(),$USER->id);
if (is_array($roles) && !empty($roles)){
foreach($roles as $role){
$this->page->add_body_class('role-'.$role->shortname);
}
}else{
$this->page->add_body_class('role-none');
}
return parent::header();
}
}
This way, every page would call this function and have the desired css classes added to the body tag.

How to integrate web services with custom module in SugarCRM?

I'm using SugarCRM to develop a software for customers management. I created a custom module from basic template with custom fields. Is it possible to get rid of SugarCRM db and perform CRUD operations through external web serivices? Actually I was able to show web services data in the datailview by setting the bean property of a custom controller.
class CustomerController extends SugarController{
public function action_detailview(){
$customer = new Customer();
$customer = getCustomerFromWebService();
$this->bean = $customer;
$this->view = "detail";
}
}
I would like to do the same thing with listview, but I don't know how set the records of the list (if it exists) used by the default listview.
You can change list view by customizing view.list.php in custom/modules/modulename/views/view.list.php using following code:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/MVC/View/views/view.list.php');
// name of class match module
class modulenameViewList extends ViewList{
// where clause that will be inserted in sql query
var $where = 'like 'htc'';
function modulenameViewList()
{
parent::ViewList();
}
/*
* Override listViewProcess with addition to where clause to exclude project templates
*/
function listViewProcess()
{
$this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
echo $this->lv->display();
}
}
?>

Customize Editview in Custom Safe Manner

Is there a way to customize module(Eg:Contacts) in an custom safe manner.
My requirement is too load one javascript in editview of Contacts module.
I have currently called the js in custom/modules/Contacts/views/view.edit.php and have created an addon for same.
But when I will upload the addon , if that file custom/modules/Contacts/views/view.edit.php already present will be overridden.
Is there an other way to do the same which do not removes customizations?
You can do the following:
<?php
require_once("modules/Contacts/views/view.edit.php");
class CustomContactsViewEdit extends ContactsViewEdit
{
public function __construct(){
parent::__construct();
}
public function display(){
parent::display();
//Load your javascript file here
}
}
OR You can include your javascript file on the editviewdefs metadata.
$viewdefs['Contacts']['EditView]['templateMeta']['includes][] = array(
'file' => 'custom/modules/Contacts/CustomJs.js',
);
Havent checked this code but it will surely work.

ZF2 layout form set input filters and validation

For my application in Zend Framework 2 I created a 'search form' in my layout.phtml.
I did this in my Application module by adding the search form as an variable.
(Form location Application/src/Application/Form/SearchForm.php)
Application/Module.php:
public function setFormToView($e)
{
$searchForm = new SearchForm();
$viewModel = $e->getViewModel();
$viewModel->setVariables(array(
'searchForm' => $searchForm,
));
}
The form directs to an Action in another module, here I want to handle what to do with
the incoming query.
MyModule/src/MyModule/Controller/MyModuleController.php
public function dataAction()
{
$form = new SearchForm();
$form->get('submit')->setValue('Add');
$website = $this->params()->fromQuery('search');
return array('searchForm', $form);
}
Getting the query 'search' is no problem, it works well. No I want to use my inputFilter I created under 'Application/src/Application/Model/Search.php'.
I tried to add this in my 'dataAction()' but no results, but I even can't change the submit value as I tried in my example above.
How do I set this in the right way in this situation? Or else, what is the right situation to handle a search form in layout.phtml.
Thanks in advance,
Nick

Zend Framework: Get whole out output in postDispath while using Layout

I have a layout loader plugin which looks like this:
class Controller_Action_Helper_LayoutLoader extends Zend_Controller_Action_Helper_Abstract
{
public function preDispatch()
{
$config = Zend_Registry::get("config");
$module = $this->getRequest()->getModuleName();
if (isset($config->$module->resources->layout->layout) && !$this->getRequest()->format)
{
$layoutScript = $config->$module->resources->layout->layout;
$this->getActionController()->getHelper('layout')->setLayout($layoutScript);
}
}
}
In a controller plugin I then want to get the whole of the response like so
$this->getResponse()->getBody()
This however only returns the output from the action, not the output from the layout too.
How can I get the whole output, layout and action together?
Thanks!
I believe that Zend_Layout operates at postDispatch() with a high stack index. So, to get the content, you might need to do your access later, at dispatchLoopShutdown().