Contao\Ajax::executePreActions PHP 메소드

executePreActions() 공개 메소드

Ajax actions that do not require a data container object
public executePreActions ( )
    public function executePreActions()
    {
        /** @var AttributeBagInterface $objSessionBag */
        $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
        switch ($this->strAction) {
            // Toggle navigation menu
            case 'toggleNavigation':
                $bemod = $objSessionBag->get('backend_modules');
                $bemod[\Input::post('id')] = intval(\Input::post('state'));
                $objSessionBag->set('backend_modules', $bemod);
                throw new NoContentResponseException();
                // Load a navigation menu group
            // Load a navigation menu group
            case 'loadNavigation':
                $bemod = $objSessionBag->get('backend_modules');
                $bemod[\Input::post('id')] = intval(\Input::post('state'));
                $objSessionBag->set('backend_modules', $bemod);
                $this->import('BackendUser', 'User');
                /** @var BackendTemplate|object $objTemplate */
                $objTemplate = new \BackendTemplate('be_navigation');
                $navigation = $this->User->navigation();
                $objTemplate->modules = $navigation[\Input::post('id')]['modules'];
                throw new ResponseException($objTemplate->getResponse());
                // Toggle nodes of the file or page tree
            // Toggle nodes of the file or page tree
            case 'toggleStructure':
            case 'toggleFileManager':
            case 'togglePagetree':
            case 'toggleFiletree':
                $this->strAjaxId = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', \Input::post('id'));
                $this->strAjaxKey = str_replace('_' . $this->strAjaxId, '', \Input::post('id'));
                if (\Input::get('act') == 'editAll') {
                    $this->strAjaxKey = preg_replace('/(.*)_[0-9a-zA-Z]+$/', '$1', $this->strAjaxKey);
                    $this->strAjaxName = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', \Input::post('name'));
                }
                $nodes = $objSessionBag->get($this->strAjaxKey);
                $nodes[$this->strAjaxId] = intval(\Input::post('state'));
                $objSessionBag->set($this->strAjaxKey, $nodes);
                throw new NoContentResponseException();
                // Load nodes of the file or page tree
            // Load nodes of the file or page tree
            case 'loadStructure':
            case 'loadFileManager':
            case 'loadPagetree':
            case 'loadFiletree':
                $this->strAjaxId = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', \Input::post('id'));
                $this->strAjaxKey = str_replace('_' . $this->strAjaxId, '', \Input::post('id'));
                if (\Input::get('act') == 'editAll') {
                    $this->strAjaxKey = preg_replace('/(.*)_[0-9a-zA-Z]+$/', '$1', $this->strAjaxKey);
                    $this->strAjaxName = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', \Input::post('name'));
                }
                $nodes = $objSessionBag->get($this->strAjaxKey);
                $nodes[$this->strAjaxId] = intval(\Input::post('state'));
                $objSessionBag->set($this->strAjaxKey, $nodes);
                break;
                // Toggle the visibility of a fieldset
            // Toggle the visibility of a fieldset
            case 'toggleFieldset':
                $fs = $objSessionBag->get('fieldset_states');
                $fs[\Input::post('table')][\Input::post('id')] = intval(\Input::post('state'));
                $objSessionBag->set('fieldset_states', $fs);
                throw new NoContentResponseException();
                // Toggle checkbox groups
            // Toggle checkbox groups
            case 'toggleCheckboxGroup':
                $state = $objSessionBag->get('checkbox_groups');
                $state[\Input::post('id')] = intval(\Input::post('state'));
                $objSessionBag->set('checkbox_groups', $state);
                break;
                // HOOK: pass unknown actions to callback functions
            // HOOK: pass unknown actions to callback functions
            default:
                if (isset($GLOBALS['TL_HOOKS']['executePreActions']) && is_array($GLOBALS['TL_HOOKS']['executePreActions'])) {
                    foreach ($GLOBALS['TL_HOOKS']['executePreActions'] as $callback) {
                        $this->import($callback[0]);
                        $this->{$callback[0]}->{$callback[1]}($this->strAction);
                    }
                }
                break;
        }
    }

Usage Example

예제 #1
0
 /**
  * Run the controller and parse the login template
  *
  * @return Response
  */
 public function run()
 {
     $packages = System::getContainer()->getParameter('kernel.packages');
     $this->Template = new \BackendTemplate('be_main');
     $this->Template->version = $packages['contao/core-bundle'];
     $this->Template->main = '';
     // Ajax request
     if ($_POST && \Environment::get('isAjaxRequest')) {
         $this->objAjax = new \Ajax(\Input::post('action'));
         $this->objAjax->executePreActions();
     }
     // Error
     if (\Input::get('act') == 'error') {
         $this->Template->error = $GLOBALS['TL_LANG']['ERR']['general'];
         $this->Template->title = $GLOBALS['TL_LANG']['ERR']['general'];
         @trigger_error('Using act=error has been deprecated and will no longer work in Contao 5.0. Throw an exception instead.', E_USER_DEPRECATED);
     } elseif (!\Input::get('do') && !\Input::get('act')) {
         $this->Template->main .= $this->welcomeScreen();
         $this->Template->title = $GLOBALS['TL_LANG']['MSC']['home'];
     } elseif (\Input::get('do')) {
         $this->Template->main .= $this->getBackendModule(\Input::get('do'));
         $this->Template->title = $this->Template->headline;
     }
     return $this->output();
 }
All Usage Examples Of Contao\Ajax::executePreActions