本文整理汇总了PHP中Varien_Data_Form_Element_Abstract::setAfterElementHtml方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Data_Form_Element_Abstract::setAfterElementHtml方法的具体用法?PHP Varien_Data_Form_Element_Abstract::setAfterElementHtml怎么用?PHP Varien_Data_Form_Element_Abstract::setAfterElementHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Data_Form_Element_Abstract
的用法示例。
在下文中一共展示了Varien_Data_Form_Element_Abstract::setAfterElementHtml方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Render Media Chooser HTML (buttons and image preview) and set it after the form element HTML
*
* @param Varien_Data_Form_Element_Abstract $element
*
* @return Varien_Data_Form_Element_Abstract
*/
public function render(Varien_Data_Form_Element_Abstract $element)
{
if (Mage::getSingleton('admin/session')->isAllowed('cms/media_gallery')) {
$layout = Mage::app()->getLayout();
$id = $element->getHtmlId();
if ($url = $element->getValue()) {
$linkStyle = "display:inline;";
if (!preg_match("/^http\\:\\/\\/|https\\:\\/\\//", $url)) {
$url = Mage::getBaseUrl('media') . $url;
}
} else {
$linkStyle = "display:none;";
$url = "#";
}
$imagePreview = '<a id="' . $id . '_link" href="' . $url . '" style="text-decoration: none; ' . $linkStyle . '"' . ' onclick="imagePreview(\'' . $id . '_image\'); return false;">' . ' <img src="' . $url . '" id="' . $id . '_image" title="' . $element->getValue() . '"' . ' alt="' . $element->getValue() . '" height="30" class="small-image-preview v-middle"/>' . ' </a>';
$selectButtonId = 'add-image-' . mt_rand();
$chooserUrl = Mage::getUrl('adminhtml/cms_wysiwyg_images_chooser/index', array('target_element_id' => $id));
$label = $element->getValue() ? $this->__('Change Image') : $this->__('Select Image');
// Select/Change Image Button
$chooseButton = $layout->createBlock('adminhtml/widget_button')->setType('button')->setClass('add-image')->setId($selectButtonId)->setLabel($label)->setOnclick('MediabrowserUtility.openDialog(\'' . $chooserUrl . '\')')->setDisabled($element->getReadonly())->setStyle('display:inline;margin-top:7px');
// Remove Image Button
$onclickJs = '
document.getElementById(\'' . $id . '\').value=\'\';
if(document.getElementById(\'' . $id . '_image\')){
document.getElementById(\'' . $id . '_image\').parentNode.style.display = \'none\';
}
document.getElementById(\'' . $selectButtonId . '\').innerHTML=\'<span><span><span>' . addslashes($this->__('Select Image')) . '</span></span></span>\';
';
$removeButton = $layout->createBlock('adminhtml/widget_button')->setType('button')->setClass('delete')->setLabel($this->__('Remove Image'))->setOnclick($onclickJs)->setDisabled($element->getReadonly())->setStyle('margin-top:7px');
$wrapperStart = '<div id="buttons_' . $id . '" class="buttons-set" style=" width: 325px;">';
$wrapperEnd = '</div>';
$wrapperEnd .= '
<script type="text/javascript">
//<![CDATA[
varienGlobalEvents.clearEventHandlers(\'mediachooserChange' . $id . '\');
varienGlobalEvents.attachEventHandler(\'mediachooserChange' . $id . '\', function(url){
document.getElementById(\'' . $id . '_image\').src = \'' . Mage::getBaseUrl('media') . '\' + url;
document.getElementById(\'' . $id . '_image\').title = url;
document.getElementById(\'' . $id . '_image\').alt = url;
document.getElementById(\'' . $id . '_link\').href = \'' . Mage::getBaseUrl('media') . '\' + url;
document.getElementById(\'' . $id . '_link\').style.display = \'inline\';
document.getElementById(\'' . $selectButtonId . '\').innerHTML=\'<span><span><span>' . addslashes($this->__('Change Image')) . '</span></span></span>\';
});
//]]>
</script>
';
// Add our custom HTML after the form element
$element->setAfterElementHtml($wrapperStart . $imagePreview . $chooseButton->toHtml() . $removeButton->toHtml() . $wrapperEnd);
}
return $element;
}
示例2: renderMediaChooser
public function renderMediaChooser(Varien_Data_Form_Element_Abstract $element)
{
if (Mage::getSingleton('admin/session')->isAllowed('cms/media_gallery')) {
$layout = $element->getForm()->getParent()->getLayout();
$id = $element->getHtmlId();
if ($url = $element->getValue()) {
$linkStyle = "display:inline;";
if (!preg_match("/^http\\:\\/\\/|https\\:\\/\\//", $url)) {
$url = Mage::getBaseUrl('media') . $url;
}
} else {
$linkStyle = "display:none;";
$url = "#";
}
$hiddenField = '<input type="hidden" name="hidden_file" id="hidden_file_' . $id . '" class="hidden-file-path" value=""/>';
$imagePreview = '<a id="' . $id . '_link" class="image-preview-link" href="' . $url . '" style="text-decoration: none; ' . $linkStyle . '"' . ' onclick="imagePreview(\'' . $id . '_image\'); return false;">' . ' <img src="' . $url . '" id="' . $id . '_image" title="' . $element->getValue() . '"' . ' alt="' . $element->getValue() . '" height="30" class="small-image-preview v-middle"/>' . ' </a>';
$selectButtonId = 'add-image-' . mt_rand();
$chooserUrl = Mage::getUrl('adminhtml/cms_wysiwyg_images_chooser/index', array('target_element_id' => $id));
$label = $element->getValue() ? $this->__('Change Image') : $this->__('Select Image');
// Select/Change Image Button
$chooseButton = $layout->createBlock('adminhtml/widget_button')->setType('button')->setClass('add-image')->setId($selectButtonId)->setLabel($label)->setOnclick('openEfinder(this, \'hidden_file_' . $id . '\', \'#' . $id . '\', changeElFieldImage)')->setDisabled($element->getReadonly())->setStyle('display:inline;margin-top:7px');
// Remove Image Button
$onclickJs = '
document.getElementById(\'' . $id . '\').value=\'\';
document.getElementById(\'hidden_file_' . $id . '\').value=\'\';
if(document.getElementById(\'' . $id . '_image\')){
document.getElementById(\'' . $id . '_image\').parentNode.style.display = \'none\';
}
document.getElementById(\'' . $selectButtonId . '\').innerHTML=\'<span><span><span>' . addslashes($this->__('Select Image')) . '</span></span></span>\';
';
$removeButton = $layout->createBlock('adminhtml/widget_button')->setType('button')->setClass('delete')->setLabel($this->__('Remove Image'))->setOnclick($onclickJs)->setDisabled($element->getReadonly())->setStyle('margin-top:7px');
$wrapperStart = '<div id="buttons_' . $id . '" class="buttons-set" style=" width: 325px;">';
$wrapperEnd = '</div>';
// Add our custom HTML after the form element
$element->setAfterElementHtml($wrapperStart . $hiddenField . $imagePreview . $chooseButton->toHtml() . $removeButton->toHtml() . $wrapperEnd);
}
return $element;
}
示例3: _fixChooserAjaxUrl
/**
* Replaces part of the chooser ajax fetch url,
* because we hit 404 page when we have routers defined in the following way:
*
* <admin>
* <routers>
* <brands>
* <use>admin</use>
* <args>
* <module>MyCompany_MyModule</module>
* <frontName>myfrontname</frontName>
* </args>
* </brands>
* </routers>
* </admin>
*
* Basically we just replace "myfrontname" with the admin front name
*
* @param Varien_Data_Form_Element_Abstract $element
*/
protected function _fixChooserAjaxUrl($element)
{
$adminPath = (string) Mage::getConfig()->getNode(Mage_Adminhtml_Helper_Data::XML_PATH_ADMINHTML_ROUTER_FRONTNAME);
$currentRouterName = Mage::app()->getRequest()->getRouteName();
if ($adminPath != $currentRouterName) {
$afterElementHtml = $element->getAfterElementHtml();
$afterElementHtml = str_replace('/' . $currentRouterName . '/', '/' . $adminPath . '/', $afterElementHtml);
$element->setAfterElementHtml($afterElementHtml);
}
}