DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

Administration

Base syntax

Contexts are defined using TypoScript. This is convenient because contexts need to be inherited along the page tree. The syntax is the following:

config.tx_context.foo = bar

When the context is loaded this will create an entry in the context array with the key "foo" and the value "bar". Contexts can be retrieved using expressions, in any extension that supports expressions. The contexts are loaded in the extra data of the expressions parser. Thus to retrieve a value from the context you would use a syntax like:

extra:foo

This will return "bar".

Extended syntax

It is meant for contexts to be able to reference a record from some table. For this contexts support the following syntax:

config.tx_context.newscat = sys_category:3

This means that the context's entry value is 3, but it's actually the system category with uid = 3.

When the context is loaded (in particular into the expression parser's extra data) the part with the table name is stripped. So the following expression:

extra:newscat

will return "3".

This extended syntax is meant to be used in the future BE module so that users could select a table and then a record from that table and this would create a context entry. The table name would be written in the context, so that it can be retrieved upon editing.

This extended syntax can already be used when creating references to database values, just to make it clear to what table it is related, even if there's no helper BE module.

Developer information

By default contexts are loaded only into the extra data of the expressions parser. However a hook is available to load the context into something else. Hook usage should be registered using:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['context']['contextStorage'][] = '...';

The designated class must implement the \Cobweb\Context\ContextStorageInterface interface which consists of a single method:

storeContext
This receives the context as an array of key-value pairs. It is not expected to return anything.

API

Class \Cobweb\Context\ContextLoader offers a method for directly getting a context value. Given a context like:

config.tx_context.foo.pid = 42

this value could be retrieved in PHP with the simple call:

try {
        $value = \Cobweb\Context\ContextLoader::getContextValue('foo|pid');
}
catch (Exception $e) {
        // Do something with the exception
}

Note

Don't use dots in the arguments passed in the call (as would be usual with values coming from TypoScript), i.e. in the example above it is foo|pid and not foo.|pid.

The getContextValue() method will throw an exception if the requested value is not found, so any call to it should be wrapped in a try/catch block.