Commit 61dfbb44 authored by Damjan's avatar Damjan

[TASK] Session use for maintaining DDL values, adding js with view helper, BE leyout, partials

Related: forge.typo3.org/issues/31889
parent 29c445ec
<?php
Please register or sign in to reply
namespace SGalinski\LFEditor\Controller;
namespace SGalinski\Lfeditor\Controller;
/***************************************************************
* Copyright notice
......@@ -26,30 +26,31 @@ namespace SGalinski\LFEditor\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
//use SGalinski\DezShops\Domain\Model\Shop;
use SGalinski\Lfeditor\Session\PhpSession;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
* Abstract Controller
*/
abstract class AbstractController extends ActionController {
// /**
// * @var \SGalinski\DezShops\Session\PhpSession
// */
// protected $session;
//
// /**
// * Initializes the actions
// *
// * @return void
// */
// public function initializeAction() {
// parent::initializeAction();
// if (!($this->session instanceof PhpSession)) {
// $this->session = $this->objectManager->get('SGalinski\DezShops\Session\PhpSession');
// $this->session->setSessionKey('tx_dezshops_shopFilter');
// }
// }
/**
* @var \SGalinski\Lfeditor\Session\PhpSession
*/
protected $session;
/**
* Initializes the actions
*
* @return void
*/
public function initializeAction() {
parent::initializeAction();
if (!($this->session instanceof PhpSession)) {
$this->session = $this->objectManager->get('SGalinski\Lfeditor\Session\PhpSession');
$this->session->setSessionKey('Lfeditor');
  • You should use somethink like this, instead of Lfeditor as Key: | tx = A mark that extbase is in use | dezshops = The extension key without underscores | shopFilter = For what is the session key in use within the given extension. In this case it was for the filter in the shop system

  • I changed it to 'tx_lfeditor_selections'.

  • Selections of what? ;) Make it a bit more precise.

  • tx_lfeditor_menuSelections

Please register or sign in to reply
}
}
}
?>
\ No newline at end of file
<?php
namespace SGalinski\LFEditor\Controller;
namespace SGalinski\Lfeditor\Controller;
/***************************************************************
* Copyright notice
......@@ -26,46 +26,93 @@ namespace SGalinski\LFEditor\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
* Controller for general overview
*/
class MainController extends ActionController {
class MainController extends AbstractController {
/**
*
  • Here should be a description, like:

    /**
     * [What does this function]
     *
     * @param [type] [Parameter name]
     * @return [void or type]
     * @throws [Class]
    */

    Please check the other functions

  • There will be comments on all functions in the end.

Please register or sign in to reply
*/
public function generalAction() {
$this->view->assign('mainMenuSelection', 'general');
$this->loadSelectionsFromSession();
}
/**
* @param string $mainMenuSelection
* @param string $extensionSelection
* @param string $languageFileSelection
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
*/
public function mainMenuSelectAction($mainMenuSelection, $extensionSelection = NULL) {
public function generalChangeSelectionAction($extensionSelection = NULL, $languageFileSelection = NULL) {
$this->saveSelectionsInSession($extensionSelection, $languageFileSelection);
$this->redirect('general');
}
$this->redirect($mainMenuSelection, NULL, NULL, array('extensionSelection' => $extensionSelection));
/**
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
*/
public function generalSaveAction() {
//TODO: Delete. test $this->session->destroy();
$this->session->destroy();
  • Why did you destroy the session?

  • It is a test, as I commented in TODO. I was testing how will look like my selection menus (and what are values of variables) when the session is empty.

Please register or sign in to reply
$this->redirect('general');
}
/**
* @param string $extensionSelection
*
*/
public function generalAction($extensionSelection = NULL) {
$this->view->assign('mainMenuSelection', 'general');
$this->view->assign('extensionSelection', $extensionSelection);
public function editFileAction() {
$this->view->assign('mainMenuSelection', 'editFile');
$this->loadSelectionsFromSession();
}
/**
* @param string $extensionSelection
* @param string $languageFileSelection
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
*/
public function editFileAction($extensionSelection = NULL) {
debug($extensionSelection, 'extSelArg: ');
echo 'ExtSel: ' . $extensionSelection;
$this->view->assign('mainMenuSelection', 'editFile');
$this->view->assign('extensionSelection', $extensionSelection);
public function editFileChangeSelectionAction($extensionSelection = NULL, $languageFileSelection = NULL) {
$this->saveSelectionsInSession($extensionSelection, $languageFileSelection);
$this->redirect('editFile');
}
/**
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
*/
public function editFileSaveAction() {
$this->redirect('editFile');
}
/**
* Saves in session currently selected values of select tags.
*
* @param string $extensionSelection
* @param string $languageFileSelection
*/
private function saveSelectionsInSession($extensionSelection = NULL, $languageFileSelection = NULL){
  • We don't use private in our CGL, please use protected.

  • Yea, I agree that protected is better, so potential sub classes can use the method. This was auto generated by phpStorm.

Please register or sign in to reply
if($extensionSelection === 'NULL') {
$extensionSelection = NULL;
}
$this->session->setDataByKey('extensionSelection', $extensionSelection);
if($languageFileSelection === 'NULL') {
$languageFileSelection = NULL;
}
$this->session->setDataByKey('languageFileSelection', $languageFileSelection);
}
/**
* Fetches from session currently selected values of select tags and puts them in view variables.
*/
private function loadSelectionsFromSession(){
$this->view->assign('extensionSelection', $this->session->getDataByKey('extensionSelection'));
$this->view->assign('languageFileSelection', $this->session->getDataByKey('languageFileSelection'));
debug($this->session->getData(), 'ses');//TODO: debug.
}
}
?>
\ No newline at end of file
<?php
namespace SGalinski\Lfeditor\Session;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\SingletonInterface;
/**
* PHP Session handler
*/
class PhpSession implements SingletonInterface {
/**
* @var string
*/
protected $sessionKey;
/**
* Constructor
*/
public function __construct() {
session_start();
$this->sessionKey = uniqid();
}
/**
* @param string $sessionKey
* @return void
*/
public function setSessionKey($sessionKey) {
$this->sessionKey = $sessionKey;
}
/**
* Returns the current session key
*
* @return string
*/
public function getSessionKey() {
return $this->sessionKey;
}
/**
* Exchanges the complete session data
*
* @param mixed $data
* @return void
*/
public function exchangeData($data) {
$this->destroy();
$_SESSION[$this->sessionKey] = $data;
}
/**
* Returns the complete session data
*
* @return mixed
*/
public function getData() {
return $_SESSION[$this->sessionKey];
}
/**
* Sets data inside the session below the given key
*
* @param string $key
* @param mixed $data
* @return void
*/
public function setDataByKey($key, $data) {
$_SESSION[$this->sessionKey][$key] = $data;
}
/**
* Returns data of the session defined by the given key
*
* @param string $key
* @return mixed
*/
public function getDataByKey($key) {
return $_SESSION[$this->sessionKey][$key];
}
/**
* Removes all session data
*
* @return void
*/
public function destroy() {
unset($_SESSION[$this->sessionKey]);
}
}
?>
\ No newline at end of file
<?php
namespace SGalinski\LFeditor\ViewHelpers;
namespace SGalinski\Lfeditor\ViewHelpers;
/***************************************************************
* Copyright notice
......@@ -11,9 +11,6 @@ namespace SGalinski\LFeditor\ViewHelpers;
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
Please register or sign in to reply
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
......
<?php
namespace SGalinski\LFEditor\ViewHelpers;
namespace SGalinski\Lfeditor\ViewHelpers;
/***************************************************************
* Copyright notice
......@@ -30,7 +30,7 @@ namespace SGalinski\LFEditor\ViewHelpers;
* View helper to add custom css files
*
* Example:
* {namespace lfe=SGalinski\LFEditor\ViewHelpers}
* {namespace lfe=SGalinski\Lfeditor\ViewHelpers}
* <lfe:addCssFile cssFile="{f:uri.resource(path: 'StyleSheets/Frontend.css')}" />
*/
class AddCssFileViewHelper extends AbstractViewHelper {
......
<?php
namespace SGalinski\LFEditor\ViewHelpers;
namespace SGalinski\Lfeditor\ViewHelpers;
/***************************************************************
* Copyright notice
......@@ -30,7 +30,7 @@ namespace SGalinski\LFEditor\ViewHelpers;
* View helper to add custom javascript files
*
* Example:
* {namespace lfe=SGalinski\LFEditor\ViewHelpers}
* {namespace lfe=SGalinski\Lfeditor\ViewHelpers}
* <lfe:addJavaScriptFile javaScriptFile="{f:uri.resource(path: 'Scripts/Frontend.js')}" />
*/
class AddJavaScriptFileViewHelper extends AbstractViewHelper {
......
{namespace lfe=SGalinski\Lfeditor\ViewHelpers}
<lfe:addJavaScriptFile javaScriptFile="{f:uri.resource(path: 'Scripts/FormUtility.js')}" />
<f:be.container enableClickMenu="FALSE" loadPrototype="FALSE" loadExtJs="FALSE">
<div class="typo3-fullDoc">
<div id="typo3-docheader">
<f:comment>
<!--<div id="typo3-docheader-row1">-->
<!--<div class="buttonsleft">-->
<!--<f:render section="iconButtons" />-->
<!--</div>-->
<!--<div class="buttonsright">-->
<!--<f:be.buttons.shortcut />-->
<!--</div>-->
<!--</div>-->
</f:comment>
<div id="typo3-docheader-row2">
<div class="docheader-row2-left">
<f:be.menus.actionMenu>
<f:comment><!-- todo translate label {f:translate(key: 'backend.overview')}--></f:comment>
<f:be.menus.actionMenuItem label="General (translate)"
controller="Main"
action="general" />
<f:comment><!-- todo translate label {f:translate(key: 'backend.overview')}--></f:comment>
<f:be.menus.actionMenuItem label="Edit file (translate)"
controller="Main"
action="editFile" />
</f:be.menus.actionMenu>
</div>
</div>
</div>
<div id="typo3-docbody">
<div id="typo3-inner-docbody">
<f:form id="mainMenuForm" action="{mainMenuSelection}ChangeSelection">
<br><br><br><br><br><br><br><br><br><br><br><br>
<f:form.select name="extensionSelection"
value="{extensionSelection}"
options="{NULL: '--Select something--', extension1: 'Test extension 1', extension2: 'Test extension 2'}"
  • Is there a better way to make "empty" select option? Because this NULL is in controller string 'NULL', and in that case I am putting rel NULL instead of string 'NULL'. See MainController.php line 100.

  • I don't know a better way.

Please register or sign in to reply
additionalAttributes="{onchange: 'document.getElementById(\'mainMenuForm\').submit();'}"
/>
<br><br>
<br>
<f:render section="selectItems" />
</f:form>
<br><br>
<f:render section="main" />
  • Please use the PhpStorm Reformat Code function. It's under Code->Reformat Code. Please use it for all files

  • Ok. There will be one commit only with format changes.

Please register or sign in to reply
</div>
</div>
</div>
</f:be.container>
<f:comment>
<div>
This is Default layout. <br>
<f:form id="mainMenuForm" action="mainMenuSelect">
<f:form.select name="mainMenuSelection"
value="{mainMenuSelection}"
options="{ general: 'General select item', editFile: 'Edit file select item'}"
additionalAttributes="{onchange: 'document.getElementById(\'mainMenuForm\').submit();'}"
additionalAttributes="{onchange: 'submitForm(\'mainMenuForm\');'}"
/>
<f:debug title="All available variables">{_all}</f:debug>
<br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<f:render section="selectItems" />
</f:form>
<br><br>
......@@ -18,4 +78,5 @@
<!--<f:link.action action="general">General link</f:link.action>-->
<!--<br><br>-->
<f:render section="main" />
</div>
\ No newline at end of file
</div>
</f:comment>
\ No newline at end of file
<f:form.select name="languageFileSelection"
value="{languageFileSelection}"
options="{NULL: '--Select something--', lf1: 'Test lf 1', lf2: 'Test lf 2'}"
additionalAttributes="{onchange: 'document.getElementById(\'mainMenuForm\').submit();'}"
/>
<f:comment> <!-- todo Call JS function--> </f:comment>
<f:debug title="All available variables">{_all}</f:debug>
\ No newline at end of file
......@@ -3,12 +3,9 @@
<f:section name="selectItems">
This is EditFile page. Select items section.
<br>
<f:render partial="SelectLanguageFile" arguments="{_all}" />
<f:form.select name="extensionSelection"
value="{extensionSelection}"
options="{ extension1: 'Test extension 1', extension2: 'Test extension 2'}"
additionalAttributes="{onchange: 'document.getElementById(\'mainMenuForm\').submit();'}"
/>
</f:section>
......@@ -16,9 +13,8 @@
This is EditFile page. Main section.
<f:form id="contentForm" action="editFileSave">
<f:form.submit value="Save" />
<f:form.submit value="Save" /> <f:comment><!-- todo translate label {f:translate(key: 'backend.overview')}--></f:comment>
<f:form.button value="Reset" type="reset" /> <f:comment><!-- todo translate label {f:translate(key: 'backend.overview')}--></f:comment>
</f:form>
</f:section>
\ No newline at end of file
......@@ -2,10 +2,15 @@
<f:section name="selectItems">
This is General page. Select items section.
<br>
<f:render partial="SelectLanguageFile" arguments="{_all}" />
</f:section>
<f:section name="main">
This is General page. Main section.
<f:form id="contentForm" action="generalSave">
<f:form.submit value="Save" /> <f:comment><!-- todo translate label {f:translate(key: 'backend.overview')}--></f:comment>
<f:form.button value="Reset" type="reset" /> <f:comment><!-- todo translate label {f:translate(key: 'backend.overview')}--></f:comment>
</f:form>
</f:section>
\ No newline at end of file
......@@ -11,7 +11,7 @@ if (TYPO3_MODE == 'BE') {
'LFEditor',
'',
[
'Main' => 'general, mainMenuSelect, editFile, editFileSave',
'Main' => 'general, generalChangeSelection, generalSave, editFile, editFileChangeSelection, editFileSave',
],
[
'access' => 'user,group',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment