TYPO3 CMS  TYPO3_8-7
AjaxWidgetContextHolder.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
25 {
32  protected $widgetContexts = [];
33 
37  protected $widgetContextsStorageKey = 'TYPO3\\CMS\\Fluid\\Core\\Widget\\AjaxWidgetContextHolder_widgetContexts';
38 
42  public function __construct()
43  {
44  $this->loadWidgetContexts();
45  }
46 
50  protected function loadWidgetContexts()
51  {
52  if (TYPO3_MODE === 'FE') {
53  $this->widgetContexts = unserialize($GLOBALS['TSFE']->fe_user->getKey('ses', $this->widgetContextsStorageKey));
54  } else {
55  $this->widgetContexts = unserialize($GLOBALS['BE_USER']->uc[$this->widgetContextsStorageKey]);
56  $GLOBALS['BE_USER']->writeUC();
57  }
58  }
59 
66  public function get($ajaxWidgetId)
67  {
68  if (!isset($this->widgetContexts[$ajaxWidgetId])) {
69  throw new \TYPO3\CMS\Fluid\Core\Widget\Exception\WidgetContextNotFoundException('No widget context was found for the Ajax Widget Identifier "' . $ajaxWidgetId . '". This only happens if AJAX URIs are called without including the widget on a page.', 1284793775);
70  }
71  return $this->widgetContexts[$ajaxWidgetId];
72  }
73 
80  public function store(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext $widgetContext)
81  {
82  $ajaxWidgetId = md5(uniqid(mt_rand(), true));
83  $widgetContext->setAjaxWidgetIdentifier($ajaxWidgetId);
84  $this->widgetContexts[$ajaxWidgetId] = $widgetContext;
85  $this->storeWidgetContexts();
86  }
87 
91  protected function storeWidgetContexts()
92  {
93  if (TYPO3_MODE === 'FE') {
94  $GLOBALS['TSFE']->fe_user->setKey('ses', $this->widgetContextsStorageKey, serialize($this->widgetContexts));
95  $GLOBALS['TSFE']->fe_user->storeSessionData();
96  } else {
97  $GLOBALS['BE_USER']->uc[$this->widgetContextsStorageKey] = serialize($this->widgetContexts);
98  $GLOBALS['BE_USER']->writeUc();
99  }
100  }
101 }
store(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext $widgetContext)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']