[TYPO3-core] RFC: eval API (#1639)
Ingmar Schlecht
ingmar at typo3.org
Mon Dec 5 15:40:53 CET 2005
Hi guys,
this one looks like a really useful feature I have been waiting for a
long time.
I just looked at the patch and tested it briefly.
Here are some comments.
----------------------------------------------------------------
instead of...
$TYPO3_CONF_VARS['EVAL']['myext']['extraeval1'] and accordingly
"myext;extraeval1"
...make it:
$TYPO3_CONF_VARS['EVAL']['tx_myext_extraeval1'] and accordingly
"tx_myext_extraeval1"
...because it makes it simpler and doesn't have any disadvantage
----------------------------------------------------------------
Sysext "evaluations" should be called "formeval" because it then
explains that it is about
*form* evaluations.
----------------------------------------------------------------
Files in the config array should be referenced using
EXT:myext/class.tx_myext_evalcalss.php syntax resolved using
t3lib_div::getFileAbsFileName().
----------------------------------------------------------------
I would like to remove the hack for evals from the sysext "evaluations"
because if we have a workaround for the old evaluations, we could just
as well have left them in their original place. I think they should work
*exactly* like any other evaluation using the API.
So I'd remove this chunk of code:
+ } else {
+ // eval methods from sysext "evaluations"
+ if (!t3lib_extMgm::isLoaded('evaluations')) continue;
+ $classPath =
t3lib_extMgm::extPath('evaluations').'class.tx_evaluations_methods.php';
+ $className = 'tx_evaluations_methods';
+ }
The only difference between evals of the "evaluations" sysext will be
that they don't have
a prefix like tx_evaluations_trim but will be called just e.g. "trim".
$TYPO3_CONF_VARS['EVAL']['trim'] = array(
'file' => 'EXT:evaluations/class.tx_evaluations.php',
'class' => 'tx_evaluations',
'method' => 'trim'
);
----------------------------------------------------------------
Kickstarter should be able to create new evals (it should have a new
section "Form evaluations").
Those new evaluations should directly be selectable for fields of the
"New Database Table" and "Extend existing table" section of the kicki.
----------------------------------------------------------------
OK, that's if for now.
Keep up the good work!
cheers,
Ingmar
Sebastian Kurfuerst schrieb:
> This is a CVS patch request.
>
> Type: (Bugfix / New feature / Code cleanup)
> => New feature
>
> Description:
> see http://bugs.typo3.org/view.php?id=1639
> Sometimes it would be useful to add special evaluations to be used in
> TCEforms. As an example, if the user needs a special date evaluation in
> the BE, he currently has to XCLASS the evaluations and add some custom
> JS. To make this more clean, an eval API would be nice.
>
> Solution:
> * currently, the JS part and the PHP part of an evaluation are
> located in different places => difficult to maintain
> * all built-in evaluations removed from the core and put into a
> sysext "evaluations".
> * new evaluations need to be added to $TYPO3_CONF_VARS['EVAL']
> * every evaluation has a JS part and a (possible) PHP part, as
> usual
>
> Possible issues:
> * the evaluations sysext is not installed by default I think, how
> can we install it automatically on update? Maybe with the update
> wizard?
> * $TYPO3_CONF_VARS['EVAL'] is maybe not the right place for
> evaluations. Suggestions?
>
> Branches: (HEAD / TYPO3_3-8 / TYPO3_3-7)
> => HEAD
>
> Bugtracker reference:
> => http://bugs.typo3.org/view.php?id=1639
>
> Files:
> .patch - core patch
> _evaluations.t3x - sysext implementing the current evaluations
> _example_evaluations.t3x - example extension for a custom evaluation
>
> The documentation is still missing, but this will be created as well.
>
> Thanks to Thomas Hempel who provided this patch.
>
> Greets, Sebastian
>
>
> ------------------------------------------------------------------------
>
> --- ../../typo380_original/t3lib/class.t3lib_tcemain.php 2005-10-30 13:10:53.140232000 +0100
> +++ class.t3lib_tcemain.php 2005-11-06 15:12:18.703791248 +0100
> @@ -273,7 +273,7 @@
> var $copiedFileMap=array();
>
> var $checkValue_currentRecord=array(); // Set to "currentRecord" during checking of values.
> -
> + var $evalClasses = NULL; // hold instances of classes for evaluations
>
> /**
> * Initializing.
> @@ -1930,73 +1930,37 @@
> $set = true;
>
> foreach($evalArray as $func) {
> - switch($func) {
> - case 'int':
> - case 'year':
> - case 'date':
> - case 'datetime':
> - case 'time':
> - case 'timesec':
> - $value = intval($value);
> - break;
> - case 'double2':
> - $theDec = 0;
> - for ($a=strlen($value); $a>0; $a--) {
> - if (substr($value,$a-1,1)=='.' || substr($value,$a-1,1)==',') {
> - $theDec = substr($value,$a);
> - $value = substr($value,0,$a-1);
> - break;
> - }
> - }
> - $theDec = ereg_replace('[^0-9]','',$theDec).'00';
> - $value = intval(str_replace(' ','',$value)).'.'.substr($theDec,0,2);
> - break;
> - case 'md5':
> - if (strlen($value)!=32){$set=false;}
> - break;
> - case 'trim':
> - $value = trim($value);
> - break;
> - case 'upper':
> - $value = strtoupper($value);
> -# $value = strtr($value, 'áéúíâêûôîæøåäöü', 'ÁÉÚÍÂÊÛÔÎÆØÅÄÖÜ'); // WILL make trouble with other charsets than ISO-8859-1, so what do we do here? PHP-function which can handle this for other charsets? Currently the browsers JavaScript will fix it.
> - break;
> - case 'lower':
> - $value = strtolower($value);
> -# $value = strtr($value, 'ÁÉÚÍÂÊÛÔÎÆØÅÄÖÜ', 'áéúíâêûôîæøåäöü'); // WILL make trouble with other charsets than ISO-8859-1, so what do we do here? PHP-function which can handle this for other charsets? Currently the browsers JavaScript will fix it.
> - break;
> - case 'required':
> - if (!$value) {$set=0;}
> - break;
> - case 'is_in':
> - $c=strlen($value);
> - if ($c) {
> - $newVal = '';
> - for ($a=0;$a<$c;$a++) {
> - $char = substr($value,$a,1);
> - if (strstr($is_in,$char)) {
> - $newVal.=$char;
> - }
> - }
> - $value = $newVal;
> - }
> - break;
> - case 'nospace':
> - $value = str_replace(' ','',$value);
> - break;
> - case 'alpha':
> - $value = ereg_replace('[^a-zA-Z]','',$value);
> - break;
> - case 'num':
> - $value = ereg_replace('[^0-9]','',$value);
> - break;
> - case 'alphanum':
> - $value = ereg_replace('[^a-zA-Z0-9]','',$value);
> - break;
> - case 'alphanum_x':
> - $value = ereg_replace('[^a-zA-Z0-9_-]','',$value);
> - break;
> + $funcData = t3lib_div::trimExplode(';', $func, 1);
> +
> + // determine the correct class
> + if (count($funcData) > 1) {
> + // userdefined evaluations
> + $evalConfData = $GLOBALS['TYPO3_CONF_VARS']['EVAL'][$funcData[0]][$funcData[1]];
> + $classPath = t3lib_extMgm::extPath($funcData[0]).$evalConfData['file'];
> + $className = $evalConfData['class'];
> + } else {
> + // eval methods from sysext "evaluations"
> + if (!t3lib_extMgm::isLoaded('evaluations')) continue;
> + $classPath = t3lib_extMgm::extPath('evaluations').'class.tx_evaluations_methods.php';
> + $className = 'tx_evaluations_methods';
> + }
> +
> + // make a new instance if necessary
> + if (!isset($this->evalClasses[$classPath])) {
> + // create new instance and store it in class array for later use
> + require_once($classPath);
> + $evalClass = t3lib_div::makeInstance($className);
> + $this->evalClasses[$classPath] = $evalClass;
> + } else {
> + // else fetch the instance from the class array
> + $evalClass = $this->evalClasses[$classPath];
> + }
> +
> + // execute evaluation method
> + if (method_exists($evalClass, 'evaluateFieldValue')) {
> + $value = $evalClass->evaluateFieldValue($value, $func, $is_in, &$set);
> }
> +
> }
> if ($set) {$res['value'] = $value;}
> return $res;
> --- ../../typo380_original/t3lib/class.t3lib_tceforms.php 2005-11-06 09:52:37.432787672 +0100
> +++ class.t3lib_tceforms.php 2005-11-06 15:12:01.213450184 +0100
> @@ -279,8 +279,9 @@
> var $additionalJS_pre = array(); // Additional JavaScript, printed before the form
> var $additionalJS_post = array(); // Additional JavaScript printed after the form
> var $additionalJS_submit = array(); // Additional JavaScript executed on submit; If you set "OK" variable it will raise an error about RTEs not being loaded and offer to block further submission.
> + var $additionalEvalJS = array(); // Additional JavaScript for user defined evaluations
>
> -
> + var $evalClasses = NULL; // hold instances of classes for evaluations
>
>
>
> @@ -932,6 +933,56 @@
> $item.='<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />'; // This is the ACTUAL form field - values from the EDITABLE field must be transferred to this field which is the one that is written to the database.
> $this->extJSCODE.='typo3FormFieldSet('.$paramsList.');';
>
> + // create and add the methods for checking userdefined evaluations
> + if (is_array($evalList)) {
> + foreach ($evalList as $evalData) {
> + $funcData = t3lib_div::trimExplode(';', $evalData, 1);
> +
> + // determine the correct class
> + if (count($funcData) > 1) {
> + // userdefined evaluations
> + $evalConfData = $GLOBALS['TYPO3_CONF_VARS']['EVAL'][$funcData[0]][$funcData[1]];
> + $classPath = t3lib_extMgm::extPath($funcData[0]).$evalConfData['file'];
> + $className = $evalConfData['class'];
> + $methodName = $className.'_' .$funcData[1];
> + $funcName = $funcData[1];
> + } else {
> + // eval methods from sysext "evaluations"
> + if (!t3lib_extMgm::isLoaded('evaluations')) continue;
> + $classPath = t3lib_extMgm::extPath('evaluations').'class.tx_evaluations_methods.php';
> + $className = 'tx_evaluations_methods';
> + $methodName = $className.'_'.$funcData[0];
> + $funcName = $evalData;
> + }
> +
> + // make a new instance if necessary
> + if (!isset($this->evalClasses[$classPath])) {
> + // create new instance and store it in class array for later use
> + require_once($classPath);
> + $evalClass = t3lib_div::makeInstance($className);
> + $this->evalClasses[$classPath] = $evalClass;
> + } else {
> + // else fetch the instance from the class array
> + $evalClass = $this->evalClasses[$classPath];
> + }
> +
> + if (method_exists($evalClass, 'returnFieldJS')) {
> + $this->extJSCODE .= "\n\nfunction ".$methodName."(value) {\n".$evalClass->returnFieldJS($funcName)."\n}";
> + $this->additionalEvalJS[] = $methodName;
> + }
> +
> + if (method_exists($evalClass, 'returnBasicJS') && !isset($this->basicJSMethods[$className])) {
> + $isInclude = false;
> + $script = $evalClass->returnBasicJS(&$isInclude);
> + if ($isInclude) {
> + $this->basicJSMethods[$className] = '<script type="text/javascript" src="'.$script.'"></script>';
> + } else {
> + $this->basicJSMethods[$className] = '<script type="text/javascript">'.$script.'</script>';
> + }
> + }
> + }
> + }
> +
> // Creating an alternative item without the JavaScript handlers.
> $altItem = '<input type="hidden" name="'.$PA['itemFormElName'].'_hr" value="" />';
> $altItem.= '<input type="hidden" name="'.$PA['itemFormElName'].'" value="'.htmlspecialchars($PA['itemFormElValue']).'" />';
> @@ -4146,12 +4197,25 @@
>
> $this->TBE_EDITOR_fieldChanged_func='TBE_EDITOR_fieldChanged_fName(fName,formObj[fName+"_list"]);';
>
> + // create call method for user defined evaluations
> + if (count($this->additionalEvalJS) > 0) {
> + $this->extJSCODE .= "\n\nfunction evalFunc_userFunction(name, value) {\nswitch (name) {\n";
> + // add a switch case for every user defined evaluation
> + foreach ($this->additionalEvalJS as $evalMethod) {
> + $this->extJSCODE .= "case '" .$evalMethod ."':\n newValue = " .$evalMethod ."(value); break\n";
> + }
> + $this->extJSCODE .= "}\nreturn newValue;\n}\n";
> + }
> +
> if ($this->loadMD5_JS) {
> $out.='
> <script type="text/javascript" src="'.$this->backPath.'md5.js"></script>';
> }
> - $out.='
> - <script type="text/javascript" src="'.$this->backPath.'t3lib/jsfunc.evalfield.js"></script>
> +
> + // insert some basic evaluations from evaluation extensions
> + $out .= "\n" .implode("\n", $this->basicJSMethods);
> +
> + $out .= '
> <script type="text/javascript">
> /*<![CDATA[*/
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Typo3-team-core mailing list
> Typo3-team-core at lists.netfielders.de
> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-team-core
More information about the TYPO3-team-core
mailing list