TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
AjaxWidgetContextHolder.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\Core\Widget;
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 
52  protected function loadWidgetContexts()
53  {
54  if (TYPO3_MODE === 'FE') {
55  $this->widgetContexts = unserialize($GLOBALS['TSFE']->fe_user->getKey('ses', $this->widgetContextsStorageKey));
56  } else {
57  $this->widgetContexts = unserialize($GLOBALS['BE_USER']->uc[$this->widgetContextsStorageKey]);
58  $GLOBALS['BE_USER']->writeUC();
59  }
60  }
61 
68  public function get($ajaxWidgetId)
69  {
70  if (!isset($this->widgetContexts[$ajaxWidgetId])) {
71  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);
72  }
73  return $this->widgetContexts[$ajaxWidgetId];
74  }
75 
83  public function store(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext $widgetContext)
84  {
85  $ajaxWidgetId = md5(uniqid(mt_rand(), true));
86  $widgetContext->setAjaxWidgetIdentifier($ajaxWidgetId);
87  $this->widgetContexts[$ajaxWidgetId] = $widgetContext;
88  $this->storeWidgetContexts();
89  }
90 
96  protected function storeWidgetContexts()
97  {
98  if (TYPO3_MODE === 'FE') {
99  $GLOBALS['TSFE']->fe_user->setKey('ses', $this->widgetContextsStorageKey, serialize($this->widgetContexts));
100  $GLOBALS['TSFE']->fe_user->storeSessionData();
101  } else {
102  $GLOBALS['BE_USER']->uc[$this->widgetContextsStorageKey] = serialize($this->widgetContexts);
103  $GLOBALS['BE_USER']->writeUc();
104  }
105  }
106 }
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
store(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext $widgetContext)