Created
August 14, 2014 13:48
-
-
Save mrwhy-orig/d3f24947d8d983d5e9d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Dir: Widget/RteController.php **/ | |
/** | |
* Description of RteWidgetController | |
* | |
* @author Björn Haverland | |
*/ | |
class Tx_BHave_ViewHelpers_Widget_Controller_RteWidgetController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController { | |
/** | |
* Return TSCpid (cached) | |
* Using BackendUtility::getTSCpid() | |
* | |
* @param string $table Tablename | |
* @param string $uid UID value | |
* @param string $pid PID value | |
* @return array Array of two integers; first is the real PID of a record, second is the PID value for TSconfig. | |
* @see BackendUtility::getTSCpid() | |
* @todo Define visibility | |
*/ | |
public function getTSCpid($table, $uid, $pid) { | |
$key = $table . ':' . $uid . ':' . $pid; | |
if (!isset($this->cache_getTSCpid[$key])) { | |
$this->cache_getTSCpid[$key] = \TYPO3\CMS\Backend\Utility\BackendUtility::getTSCpid($table, $uid, $pid); | |
} | |
return $this->cache_getTSCpid[$key]; | |
} | |
public function getRTE($table, $field, $doc, $name, $value, $rep, $rowID){ | |
$formEngine = $this->objectManager->get('TYPO3\\CMS\\Backend\\Form\\FormEngine'); | |
$formEngine->initDefaultBEMode(); | |
$repository = $this->objectManager->get($rep); | |
$getField = "get".ucfirst($field); | |
$rowObj = $repository->findByUid($rowID); | |
if($rowObj === null){ | |
$row['uid'] = 0; | |
$row['content'] = $value; | |
$row['pid'] = 0; | |
} else { | |
$row['uid'] = $rowObj->getUid(); | |
$row['content'] = $rowObj->$getField(); | |
$row['pid'] = $rowObj->getPid(); | |
} | |
list($tscPID, $thePidValue) = $this->getTSCpid($table, $row['uid'], $row['pid']); | |
$RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($tscPID)); | |
$RTEtypeVal = \TYPO3\CMS\Backend\Utility\BackendUtility::getTCAtypeValue($table, $row); | |
$thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $table, $field, $RTEtypeVal); | |
$PA = array(""); | |
t3lib_div::loadTCA($table); | |
$PA['fieldConf'] = $GLOBALS['TCA'][$table]['columns'][$field]; | |
$PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ? $PA['fieldConf']['config']['form_type'] : $PA['fieldConf']['config']['type']; | |
$PA['itemFormElName']= $name; // Form field name | |
$PA['itemFormElName_file']=$formEngine->prependFormFieldNames_file.'[' . $table.'][' . $row['uid'].'][' . $field . ']'; // Form field name, in case of file uploads | |
$PA['itemFormElValue']=$row['content']; | |
$rteController = $this->objectManager->create("Tx_BHave_ViewHelpers_Widget_Controller_RteController", $doc); | |
$rte = $rteController->drawRTE($formEngine, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue); | |
return $rte; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* | |
* @author Bjoern Haverland ([email protected]) | |
* @license http://www.gnu.org/copyleft/gpl.html | |
*/ | |
class Tx_BHave_ViewHelpers_Widget_RteViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper { | |
/** | |
* Gets instance of template if exists or create a new one. | |
* Saves instance in viewHelperVariableContainer | |
* | |
* @return \TYPO3\CMS\Backend\Template\DocumentTemplate $doc | |
*/ | |
public function getDocInstance() { | |
if ($this->viewHelperVariableContainer->exists( | |
'TYPO3\\CMS\\Fluid\\ViewHelpers\\Be\\AbstractBackendViewHelper', | |
'DocumentTemplate' | |
) | |
) { | |
$doc = $this->viewHelperVariableContainer->get( | |
'TYPO3\\CMS\\Fluid\\ViewHelpers\\Be\\AbstractBackendViewHelper', | |
'DocumentTemplate' | |
); | |
} else { | |
/** @var $doc \TYPO3\CMS\Backend\Template\DocumentTemplate */ | |
$doc = $this->createDocInstance(); | |
$doc->backPath = $GLOBALS['BACK_PATH']; | |
$this->viewHelperVariableContainer->add( | |
'TYPO3\\CMS\\Fluid\\ViewHelpers\\Be\\AbstractBackendViewHelper', | |
'DocumentTemplate', | |
$doc | |
); | |
} | |
return $doc; | |
} | |
/** | |
* | |
* @var | |
*/ | |
protected $controller; | |
/** | |
* add RTE | |
* @param string $table | |
* @param string $col | |
* @param int $rowID | |
* @param string $rep | |
* @return string | |
*/ | |
public function render($table, $col, $rowID, $rep) { | |
$name = $this->getName(); | |
$this->registerFieldNameForFormTokenGeneration($name); | |
$doc = $this->getDocInstance(); | |
$this->controller = $this->objectManager->create("Tx_BHave_ViewHelpers_Widget_Controller_RteWidgetController"); | |
$value = htmlspecialchars($this->getValue()); | |
return $this->controller->getRTE($table, $col, $doc, $name, $value, $rep, $rowID); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Dir: Widget/RteWidgetController.php **/ | |
/** | |
* Description of RteWidgetController | |
* | |
* @author Björn Haverland | |
*/ | |
class Tx_BHave_ViewHelpers_Widget_Controller_RteWidgetController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController { | |
/** | |
* Return TSCpid (cached) | |
* Using BackendUtility::getTSCpid() | |
* | |
* @param string $table Tablename | |
* @param string $uid UID value | |
* @param string $pid PID value | |
* @return array Array of two integers; first is the real PID of a record, second is the PID value for TSconfig. | |
* @see BackendUtility::getTSCpid() | |
* @todo Define visibility | |
*/ | |
public function getTSCpid($table, $uid, $pid) { | |
$key = $table . ':' . $uid . ':' . $pid; | |
if (!isset($this->cache_getTSCpid[$key])) { | |
$this->cache_getTSCpid[$key] = \TYPO3\CMS\Backend\Utility\BackendUtility::getTSCpid($table, $uid, $pid); | |
} | |
return $this->cache_getTSCpid[$key]; | |
} | |
public function getRTE($table, $field, $doc, $name, $value, $rep, $rowID){ | |
$formEngine = $this->objectManager->get('TYPO3\\CMS\\Backend\\Form\\FormEngine'); | |
$formEngine->initDefaultBEMode(); | |
$repository = $this->objectManager->get($rep); | |
$getField = "get".ucfirst($field); | |
$rowObj = $repository->findByUid($rowID); | |
if($rowObj === null){ | |
$row['uid'] = 0; | |
$row['content'] = $value; | |
$row['pid'] = 0; | |
} else { | |
$row['uid'] = $rowObj->getUid(); | |
$row['content'] = $rowObj->$getField(); | |
$row['pid'] = $rowObj->getPid(); | |
} | |
list($tscPID, $thePidValue) = $this->getTSCpid($table, $row['uid'], $row['pid']); | |
$RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($tscPID)); | |
$RTEtypeVal = \TYPO3\CMS\Backend\Utility\BackendUtility::getTCAtypeValue($table, $row); | |
$thisConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $table, $field, $RTEtypeVal); | |
$PA = array(""); | |
t3lib_div::loadTCA($table); | |
$PA['fieldConf'] = $GLOBALS['TCA'][$table]['columns'][$field]; | |
$PA['fieldConf']['config']['form_type'] = $PA['fieldConf']['config']['form_type'] ? $PA['fieldConf']['config']['form_type'] : $PA['fieldConf']['config']['type']; | |
$PA['itemFormElName']= $name; // Form field name | |
$PA['itemFormElName_file']=$formEngine->prependFormFieldNames_file.'[' . $table.'][' . $row['uid'].'][' . $field . ']'; // Form field name, in case of file uploads | |
$PA['itemFormElValue']=$row['content']; | |
$rteController = $this->objectManager->create("Tx_BHave_ViewHelpers_Widget_Controller_RteController", $doc); | |
$rte = $rteController->drawRTE($formEngine, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue); | |
return $rte; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{namespace asc=Tx_BHave_ViewHelpers} | |
<asc:Widget.rte property="content" table="tx_bhave_domain_model_boxcontent" col="Content" rowID="{rowID}" rep="Tx_BHave_Domain_Repository_BoxContentRepository" /> | |
<script type="text/javascript"> | |
var fName = "{rteFieldName}"; | |
//Save function for the Editor. Would be called by pressing the save button. | |
function saveData(){ | |
var html = RTEarea['tx_bhave_web_boxen_'+fName+'__content_'].editor.getHTML(); | |
$('RTEareatx_bhave_web_boxen_boxContent__content_').setValue(html); | |
} | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment