ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
AddNewItemGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
32 {
33  private \ilLanguage $lng;
34  private \ilObjectDefinition $obj_definition;
35  private \ilSetting $settings;
36  private \ilAccessHandler $access;
37  private \ilCtrl $ctrl;
38  private \ilToolbarGUI $toolbar;
39  private \ilGlobalTemplateInterface $tpl;
40 
43 
48  public function __construct(
49  private array $elements = []
50  ) {
51  global $DIC;
52 
53  $this->lng = $DIC['lng'];
54  $this->toolbar = $DIC['ilToolbar'];
55  $this->tpl = $DIC['tpl'];
56 
57  $this->ui_factory = $DIC['ui.factory'];
58  $this->ui_renderer = $DIC['ui.renderer'];
59 
60  $this->lng->loadLanguageModule('wsp');
61  $this->lng->loadLanguageModule('rep');
62  $this->lng->loadLanguageModule('cntr');
63  }
64 
68  public function render(): void
69  {
70  if ($this->elements === []) {
71  return;
72  }
73  $modal = $this->ui_factory->modal()->roundtrip(
74  $this->lng->txt('cntr_add_new_item'),
75  $this->ui_factory->menu()->drilldown(
76  $this->lng->txt('object_list'),
77  $this->buildAddNewItemsMenu($this->elements)
78  )
79  );
80 
81  $this->toolbar->addComponent(
82  $this->ui_factory->button()->primary(
83  $this->lng->txt('cntr_add_new_item'),
84  $modal->getShowSignal()
85  )
86  );
87  $this->tpl->setVariable(
88  'IL_OBJECT_ADD_NEW_ITEM_MODAL',
89  $this->ui_renderer->render($modal)
90  );
91  }
92 
96  private function buildAddNewItemsMenu(array $elements): ?array
97  {
98  $sub_menu = [];
99 
100  foreach ($elements as $element) {
101  if ($element->getType() === AddNewItemElementTypes::Group) {
102  $sub_menu[] = $this->ui_factory->menu()->sub(
103  $element->getLabel(),
104  $this->buildAddNewItemsMenu($element->getSubElements())
105  );
106  }
107  if ($element->getType() === AddNewItemElementTypes::Object) {
108  $sub_menu[] = $this->ui_factory->link()->bulky(
109  $element->getIcon(),
110  $element->getLabel(),
111  $element->getCreationUri()
112  );
113  continue;
114  }
115  }
116 
117  return $sub_menu;
118  }
119 }
global $DIC
Definition: shib_login.php:22
Render add new item selector.
render()
Add new item selection to current page incl.
__construct(private array $elements=[])