Wednesday, April 30, 2014

Tuesday, April 15, 2014

Wie kann man felogin in TYPO3 6.1 um eine XCLASS erweitern? / Wie nutzt man hooks in TYPO3 6.1?

Wie kann man felogin in TYPO3 6.1 um eine XCLASS erweitern?

In der Theorie ist das hier beschrieben:

http://docs.typo3.org/TYPO3/CoreApiReference/ApiOverview/Xclasses/Index.html

In der Praxis ist es mir aber noch nicht gelungen.



Wie nutzt man hooks in TYPO3 6.1?

Ein kurzes Tutorial findet sich z. B. unter:

http://www.schmutt.de/456/hook-mit-extbase-implementieren/comment-page-1/

Verfuegbare hooks findet man idealerweise in der Dokumentation (z.b. einer Extension). Fall nicht, kann man den Programmcode z.b. nach dem Begriff "hook" durchsuchen.

Die Extension "felogin" bietet z.b. einen hook namens "postProcContent" an, womit sich der gesamte von der Extension erzeugte HTML-Code nachbearbeiten laesst. (Damit lassen sich evtl. XCLASS Implementierungen umgehen. XCLASSes sind nur sehr bedingt empfehlenswert - siehe die entspr. Dokumentationen.)

Thursday, April 3, 2014

Wie kann ich eine TypoScript-Constants Datei ohne die TYPO3-Frontend-Umgebung benutzen/lesen/parsen/auswerten?


Eine grundlegende Beschreibung zum parsen von TypoScript-Dateien befindet sich hier:
http://docs.typo3.org/typo3cms/TyposcriptSyntaxReference/TypoScriptParserApi/Index.html

Diese wendet sich aber an (Core-)Extension-Entwickler, die z.b. TypoScript-Erweiterungen implementieren moechten.

Falls man die bestehenden TypoScript-Moeglichkeiten, d.h. das bestehende Framework nutzen moechte, wird etwas mehr benoetigt.

Hier ein gekuerztes Beispiel, das aus folgender Situation entstanden ist: in einem eigenen PHP-Page-Not-Found-Handler sollen Werte aus einer TypoScript-Constants-Datei verwendet werden. Im Page-Not-Found-Handler stehen die Werte aus $GLOBALS['TSFE'] nur unvollstaendig zur Verfuegung (da ja keine Seite gefunden wurde), und vor allem kein $GLOBALS['TSFE']->tmpl->setup (d.h. ausgewertetes TypoScript-Setup).


require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('core') . 'Classes/Utility/GeneralUtility.php');
require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('core') . 'Classes/TypoScript/Parser/TypoScriptParser.php');
require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('frontend') . 'Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php');


class myPhpObjectClass {
    function myMethod() {
        // 1. read our typoscript constants file:
        $constants_ts = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/path/to/your/constantsfile.ts');
        // 2. build typoscript parser:
        $TSparserObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser');
        // 3. build matchObject for TypoScript conditions to work (ooh, very typo3-ish...):
        $matchObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher');
        // 4. add to (incomplete, because page-not-found) $GLOBALS['TSFE'], required by our $matchObject
        //    (actually only rootLine required, but we build complete tmpl object, just for the sake of typo3-ness...):
        $GLOBALS['TSFE']->tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\TypoScript\TemplateService');
        $GLOBALS['TSFE']->tmpl->rootLine = $pObj->rootLine;
        // 5. parse typoscript (ooh, again, very typo3-ish: must check include lines... separately...)
        $constants_ts = \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines($constants_ts);
        $TSparserObject->parse($constants_ts, $matchObject);
        // 6. whatever we have parsed is now in $TSparserObject->setup:
        $constants = $TSparserObject->setup;
        // 7. finally, we can grab the values needed! :-)
        $myValue = $constants['myValueFromConstantsfile'];

    }
}

(entwickelt mit TYPO3 6.1.7)

Moegliche Verbesserungen:
- Wie parsed man eine Setup-Datei einschliesslich Konstanten (z.b. {$myConstant})?
- bessere Methode (statt file_get_contents($_SERVER['DOCUMENT_ROOT']...)) zum Einlesen der TypoScript-Datei?

Tuesday, April 1, 2014

Wie kann man den Layout-Schalter eines Content-Elements nutzen?


...im TSConfig Feld einer Seite eingeben:

TCEFORM {
    tt_content {
        layout {

            # neue eintraege hinzufuegen:
            addItems {
                4 = Layout fuer hervorgehobene Elemente
            }

            # mit "altLabels" koennen die bestehenden eintraege veraendert werden:
            altLabels {
                2 = Mein Layout
            }
        }
    }
}


 
...im TypoScript Template Feld "Setup":

lib.layoutSwitchCObject = CASE
lib.layoutSwitchCObject {
    key.field = layout
    4 = TEXT
    4.value = <div id="c{field:uid}" class="csc-default step-by-step-guide">|</div>
    4.insertData = 1
}


# nun ergaenzen wir die ausgabe der content-elemente via styles.content.get
# durch unser cObject (siehe oben)

page = PAGE
page {
    10 < styles.content.get
    10 {
        renderObj {
            stdWrap.innerWrap.cObject < lib.layoutSwitchCObject
        } 
    } 
}