Remove action in an existing plugin class via another plugin - plugins

I am trying to remove an action within an existing WooThemes Sensei Class
global $woothemes_sensei;
remove_action( 'sensei_single_course_modules_before', array( $woothemes_sensei->modules, 'course_modules_title' ),20 );
remove_action( 'sensei_single_course_modules_content', array( $woothemes_sensei->modules, 'course_module_content' ),30 );
I am not sure what I am doing wrong? I think I am calling the correct class with the global variable. And the labels are correct? I've tried various priorities.
Thank you!

You must wrap the remove functions in a function and attach it to a hook, before the action in question has been run.
$this has no context here. it only has context inside a class
remove_action must have the exact same priority as the add_action that you are trying to remove
The course-modules.php template says exactly how the course_modules_title action is being added
/**
* Hook runs inside single-course/course-modules.php
*
* It runs before the modules are shown. This hook fires on the single course page,but only if the course has modules.
*
* #since 1.8.0
*
* #hooked Sensei()->modules->course_modules_title - 20
*/
do_action('sensei_single_course_modules_before');
Sensei does not appear to be using a global and the modules class is accessed via Sensei()->modules as hinted at in the template. Therefore something like the following should remove your actions:
function so_31590319_remove_sensei_actions(){
remove_action('sensei_single_course_modules_before',array( Sensei()->modules,'course_modules_title' ), 20);
remove_action('sensei_single_course_modules_content', array( Sensei()->modules,'course_module_content' ), 20);
}
add_action( 'sensei_single_course_modules_before', 'so_31590319_remove_sensei_actions', 10 );

Related

How do I set default alignment for horizontal controls in Bootstrap-UI 3 for CakePHP 4?

This is a particularly obscure question about the Boostrap-UI plugin for CakePHP but I'm hoping someone might be able to help.
I’m using Bootstrap-UI (https://github.com/FriendsOfCake/bootstrap-ui) version 3.0, so using Bootstrap 4.6.
I’m trying to create a form that has controls that are aligned horizontally with their labels using the example from the readme here -
This works fine except I can’t see how to define the default column distribution ie so that the classes for the label and the control container are something like col-4 and col-8 without any breakpoint defined.
If I try something like -
'align' => [
'left' => 4,
'middle' => 8,
]
The classes created are col-md-4 and col-md-8 ie it seems to default to md as the breakpoint for the columns.
I know this is a bit obscure but does anyone have any idea how to do what I want?
AFAICT that's currently not supported, meaning you can only generate the default mb breakpoint ones, or specify breakpoints yourself.
You can open an issue over at GitHub for a feature request. As a workaround you could extend the plugin'S form helper and overwrite FormHelper::_gridClass() to modify the generated classlist, something along the lines of this, which would remove the default breakpoint from the generated class string:
namespace App\View\Helper;
class FormHelper extends \BootstrapUI\View\Helper\FormHelper
{
protected function _gridClass(string $position, bool $offset = false): string
{
return str_replace('-md', '', parent::_gridClass($position, $offset));
}
}
public function initialize(): void
{
parent::initialize();
$this->initializeUI();
$this->helpers['Form'] = [
'className' => \App\View\Helper\FormHelper::class
];
}
See also https://book.cakephp.org/4/en/views/helpers.html#creating-helpers

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.

Bootstrapping an extension with Typoscript and calling a specific action

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' => '',
)
);

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);

How to put 2 buttons in a row in one Zend_Form

I assume it's a common requirement to have forms in your web apps that have
Edit Delete
buttons under them. But ZF puts one button under another, which is counter-intuitive.
I guess ViewScript decorator could help me completely override button html.
But how to do it across other forms, to avoid duplicating?
May be I am overcomplicating and I just should somehow paste html code instead of button element objects?
This is the code I use in my own Form class that all my forms inherit from. The main trick is to only use the ViewHelper Decorator on the button itself, and stick the buttons in a displaygroup that uses a DtDdWrapper and wraps the buttons in a <div class='buttons'> for extra styling options
protected $_buttons = array();
/**
* Sets a list of buttons - Buttons will be standard submits, or in the getJson() version
* they are removed from display - but stuck in the json in the .buttons property
*
* $buttons = array('save'=>'Save This Thing', 'cancel'=>'Cancel') as an example
*
* #param array $buttons
* #return void
* #author Corey Frang
*/
public function setButtons($buttons)
{
$this->_buttons = $buttons;
foreach ($buttons as $name => $label)
{
$this->addElement('submit', $name, array(
'label'=>$label,
'class'=>$name,
'decorators'=>array('ViewHelper'),
));
}
$this->addDisplayGroup(array_keys($this->_buttons),'buttons', array(
'decorators'=>array(
'FormElements',
array('HtmlTag', array('tag'=>'div', 'class'=>'buttons')),
'DtDdWrapper'
)
));
}
// Example from form::init()
$this->setButtons(array('save'=>'Save Entry', 'delete'=>'Delete Entry'));
Have a read through this tutorial on Zend Developer Zone:
Decorators-with-Zend_Form.
Button decorators can be modified in Form's constructor.
Buttons should be left without HtmlTag decorator to disable being on separate lines due to dt/dd tags, HtmlTag decorator can be remove like this:
$buttonobject->setDecorators(array(
'ViewHelper',
//array('HtmlTag', array('tag' => 'dd')),
//array('Label', array('tag' => 'dt')),
));
Comments are for demonstration purposes only.
Additionally, buttons may be grouped into a fieldset, for styling purposes:
$this->addDisplayGroup(array('delete','submit'),'buttons');
Optional site.css code:
#fieldset-buttons { border: none; }