Hi I have created a custom button link in the admin section of my component, something like this:
$bar = & JToolBar::getInstance('toolbar');
$bar->appendButton( 'Link', 'export', 'Export', 'index.php?option=com_component&task=export&format=raw' );
However no image is assigned to it and I don't know how to assign one to the button. Does anyone know how I can do this?
You need to create CSS class called icon-32-export with image background.
Here is an example:
<?php
// Add CSS class to the document, it's better to have it in external CSS document
$imgPath = JRoute::_('/administrator/templates/khepri/images/toolbar/icon-32-new.png');
JFactory::getDocument()->addStyleDeclaration(".icon-32-export { background: url($imgPath); }");
//
$bar = & JToolBar::getInstance('toolbar');
$url = JRoute::_('index.php?option=com_component&task=export&format=raw');
$bar->appendButton( 'Link', 'export', 'Export', $url);
?>
Related
I'm trying to fill a rich text editor field (TinyMCE) within my acceptance test in Codeception.
Using the fillField() function doesn't work as this 'field' isn't really an input field. It's an iframe, styled to look like a fancy textarea.
How can I set some text into the body of the TinyMCE box? I think I'm looking for the addition of a $I->setContent(xpathOrCSS) function. Or does something else already exist to do this?
It is best to do this by adding re-usable actions to your Actor class (AcceptanceTester, by default). You can then use the actions in your tests to set the content of rich text editor fields without reducing the readability of your tests. More details on this are available in the Codeception documentation.
I have included solutions for TinyMCE and CKEditor below. The solution uses the executeInSelenium() call to give us access to Facebook's underlying WebDriver bindings. From there, we simply use the frame switching/Javascript injection technique described here to set the content of our target editor.
Note that the final call to $webDriver->switchTo()->defaultContent() is very important - this switches WebDriver's focus back from the RTE iframe to the page that contains it.
Actor functions:
<?php
class AcceptanceTester extends \Codeception\Actor {
use _generated\AcceptanceTesterActions;
public function fillCkEditorById($element_id, $content) {
$this->fillRteEditor(
\Facebook\WebDriver\WebDriverBy::cssSelector(
'#cke_' . $element_id . ' .cke_wysiwyg_frame'
),
$content
);
}
public function fillCkEditorByName($element_name, $content) {
$this->fillRteEditor(
\Facebook\WebDriver\WebDriverBy::cssSelector(
'textarea[name="' . $element_name . '"] + .cke .cke_wysiwyg_frame'
),
$content
);
}
public function fillTinyMceEditorById($id, $content) {
$this->fillTinyMceEditor('id', $id, $content);
}
public function fillTinyMceEditorByName($name, $content) {
$this->fillTinyMceEditor('name', $name, $content);
}
private function fillTinyMceEditor($attribute, $value, $content) {
$this->fillRteEditor(
\Facebook\WebDriver\WebDriverBy::xpath(
'//textarea[#' . $attribute . '=\'' . $value . '\']/../div[contains(#class, \'mce-tinymce\')]//iframe'
),
$content
);
}
private function fillRteEditor($selector, $content) {
$this->executeInSelenium(
function (\Facebook\WebDriver\Remote\RemoteWebDriver $webDriver)
use ($selector, $content) {
$webDriver->switchTo()->frame(
$webDriver->findElement($selector)
);
$webDriver->executeScript(
'arguments[0].innerHTML = "' . addslashes($content) . '"',
[$webDriver->findElement(\Facebook\WebDriver\WebDriverBy::tagName('body'))]
);
$webDriver->switchTo()->defaultContent();
});
}
}
Example Usage:
$content = '<h1>Hello, world!</h1>';
// CKEditor
$I->fillCkEditorByName('rich_content', $content);
$I->fillCkEditorById('my_ckeditor_textarea', $content);
// TinyMCE
$I->fillTinyMceEditorByName('rich_content', $content);
$I->fillTinyMceEditorById('my_tinymce_textarea', $content);
In all cases, the first parameter refers to the name/id attribute of the original textarea element, and the second parameter is the HTML content to fill it with.
Best way:
$I->executeJS('$("#selector").val("Value")');
If you have a simple setup and only need to test one instance in tinyMCE 4, this worked for me.
$I->executeJS('tinyMCE.activeEditor.setContent(" your content goes here ");');
IF you have and iframe like this:
<iframe id="myFrameID" allowtransparency="true"></iframe>
notice, that Codeception switches to the iframe using
$I->switchToIFrame("myFrameID");
Keep in mind, to omit the # in front of "myFrameID", as switch to iframe does not use a css selector but rather just the name of the iframe.
Then do
$I->executeJS('document.getElementById("tinymce").innerHTML = "<p>Some Text Here!</p>";');
and don't forget to switch back to previous window:
$I->switchToIFrame();
as stated in
https://codeception.com/docs/modules/WebDriver#switchToIFrame
Tried and following solution works:
$I->switchToIFrame('#frameName');
$I->executeJS('document.getElementById("tinymce").innerHTML = "<p>Test abc def</p>";');
try this
$x = $I->grabAttributeFrom('//iframe', 'id');
$I->switchToIframe($x);
$I->fillField('//*[#id="tinymce"]', '<p>Test abc</p>');
I am trying to add a button to the product edit page in the Magento admin. I know there are lots of tutorials out there (which I have used for reference) but I am trying to figure this out myself (with the help of SO of course ;) )
I have overridden the Product_Edit block like so (other module files omitted for clarity):
<?php
class Sulman_Addviewbutton_Adminhtml_Block_Catalog_Product_Edit extends Mage_Adminhtml_Block_Catalog_Product_Edit
{
protected function _prepareLayout(){
parent::_prepareLayout();
$this->setChild('sulman_test',
$this->getLayout()->createBlock('adminhtml/widget_button')
->setData(array(
'label' => Mage::helper('catalog')->__('Sulman Test'),
'onclick' => 'setLocation(\''
. $this->getUrl('*/*/', array('store'=>$this->getRequest()->getParam('store', 0))).'\')', // just copied the back button for now until I get it working
'class' => 'back'
))
);
return $this;
}
}
This appears to be correctly extending the Product_Edit class because if I comment out parent::_prepareLayout(); none of the buttons render.
I'm just not sure why the button isn't showing.
Thanks
The product edit form is rendered by the template catalog/product/edit.phtml.
You need to add some code in there also to make the button appear somewhere between the rest of the buttons.
<?php echo $this->getChildHtml('sulman_test')?>
In my component view, I can show a module by this code:
$module = JModuleHelper::getModule('mod_login');
$html = JModuleHelper::renderModule($module);
echo $html;
or
echo JHtml::_('content.prepare', '{loadmodule login}');
But that will usually place the module in the middle of the screen in the main-content div.
How can I place the module in the position defined in the module params?
Take a look at how the admin template Isis renders the quickicons module on the home page or at how the error page in protostar renders the search modules.
$this->searchmodules = JModuleHelper::getModules('position-0');
foreach ($this->searchmodules as $searchmodule)
{
$output = JModuleHelper::renderModule($searchmodule, array('style' => 'none'));
$params = new JRegistry;
$params->loadString($searchmodule->params);
echo $output;
}
You just want one module, but you get the basic idea.
Try This.
You can Pass the module parameters too.
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$Module = &JModuleHelper::getModule('mod_fmDataGrid');
$Params = "param1=bruno\n\rparam2=chris";
$Module->params = $Params;
echo $renderer->render($Module);
This may help you..
You can't, jdoc includes in the template are processed after the component has finished producing its output.
Why not let Joomla render the modules in the right positions? that should be one of the reasons for using it, i.e. taking care of placement and order of modules.
If you have other reasons for doing this, please explain further.
One of my application devoloped with Codeignitor and create a barcode using Zend_Barcode library,
reference : http://www.beyondcoding.com/2008/02/21/using-zend-framework-with-codeigniter/
How can I show the barcode on codeignitor view.
Tried as ,
// Only the text to draw is required
$barcodeOptions = array('text' => 'NOT-ME');
// No required options
$rendererOptions = array();
// Draw the barcode in a new image,
$imageResource = Zend_Barcode::draw(
'code39', 'image', $barcodeOptions, $rendererOptions
);
$data['barcode'] = imagejpeg($imageResource, 'barcode.jpg', 100);
// Free up memory
imagedestroy($imageResource);
in view
<img src="<?php echo $barcode;?>">
but its fails :(
Instead of
Zend_Barcode::draw('code39', 'image', $barcodeOptions, $rendererOptions);
Use
Zend_Barcode::render('code39', 'image', $barcodeOptions, $rendererOptions);
We are building joomla component. And we use joomla editor in which we insert content.
But there is a problem, because when we add image to editor and save it, it do not add image to database and when we opening this element to edit it again, there is only text in editor, image disappears.
This is how we use it:
$editor =& JFactory::getEditor();
echo $editor->display('text', $this->hello->text, '800', '300', '20', '20');
Maybe there is need to supply aditional parameters to display method?
Problem solved.
The standard way of getting the form data $post = JRequest::get('post'); is not enough in the case of using a editor. This will filter the content, hence losing line breaks and paragraps. So we need to add an extra line to get the editor contents in a raw unfiltered way. This data will be passed to the model to save into the database.
To get HTML form post data you need to get this data in following way
$data = JRequest::getVar( 'editorName', 'defaultValue', 'post', 'string', JREQUEST_ALLOWRAW );
And need to add a javascript for the view(tmpl file)
function submitbutton(action) {
var form = document.adminForm;
switch(action)
{
case 'save':case 'apply':
<?php
$editor =& JFactory::getEditor();
echo $editor->save( 'editorName' );
?>
case 'publish':
case 'unpublish':
case 'cancel':
default:
submitform( action );
}
}