TYPO3.CMS 7.6 Schnipsel
Aus Vosp.info
Version vom 8. März 2016, 22:36 Uhr von F (Diskussion | Beiträge) (→Datei cache typo3 (keine Datenbank))
Inhaltsverzeichnis
Allgemeine Theorien
Template / Typoscript Ladereihenfolge
- keine ahnung was als erstes geladen,
- Basis-Template
- danach werden die statischen templates (ExtensionManagementUtility::addStaticFile()) welche im Backend bei den Seiten aus den Erweiterungen eingebunden werden können geladen (oben als erstes/unten als letztes)
- danach die constants/setup der Seite
- danach erst die alphabetisch die ext_typoscsript_setup.txt Dateien
typoscript
[globalVar = TSFE:id = 10|12|15] (ist enthalten)
[globalVar = TSFE:id != 10|12|15] (ist nicht enthalten)
PIDinRootline
[PIDinRootline = 31]
page.10.variables.INHALT >
page.10.variables.INHALT = TEXT
page.10.variables.INHALT.value = Sie sind auf Seite 31 !!!! und PIDinRootline darf nicht geschachtelt sein!!!!
[global]
- wichtig die PIDinRootline Condition, darf nicht innner halb von geschweiften {} Klammern geschachtelt stehen
Sprachübersetzungen typoscript
plugin.tx_name_LOCAL_LANG.de.greater = Gruß
extbase (php)
Generell
Variablen
krexx($GLOBALS['TSFE']);
krexx($GLOBALS['TSFE']->tmpl);
krexx($GLOBALS['TSFE']->tmpl->constants);
krexx($GLOBALS['TSFE']->tmpl->setup);
Konstanten
ContentObject (tt_content Inhaltselement Eintrag)
- hole aktuelles tt_content objekt, also in diesem (Controller Plugin) Fall, das plugin (Controller::Action) Inhaltselement
im Controller:
$this->contentObj = $this->configurationManager->getContentObject();
// unter
krexx($this->contentObj->data); // ist ein tt_content Datensatz
// zB.
$this->contentObj->data['pid']; // Seiten ID wo das Plugin (Inhaltselement) installiert ist
$this->contentObj->data['pages']; // Datensatzsammlung
Installations Domain absRefPrefix
$GLOBALS['TSFE']->absRefPrefix.'/'
_GET / _POST holen
\TYPO3\CMS\Core\Utility\GeneralUtility::_GET();
\TYPO3\CMS\Core\Utility\GeneralUtility::_POST();
hole Objektmanager um Klassen bzw Objekte zu laden
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$ncmail = $objectManager->get('Netzcoop\Extension\Services\Ncmail');
hole Extension Konfiguration aus dem Backend
Formularfelder die vorher in ext_conf_template.txt definiert und im Backend unter Erweiterungsmanager bei der Extension eingestellt wurden
ext_conf_template.txt
# cat=basic/enable/010; type=int; label=LLL:EXT:ancextension/Resources/Private/Language/locallang_be.xml:basic.varInt
varInt =
# cat=basic/enable/020; type=string; label=LLL:EXT:ancextension/Resources/Private/Language/locallang_be.xml:basic.varString
varString = default wert
werte holen
// im Controller
$confArray = unserialize($GLOBALS["TYPO3_CONF_VARS"]["EXT"]["extConf"][strtolower($this->extensionName)]);
// im Zweifel aber Extensionname (ancextension) angeben!!!!
$confArray = unserialize($GLOBALS["TYPO3_CONF_VARS"]["EXT"]["extConf"][strtolower('ancextension')]);
echo $confArray['varString'];
logout / login
protected function login($ncfeuserid) {
$user = $this->userRepository->findByUid($ncfeuserid);
$GLOBALS['TSFE']->fe_user->createUserSession($user->_getProperties());
$GLOBALS["TSFE"]->fe_user->user = $GLOBALS["TSFE"]->fe_user->fetchUserSession();
// es wird empfohlen jetzt zu redirect'en
}
protected function logout() {
$GLOBALS['TSFE']->fe_user->logoff();
}
Controller
Controller::settings - Informationen aus Typoscript und Flexform
von Typoscript
- ancotherextension/Configuration/TypoScript/setup.txt
plugin.tx_ancmycurrentextension {
settings {
ancotherextension_typoscript_setup = TEXT
ancotherextension_typoscript_setup {
value = ancotherextension/Configuration/TypoScript/setup.txt
}
}
}
- ancotherextension/ext_typoscript_setup.txt
plugin.tx_ancmycurrentextension {
settings {
ancotherextension_ext_typoscript = TEXT
ancotherextension_ext_typoscript {
value = ancotherextension: ext_typoscript_setup.txt
}
}
}
von Flexform
- plugin Konfiguration beim Inhaltselement
ancmycurrentextension/Configuration/FlexForms/pi.xml
<T3DataStructure>
<meta>
<langDisable>1</langDisable>
</meta>
<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>examples.pi_flexform.sheetGeneral</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.flexformvariable>
<TCEforms>
<label>flexformvariable label</label>
<config>
<type>input</type>
<size>10</size>
<max>10</max>
<eval>trim</eval>
</config>
</TCEforms>
</settings.flexformvariable>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
ancmycurrentextension/ext_localconf.php
$pluginSignature = 'pi';
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Netzcoop.' . $_EXTKEY,
$pluginSignature,
array(
'Nctest' => 'show',
),
// non-cacheable actions
array(
'Nctest' => 'show',
)
);
ancmycurrentextension/ext_tables.php
$pluginSignature = 'pi';
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
$_EXTKEY,
$pluginSignature,
'ancmycurrentextension: pi'
);
$TCA['tt_content']['types']['list']['subtypes_addlist'][$_EXTKEY.'_'.strtolower($pluginSignature)]='pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($_EXTKEY.'_'.strtolower($pluginSignature), 'FILE:EXT:'.$_EXTKEY.'/Configuration/FlexForms/'.$pluginSignature.'.xml');
nach Controller::settings
- ancmycurrentextension/Classes/Controller/NctestController.php
// ...
public function showAction() {
krexx($this->settings);
echo $this->settings['ancotherextension_typoscript_setup']['value'];
echo $this->settings['ancotherextension_ext_typoscript']['value'];
echo $this->settings['flexformvariable'];
}
// ...
Url/Link erstellen
$uriBuilder = $this->controllerContext->getUriBuilder();
$uriBuilder->reset();
$uriBuilder->setArguments(array(
strtolower($this->extensionName) => array(
'param1' => $user->getUid(),
'param2' => 'test',
)
));
$uri = $uriBuilder->build();
\TYPO3\CMS\Core\Utility\HttpUtility::redirect($uri, \TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_303);
$uriBuilder = $this->objectManager->get(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
# ausserhalb vom Controller ists schwierig weil kontext fehlt
#$uriBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class);
# backend uribuilder
# $uriBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
$uriBuilder->setRequest($this->request);
$url = $uriBuilder->reset()->uriFor($action, $parameters, $controller);
- https://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_extbase_1_1_mvc_1_1_web_1_1_routing_1_1_uri_builder.html
- Probleme gibt es ausserhalb von einem Controller und wenn mensch nicht eingeloggt ist
Actions für ander extensions bereitstellen
Configuration/TypoScript/setup.txt
config.tx_extbase {
objects {
In2code\Powermail\Controller\FormController {
className = Netzcoop\Ancextension\Controller\FormController
}
}
}
- ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['Powermail']['plugins']['Pi1']['controllers']['Form']['actions'][] = 'neue';
Domain
Repository nutzen
ein Repository zum Beispiel im Sheduler nutzen
- ausserhalb von einem controller oder so ein Repository nutzen
/** @var $querySettings \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings */
// $querySettings = $objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class);
$querySettings = $objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
$querySettings->setStoragePageIds(array(15));
$frontendUserRepository->setDefaultQuerySettings($querySettings);
$users=$frontendUserRepository->findAll();
krexx($users);
Database
direktes sql
// prepare_SELECTquery ($select_fields, $from_table, $where_clause, $groupBy= '', $orderBy= '', $limit= '', array $input_parameters=array())
$statement = $GLOBALS['TYPO3_DB']->prepare_SELECTquery(
'*' // $select_fields
, 'tab1, tab1_mm as mm' // $from_table
, 'tt_news.uid = mm.uid_local ' // $where_clause
. 'AND tt_news.pid = :store_page_id '
. $ncsearchwhere.$between
, '' // $groupBy
, 'crdate DESC' // $orderBy
, '' // $limit
);
$statement->bindValues(array(
':store_page_id' => $store_page_id
));
if ($statement) {
$statement->execute();
$return = $statement->fetchAll();
$statement->free();
}
ext_conf_template.txt
vorhandene typen
ext_conf_template.txt
# cat=basic/enable/020;; type=int+; label=LLL:EXT:ancextension/Resources/Private/Language/locallang_be.xml:basic.forgotTimeForDeactivateLogin
forgotTimeForDeactivateLogin =
# cat=basic/enable/030;; type=string; label=LLL:EXT:ancextension/Resources/Private/Language/locallang_be.xml:basic.mailsubject
mailsubject =
# cat=basic/enable/017;; type=options[gleich=0,ungleich=1]; label=LLL:EXT:ancextension/Resources/Private/Language/locallang_be.xml:basic.emailcondition2
emailcondition2 =
eigener typ (als Viewhelper)
ext_conf_template.txt
# cat=basic/enable/050;; type=user[Netzcoop\Ancextension\ViewHelpers\TextArea->render]; label=LLL:EXT:ancextension/Resources/Private/Language/locallang_be.xml:basic.mailtext
mailtext =
Classes/ViewHelpers/TextArea.php
<?php
namespace Netzcoop\Ancextension\ViewHelpers;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extensionmanager\ViewHelpers\Form\TypoScriptConstantsViewHelper;
/**
* @package jwparking
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class TextArea {
/**
* Tag builder instance
*
* @var \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder
*/
protected $tag = NULL;
/**
* constructor of this class
*/
public function __construct() {
$this->tag = GeneralUtility::makeInstance('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder');
}
/**
* render textarea for extConf
*
* @param array $parameter
* @param TypoScriptConstantsViewHelper $parentObject
* @return string
*/
public function render(array $parameter = array(), TypoScriptConstantsViewHelper $parentObject) {
$this->tag->setTagName('textarea');
$this->tag->forceClosingTag(TRUE);
$this->tag->addAttribute('cols', 45);
$this->tag->addAttribute('rows', 7);
$this->tag->addAttribute('name', $parameter['fieldName']);
$this->tag->addAttribute('id', 'em-' . $parameter['fieldName']);
if ($parameter['fieldValue'] !== NULL) {
$this->tag->setContent(trim($parameter['fieldValue']));
}
return $this->tag->render();
}
}
fluid
if in geschweiften klammern
1: {f:if(condition: "{type}=='auto'", then:" dannDas" )}
2: <f:if condition="{type}=='auto'"> dannDas</f:if>
elseif
<f:if condition="{var}!='<ul class=\"navi\"></ul>'">
<f:then>
hier ist if
</f:then>
<f:else>
<f:if condition="!{var}">
<f:then>
Hier ist else if
</f:then>
<f:else>
Hier ist Else
</f:else>
</f:if>
</f:else>
</f:if>
translate
- de.locallang.xlf
<trans-unit id="form.login.no.account.yet">
<target>Hier gleich ein Link <![CDATA[? <a href="%s" target="%s" id="register-btn">nein hier</a>]]></target>
</trans-unit>
<trans-unit id="linktest2">
<target>Weitere Informationen zu den Lizenzen<![CDATA[ <a href="%s" id="register-btn">finden Sie hier</a>]]></target>
</trans-unit>
- template
<f:translate key="form.login.no.account.yet" arguments="{0: '{f:uri.action(action: \'test\')}', 1: '_self'}" />
<f:format.html>{f:translate(key: 'form.login.no.account.yet', arguments: {0: 'dog', 1: 'fox'})}</f:format.html>
<p><f:format.html>{f:translate(key: 'linktest2', arguments: {0: '{settings.linkTo}'})}</f:format.html></p>
allgemein
<f:format.html parseFuncTSPath="lib.parseFunc">{ancitscttnews.bodytext}</f:format.html>
Backend
Javascript im Backend
ext_localconf.php
<?php
$GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'][] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY). '/backend_ext1.php';
backend_ext1.php
<?php
if (TYPO3_MODE=="BE" ) {
$pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
$path = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('extensionsname');
$pageRenderer->addJsFile('https://code.jquery.com/jquery-1.11.3.min.js', 'text/javascript', true, false);
$pageRenderer->addJsFile($path.'/Resources/Public/JavaScript/ancbackend.js', 'text/javascript', true, false);
}
- Achtung
- es muss extra der Weg über eine extra Datei gegangen werden, da $GLOBALS['TBE_TEMPLATE'] nicht geladen ist
- Cache muss natürlich gelöscht werden
- in ext_localconf muss der absolute Pfad angegeben werden
- in backend_ext1.php muss der relative Pfad angegeben werden (vom backend ;) )
- http://www.typo3.net/forum/thematik/zeige/thema/117431/
CSS im Backend
ext_tables.php
if (TYPO3_MODE=="BE" ) {
$TBE_STYLES['inDocStyles_TBEstyle'] .= ' body {font-size: 100px;}";';
$TBE_STYLES['inDocStyles_TBEstyle'] .= '@import "/typo3conf/ext/'.$_EXTKEY.'/Resources/Public/Stylesheets/backend.css";';
}
- Cache muss gelehrt werden
- Achtung: CSS ist nicht im iframe gültig
Transformation typo3 4.x => typo3 7.6
GeneralUtility
alt
t3lib_div::
neu
\TYPO3\CMS\Core\Utility\GeneralUtility::
alt
$this->doc = t3lib_div::makeInstance('bigDoc');
neu
$this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
BaseScriptClass
alt
extends t3lib_SCbase
neu
extends \TYPO3\CMS\Backend\Module\BaseScriptClass
BackendUtility
alt
t3lib_BEfunc::
neu
BackendUtility:: use \TYPO3\CMS\Backend\Utility\BackendUtility;
BackendUtility
alt
t3lib_extMgm::
neu
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::
tt_news
fileupload maxFileSize für Medien im Artikel erstellen hochsetzen
z.B: 50 MB
typo3conf/ext/EXTENSIONNAME/ext_tables.php
// tt_news
$GLOBALS['TCA']['tt_news']['columns']['news_files']['config']['max_size'] = 500000;
// This changes the upload limit for image elements
$GLOBALS['TCA']['tt_content']['columns']['image']['config']['max_size'] = 500000;
// This changes the upload limit for media elements
$GLOBALS['TCA']['tt_content']['columns']['media']['config']['max_size'] = 500000;
// This changes the upload limit for multimedia elements
$GLOBALS['TCA']['tt_content']['columns']['multimedia']['config']['max_size'] = 500000;
flexform
Display Condition
Flexformfelder nur im bestimten Kontext anzeigen.
<el>
<switchableControllerActions>
<TCEforms>
<label>Select function</label>
<config>
<type>select</type>
<items>
<numIndex index="0">
<numIndex index="0">Testcontroller anzeigen</numIndex>
<numIndex index="1">Testcontroller->list</numIndex>
</numIndex>
....
<settings.test>
<TCEforms>
<label>Test</label>
<displayCond>FIELD:switchableControllerActions:=:Testcontroller->list</displayCond>
<config>
<type>input</type>
<size>20</size>
<max>120</max>
<eval>trim</eval>
</config>
</TCEforms
Andere Beispiel mit AND und OR
<feld1>
<TCEforms>
<label>Feld 1</label>
<config>
<type>input</type>
<size>30</size>
</config>
</TCEforms>
</feld1>
<feld2>
<TCEforms>
<label>Feld 2</label>
<config>
<type>input</type>
<size>30</size>
</config>
</TCEforms>
</feld2>
<cond>
<TCEforms>
<label>Teste Bedingung</label>
<displayCond>
<AND>
<numIndex index="0">FIELD:feld1:REQ:TRUE</numIndex>
<numIndex index="1">FIELD:feld2:REQ:TRUE</numIndex>
<OR>
<numIndex index="0"><![CDATA[FIELD:feld1:<:12]]></numIndex>
<numIndex index="1">FIELD:feld2:>:20</numIndex>
</OR>
</AND>
</displayCond>
<config>
<type>input</type>
<size>30</size>
</config>
</TCEforms>
</cond>
https://jweiland.net/typo3/codebeispiele/extension-programmierung/displaycond.html