Bootstrapping an extension with Typoscript and calling a specific action - typo3

I have build an extension which I am bootstrapping with Typoscript and placing it in a modal box. I also have the same extension included in a Page element but with a different action.
The problem is when calling other actions from the extension in the Page it also reflects what is displayed in the bootstrapped version in the modal box. What I want to do is no matter what arguments are in the URL (which tell the extension what action to execute) the one in the modal box to always call the same action first.
Is this possible?
Should I probably look for a different solution to my problem?

The easiest way in my opinion would be an AbstractContoller from which two different controller inherit.
This way the would be separated completely but could share the same actions:
namespace YOUR\Extension\Controller;
abstract class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController{
public function firstAction(){
// your code here
}
public function secondAction(){
// your code here
}
}
First Controller:
namespace YOUR\Extension\Controller;
class FirstController extends AbstractController{
//no need to add actions here
}
Second Controller:
namespace YOUR\Extension\Controller;
class SecondController extends AbstractController{
//no need to add actions here
}
Your typoscript included on the page would then call FirstController->firstAction, the one in the modal would call SecondController->firstAction. If you transfer a different action via GET, it will only affect either the first or the second Controller.
Don't forget:
register the controller/actions in your ext_localconf.php
copy / move the templates accordingly (they need to be in the folders named after the controller, e.g. templates/first/)

Do you call both of your Controller/Action sets in one Plugin?
I would try to split them fe like this
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'VENDOR.' . $_EXTKEY,
'Pluginkey1',
array(
'FirstController' => 'foo, bar',
),
// non-cacheable actions
array(
'FirstController' => '',
)
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'VENDOR.' . $_EXTKEY,
'Pluginkey2',
array(
'SecondController' => 'baz',
),
// non-cacheable actions
array(
'SecondController' => '',
)
);

Related

How to add condition for a field in the layout of SuiteCRM.?

In that in studio I have created some fields in one module and i also add those fields in Layout. but i want to display the fields according to the selection, for example: if user select option-1 from dropdown field then it has to display say only three field, and if user select option-2 from dropdown field then it has to display say six fields. so i need to add some condition in the layout field. but i can't find any option there.. please help me to find out.
i also attached the example image below.
If you are using sugar 7.6 I can help,
You want to change the fields according to drop down values if i am not wrong .
For that you have to right a code in "record.js" and "create-actions.js" files . just write a js function.
This is an example for crerate-action.js
({
extendsFrom: 'CreateActionsView',
initialize: function (options) {
this.model.on("change:dropdown", this.renderFields, this);
},
renderFields: function () {
// write your code here
},
})
You need to modify the view definitions to add a script into the edit view of your module.
Example:
$viewdefs ['<Module Name>'] =
array(
'<View Name>View' =>
array(
'templateMeta' =>
array(
...
'includes' =>
array(
0 =>
array(
'file' => 'path/to/your/script.js',
),
1 =>
array(
'file' => 'path/to/your/script.js',
),
),
...
),
...
),
...
);
You then can use jQuery or any javascript library to hide or show the fields. if you are using SuiteR or SuiteP theme you can simply add/remove the hidden class to the elements.
Just make sure that you add all the fields into your view which you wish to show or hide.
To make this upgrade save modify or create
custom/modules/module name/metadata/editviewdefs.php for the edit view
custom/modules/module name/metadata/detailviewdefs.php for the detail view
There are many defined ways in sugarcrm, as you have created new fields, all you need to add dependencies on those fields like
$dictionary['YOUR_MODULE_NAME']['fields']['YOUR_FIELD_NAME']['dependency']='(equal($YOUR_DROPDOWN,"OPTION_1"))
see
http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Architecture/Sugar_Logic/Dependency_Actions/SetVisibility/#Visibility_Dependencies_in_Field_Definitions
This can also be added through Studio.
Go to Studio > module > fields > YOUR_FIELD > Dependent and add dependency.

How to disable layout and view renderer in ZF2?

How can i disable layout and view renderer in Zend Framework 2.x? I read documentation and can't get any answers looking in google i found answer to Zend 1.x and it's
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout->disableLayout();
But it's not working any more in Zend Framework 2.x. I need to disable both view renderer and layout for Ajax requests.
Any help would be great.
Just use setTerminal(true) in your controller to disable layout.
This behaviour documented here: Zend View Quick Start :: Dealing With Layouts
Example:
<?php
namespace YourApp\Controller;
use Zend\View\Model\ViewModel;
class FooController extends AbstractActionController
{
public function fooAction()
{
$viewModel = new ViewModel();
$viewModel->setVariables(array('key' => 'value'))
->setTerminal(true);
return $viewModel;
}
}
If you want to send JSON response instead of rendering a .phtml file, try to use JsonRenderer:
Add this line to the top of the class:
use Zend\View\Model\JsonModel;
and here an action example which returns JSON:
public function jsonAction()
{
$data = ['Foo' => 'Bar', 'Baz' => 'Test'];
return new JsonModel($data);
}
EDIT:
Don't forget to add ViewJsonStrategy to your module.config.php file to allow controllers to return JSON. Thanks #Remi!
'view_manager' => [
'strategies' => [
'ViewJsonStrategy'
],
],
You can add this to the end of your action:
return $this->getResponse();
Slightly more info on the above answer... I use this often when outputting different types of files dynamically: json, xml, pdf, etc... This is the example of outputting an XML file.
// In the controller
$r = $this->getResponse();
$r->setContent(file_get_contents($filePath)); //
$r->getHeaders()->addHeaders(
array('Content-Type'=>'application/xml; charset=utf-8'));
return $r;
The view is not rendered, and only the specified content and headers are sent.

Zend Framework 2 Translating the text of the radio buttons

I´m developing an application using Zend Framework 2 and I need to translate the text of the radio buttons ("Show", "Hide") that I´ve created in my form:
//within the Form
public function addRadioButtons ()
{
$isPublicRadioButtons = new Element\Radio('isPublic');
$isPublicRadioButtons->setAttribute('id', 'isPublic')
->setAttribute('value', '0')
->setValueOptions(array(
'0' => 'Show',
'1' => 'Hide',
));
$this->add($isPublicRadioButtons);
}
What do I have to do in the view side to be able to translate them?
I know that to render translations to the views I need to use $this→translate() view helper. So within the view I´ll have to somehow call the text of the radio buttons..
//Whithin the view
echo $this->translate($someHowCallTheTextOfRadioButton('isPublic') , $textDomain, $locale);
Look at FormLabel section to read about translating labels in zend framework 2. I think that most important thing to remember is:
If you have a translator in the Service Manager under the key,
‘translator’, the view helper plugin manager will automatically attach
the translator to the FormLabel view helper. See
Zend\View\HelperPluginManager::injectTranslator() for more
information.
How to properly setup translator you have in ZendSkeletonApplication
In your view you can do something like this:
$this->formRadio()->setTranslatorTextDomain('textdomainhere');
You can have your form implement the TranslatorAwareInterface and, if you are using PHP 5.4+, have it use the TranslatorAwareTrait (otherwise you simply have to implement the interface yourself). You can now inject a translator instance into your form, e.g. in the form's factory. Then you can translate the labels as follows:
//within the Form
public function addRadioButtons ()
{
$isPublicRadioButtons = new Element\Radio('isPublic');
$isPublicRadioButtons->setAttribute('id', 'isPublic')
->setAttribute('value', '0')
->setValueOptions(array(
'0' => $this->getTranslator()->translate('Show'),
'1' => $this->getTranslator()->translate('Hide'),
));
$this->add($isPublicRadioButtons);
}

How do i assign a custom helper to each view differently in zend framework

i have a custom helper written which returns the html form as string which extends the Zend_view-hepler_Abstract
Now i have 3 helpers .How do i assign each helper to a different view .
It is something like this in the controller
class abc extends Zend_controller_front{
public action page1Action (){
// I want to use a different Helper
//How do i assign custom1 helper to this view Separately
}
public action page2Action (){
// I want to use a different Helper
//How do i assign custom2 helper to this view Separately
}
public action page3Action (){
// I want to use a different Helper
//How do i assign custom3 helper to this view Separately
}
}
um, should you be inheriting from Zend_Controller_Action not Zend_Controller_Front?
also the word 'action' is not a valid php keyword?
just use the view helper in your view script, so in abc/page1.phtml
print $this->page1Helper()
similarly for page2 and page3
but there may be an easier way... you can just
print $this->form;
and the form will print without the need for a helper?

Zend_Navigation: Having trouble getting breadcrumbs to render using multiple containers [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Zend Framework - multiplate navigation blocks
I'm trying to make breadcrumbs render in my application ( they don't show up anywhere, not even the homepage, which has a corresponding Zend Page Uri object ), which has multiple navigation areas - primary and utility. For the menu generation, I have a MenuController which I render with from within the layout using:
$this->layout()->utility = $this->action('render', 'menu', null, array('menu' => $this->utilityId));
$this->layout()->nav = $this->action('render', 'menu', null, array('menu' => $this->mainMenuId));
The utilityId and mainMenuId properties are numbers, grabbed from a database.
The Menu controller's render method just builds an array and creates a Zend Navigation object, then invokes setContainer and sets it to that container. This is pseudo code because it's rather long:
// MenuController.php
private function renderAction() {
$itemArray[] = array('label' => $label, 'uri' => $uri ); // in a loop
$container = new Zend_Navigation($itemArray);
if ( $container instanceof Zend_Navigation_Container ) {
$this->view->navigation()->setContainer( $container );
$uri = $this->_request->getPathInfo();
$item = $this->view->navigation()->findByUri($uri);
$item->active = true;
}
}
So this render method is called twice from within the layout for the utility and nav.
EDIT:
I think the issue is that I need to specify the $container so my code would be
$this->navigation($container)->breadcrumbs();
However because I'm using $this->action('render', 'menu' ) the $container variable is set there and not returned, is there a way I can specify the container some other way? Possibly using $this->layout()->nav and a property in that which points to the container.
This looks like it's the same issue and someone suggests setting/getting them with Zend_Registry, perhaps I'll try this out.
I suspect you don't have a navigational hierarchy. You need pages within pages.
e.g.
Home Page
[pages] => Sign In
[pages] => Forgot Password
=> Create Account
[pages] => Confirm Account Email
=> Email Confirmed
With the above, breadcrumbs will be rendered on all active pages except for the Home Page... all pages if you do this:
$this->navigation()->breadcrumbs()->setMinDepth(0); // don't skip the root page
Or maybe it's something else, but it's hard to say. I hope that helps, though!
This is probably a dirty solution, but I manually set the container reference using Zend_Registry like so:
Zend_Registry::set( 'nav' . $menu, $container );
And spit it out like so:
$main = Zend_Registry::get( 'nav' . $this->mainMenuId );
echo $this->navigation( $main )->breadcrumbs()->setMinDepth(0);