Contao\Session::setData PHP Method

setData() public method

Set the session data from an array
public setData ( array $arrData )
$arrData array The session data
    public function setData($arrData)
    {
        if (!is_array($arrData)) {
            throw new \Exception('Array required to set session data');
        }
        // Map the referer (see #281)
        foreach ($this->mappedKeys as $strKey) {
            if (isset($data[$strKey])) {
                $this->session->set($strKey, $data[$strKey]);
                unset($data[$strKey]);
            }
        }
        $this->sessionBag->replace($arrData);
    }

Usage Example

 /**
  * Restrict content element ids.
  *
  * @param array $allowedElements List of allowed elements.
  * @param int   $contentId       The id of the current content element.
  *
  * @return void
  * @throws AccessDeniedException When an invalid content element type is accessed.
  */
 private function restrictIds($allowedElements, $contentId)
 {
     $session = $this->session->getData();
     $allowedElements = ArrayUtil::flatten($allowedElements);
     // Set allowed content element IDs (edit multiple)
     if (!empty($session['CURRENT']['IDS']) && is_array($session['CURRENT']['IDS'])) {
         $session['CURRENT']['IDS'] = $this->filterIds($session['CURRENT']['IDS'], $allowedElements);
     }
     // Set allowed clipboard IDs
     if (!empty($session['CLIPBOARD']['tl_content']['id'])) {
         $session['CLIPBOARD']['tl_content']['id'] = $this->filterIds((array) $session['CLIPBOARD']['tl_content']['id'], $allowedElements, 'sorting');
     }
     // Overwrite session
     $this->session->setData($session);
     $this->guardAllowedAccess($allowedElements, $contentId);
 }