Hi there
we are using the EE-Version, 5.2.7 in our shops.
I’m trying to use the standard wysiwyg-editor for own custom fields.
What I did so far:
- Extended table oxartextends with 2 new fields ‘oxnutrient’ and ‘oxnutrient_1’
- Extended oxarticle modul with 3 new functions (same as for oxlongdesc)
- getNutritionText()
- setNutritionText()
- _saveArtNutrition()
I want to use the Editor in the article_extend classes
so I extended in article_extend
- render()
- save()
_getEditValue()
in render()
$this->_aViewData["editor"] = $this->_generateTextEditor("100%", 300, $oArticle, "oxarticles__oxnutrient", "details.tpl.css");
in save()
...
$aParams = $oConfig->getRequestParameter("editval");
$sText = print_r($aParams, true); // TODO - delete
error_log("inArticleExtend | save | aParams: $sText"); // TODO - delete
...
$oArticle->assign($aParams);
$oArticle->setNutritionText($aParams['oxarticles__oxnutrient']);
$oArticle->save();
in article_extend.tpl
<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="[{$iMaxUploadFileSize}]">
[{$oViewConf->getHiddenSid()}]
<input type="hidden" name="cl" value="article_extend">
<input type="hidden" name="fnc" value="">
<input type="hidden" name="oxid" value="[{$oxid}]">
<input type="hidden" name="voxid" value="[{$oxid}]">
<input type="hidden" name="oxparentid" value="[{$oxparentid}]">
<input type="hidden" name="editval[article__oxid]" value="[{$oxid}]">
<input type="hidden" name="editval[oxarticles__oxnutrient]" value="">
...
[{oxhasrights object=$edit field='oxnutrient' readonly=$readonly}]
[{if $readonly == ''}]
[{$editor}]
<div class="messagebox">[{oxmultilang ident="EDITOR_PLAINTEXT_HINT"}]</div>
[{else}]
<div id="myLongDesc" style="position:relative; width:1000px; white-space:normal; height:450px; border:1px solid #c1c1c1; overflow:scroll; padding:0 15px;">
[{$edit->getNutritionText()}]
</div>
[{/if}]
[{/oxhasrights}]
...
the effect:
If I manually edit an entry in oxartextends.oxnutrient for an article, the value is shown in the editor an I can edit it.
When I change the text and save it, the entry in DB is deleted/set to ‘’ (empty string).
The output in error_log form save():
inArticleExtend | save | aParams: Array
(
[article__oxid] => 000a876cdc6f43......
[oxarticles__oxnutrient] =>
[oxarticles__oxweight] => 0.309
[express_number] =>
[action_item] => 0
[oxarticles__oxissearch] => 1
)
my question
[B]What am I doing wrong, what’s missing to get the edited value back to DB?[/B]
the implemented fiunctions
/**
* get value for oxnutrition from oxartextends
*
* @return object
*/
public function getNutritionText() {
if ($this->_oNutritionText === null) {
// initializing
$this->_oNutritionText = new oxField();
// choosing which to get..
$sOxid = $this->getId();
$sViewName = getViewName('oxartextends', $this->getLanguage());
$oDb = oxDb::getDb();
$sSql = "select oxnutrient from {$sViewName} where oxid = " . $oDb->quote($sOxid);
$sDbValue = $oDb->getOne($sSql);
error_log("arOxArticle | getNutritionText | $sSql"); # TODO - delete
if ($sDbValue != false) {
$this->_oNutritionText->setValue($sDbValue, oxField::T_RAW);
}
}
error_log("arOxArticle | getNutritionText | $sDbValue"); # TODO - delete
return $this->_oNutritionText;
}
/**
* save article oxnutrition text to oxartextends table
*
* @param string $sText
*
*/
public function setNutritionText($sText) {
// setting current value
error_log("arOxArticle | setNutritionText | $sText"); # TODO - delete
$this->_oNutritionText = new oxField($sText, oxField::T_RAW);
$this->oxarticles__oxnutrient = new oxField($sText, oxField::T_RAW);
}
/**
* inserts article long description to artextends table
*
* @return null
*/
protected function _saveArtNutritionText()
{
$myConfig = $this->getConfig();
$sShopId = $myConfig->getShopID();
if ($this->_blEmployMultilanguage) {
$sValue = $this->getNutritionText()->getRawValue();
if ($sValue !== null) {
$oArtExt = oxNew('oxI18n');
$oArtExt->init('oxartextends');
$oArtExt->setLanguage((int) $this->getLanguage());
if (!$oArtExt->load($this->getId())) {
$oArtExt->setId($this->getId());
}
$oArtExt->oxartextends__oxnutrient = new oxField($sValue, oxField::T_RAW);
$oArtExt->save();
}
} else {
$oArtExt = oxNew('oxI18n');
$oArtExt->setEnableMultilang(false);
$oArtExt->init('oxartextends');
$aObjFields = $oArtExt->_getAllFields(true);
if (!$oArtExt->load($this->getId())) {
$oArtExt->setId($this->getId());
}
foreach ($aObjFields as $sKey => $sValue) {
if (preg_match('/^oxnutrient(_(\d{1,2}))?$/', $sKey)) {
$sField = $this->_getFieldLongName($sKey);
if (isset($this->$sField)) {
$sLongDesc = null;
if ($this->$sField instanceof oxField) {
$sLongDesc = $this->$sField->getRawValue();
} elseif (is_object($this->$sField)) {
$sLongDesc = $this->$sField->value;
}
if (isset($sLongDesc)) {
$sAEField = $oArtExt->_getFieldLongName($sKey);
$oArtExt->$sAEField = new oxField($sLongDesc, oxField::T_RAW);
}
}
}
}
$oArtExt->save();
}
}
extend save() method in oxarticle (not in core):
/**
* (oxArticle::_saveArtLongDesc()) save the object using parent::save() method.
*
* @return bool
*/
public function save()
{
$this->_assignParentDependFields();
if (($blRet = parent::save())) {
// saving long description
$this->_saveArtLongDesc();
$this->_saveArtNutritionText();
}
return $blRet;
}
only OXID Support can provide you qualified supprt/help for EE Shops, because its different from CE and WYSIWYG Editor is not a part of CE Shop:
https://www.oxid-esales.com/en/support-services/software-maintenance-and-support.html
the support was helpful.
there was only a js-call missing at the form element
// old and wrong:
// <form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" enctype="multipart/form-data" method="post">
// new:
<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" onSubmit="copyLongDesc('oxarticles__oxnutrient');" enctype="multipart/form-data" method="post">
Now values are stored correctly to DB.
-> can be closed as solved
[QUOTE=Printus;179835]the support was helpful.
there was only a js-call missing at the form element
// old and wrong:
// <form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" enctype="multipart/form-data" method="post">
// new:
<form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" onSubmit="copyLongDesc('oxarticles__oxnutrient');" enctype="multipart/form-data" method="post">
Now values are stored correctly to DB.
-> can be closed as solved[/QUOTE]
thank you so much!