1ScreenContext
2=============
3To add or modify context-sensitive elements to the GlobalScreen, the respective `ScreenContextAwareProviders` must be able to decide whether or not they want to contribute to the current location where a user is in ILIAs. Therefore all these providers provide a collection to `ScreenContext` in which they are generally interested:
4
5The following example is interested in the two `ScreenContext` 'repository' and 'desktop'. In all other contexts the provider is not requested at all.
6
7```php
8class MyFancyToolProvider extends AbstractDynamicToolProvider implements ScreenContextAwareProvider
9{
10
11    ...
12
13    public function isInterestedInContexts() : ContextCollection
14    {
15        return $this->context_collection->main()->repository()->desktop();
16    }
17    ...
18
19```
20
21All available contexts can be seen here: `src/GlobalScreen/ScreenContext/ContextRepository.php`
22
23## Claiming
24`ScreenContext` are used at certain places in ILIAS, this can only be done once per context. All previously available `ScreenContext` are already claimed in ILIAS, e.g:
25
26```php
27class ilRepositoryGUI
28{
29    ...
30    function __construct()
31    {
32        ...
33        $this->tool_context = $DIC->globalScreen()->tool()->context();
34        ...
35    }
36    ...
37    function executeCommand()
38    {
39        ...
40        $this->tool_context->claim()->repository();
41        ...
42    }
43}
44```
45
46## Enter data into the ScreenContext
47Since a `ScreenContextAwareProvider` cannot only decide on the basis of the currently set contexts in order to display a tool, for example, or not, `ScreenContext` can be provided with any additional data:
48
49```php
50class ilMediaPoolPresentationGUI
51{
52    ...
53    public function __construct()
54    {
55        ...
56        $DIC->globalScreen()->tool()->context()->current()->addAdditionalData(ilMediaPoolGSToolProvider::SHOW_FOLDERS_TOOL, true);
57        ...
58    }
59
60```
61
62All currently claimed contexts with all additional data will then be provided by the provider when the content is retrieved and the provider can granularly decide whether something should be done on the GlobalScreen or not.
63
64This value can then be used, for example, when creating a tool:
65
66```php
67    public function getToolsForContextStack(CalledContexts $called_contexts) : array
68    {
69        ...
70        $additional_data = $called_contexts->getLast()->getAdditionalData();
71        if ($additional_data->exists(self::SHOW_FOLDERS_TOOL) && $additional_data->get(self::SHOW_FOLDERS_TOOL) === true) {
72           ...
73        }
74        ...
75    }
76```
77