HTTP\TabState
Templating
Global Functions
Website
\Components\Website\Designs \Components\Website\Media \Components\Website\Pages \Components\Website\Pages\Forms \Components\Website\Posts \Components\Website\Posts\Categories
Customers
\Components\Customers\Contacts \Components\Customers\Contacts\Relationships \Components\Customers\Contacts\Relationships\Types \Components\Customers\Groups
Marketing
\Components\Marketing\EmailMarketing \Components\Marketing\Events \Components\Marketing\Events\Attendees \Components\Marketing\Events\Categories \Components\Marketing\Events\Locations \Components\Marketing\Events\Recurring \Components\Marketing\Events\Recurring\Rules \Components\Marketing\SMSMarketing
Commerce
\Components\Commerce\Carts \Components\Commerce\Carts\Current \Components\Commerce\Discounts \Components\Commerce\Products \Components\Commerce\Products\Brands \Components\Commerce\Products\Categories \Components\Commerce\Products\Inventory \Components\Commerce\RecurringSales\Items \Components\Commerce\Sales \Components\Commerce\Sales\Items \Components\Commerce\Sales\Receipts \Components\Commerce\Sales\Receipts\Allocations
Settings
\Components\Settings\Administrators \Components\Settings\CustomFields \Components\Settings\Domains
Other Apps
\Components\Website\Comments \Components\Commerce\Affiliates \Components\Commerce\Affiliates\Administrators \Components\Commerce\Affiliates\Commissions \Components\Commerce\Affiliates\Payments \Components\Commerce\RecurringSales \Components\Commerce\RecurringSales\StoredCards
Framework
\Framework\Caching \Framework\Data\Util \Framework\DOM\CurrentContext \Framework\HTML\Converters \Framework\HTTP\Cookies \Framework\HTTP\Redirection \Framework\HTTP\Request \Framework\HTTP\Session \Framework\HTTP\TabState
METHODS
\Framework\HTTP\UserAgent \Framework\I18N\CompanyTypes \Framework\I18N\Countries \Framework\I18N\Languages

TabState

Browser-tab scoped session state

Session array values that can differ per browser tab (a list page's filters, for example).
The tab id is minted by tabstate.js and kept in the tab's sessionStorage; AJAX requests send it as the X-Oncord-Tab header and page loads carry the oncord_tab cookie, which the script keeps pointed at the tab the next page request will come from.

Reads resolve the tab's copy first. A key the tab has never seen is copied in from the shared array at that moment (an unset key is pinned as unset), so a tab keeps showing what it displayed even after another tab changes the same key. Writes update both the tab's copy and the shared array - the shared array is what a new tab starts from. Without a (valid) tab id every method acts on the shared array only, which is the pre-tab behaviour.

A brand-new tab's first page is attributed to another tab (the cookie's), so every value a page render resolves is also echoed into the page as window.oncordTabStateRendered; tabstate.js posts that snapshot back (adopt()) when it finds the tab is new. The snapshot is what the page showed, so neither a change in the other tab while the request is in flight nor a cookie that has moved on by the time the script runs can leak into the new tab.

Each tab's copy is its own top-level session key (<array>:tab:<id>) because Session::write() merges per top-level key: concurrent tabs must not write the same key.

Methods

Invoke via \Framework\HTTP\TabState::method()
Click a method name to copy it.
- ` bool adopt($arrRendered) `
Writes the values a page displayed into the requesting tab

Posted by tabstate.js from a tab that has just found out it is new (or a duplicate): its first page was rendered as another tab, and this is what that page showed. Keys the tab already holds are kept.
Parameters:
- $arrRendered
mixed
Return
Whether anything was adopted
- ` mixed getArrayValue($strArrayKey, $strKey) `
Gets an array value for this tab
Parameters:
- $strArrayKey
mixed
- $strKey
mixed
Return
mixed
- ` bool getArrayValueIsSet($strArrayKey, $strKey) `
Returns whether an array value is set for this tab
Parameters:
- $strArrayKey
mixed
- $strKey
mixed
Return
bool
- ` string|null getTabId() `
Returns the requesting browser tab's id, or null when the request carries none
Return
string|null
- ` void setArrayValue($strArrayKey, $strKey, $mixedValue) `
Sets an array value for this tab and as the shared default for new tabs
Parameters:
- $strArrayKey
mixed
- $strKey
mixed
- $mixedValue
mixed