Commit f3401aa5 authored by Baudouin Feildel's avatar Baudouin Feildel

Merge branch 'empty-panel-item-object' into 'master'

Meilleure gestion des éléments JSON invalides dans les blocs des menus

See merge request !4
parents e5725846 c2c237be
Pipeline #1137 passed with stage
in 1 minute and 26 seconds
......@@ -22,3 +22,5 @@
.idea/workspace.xml
.idea/dataSources*
.idea/httpRequests
version.json
......@@ -42,18 +42,33 @@ class Panel
$this->search_enabled = false;
if(is_object($info)) {
$this->title = $info->title;
$nbrItems = count($info->items);
$this->items = new TArray($nbrItems);
for ($i = 0; $i < $nbrItems; $i++)
$this->items[$i] = new PanelItem(
$info->items[$i]->name,
$info->items[$i]->url,
isset($info->items[$i]->openInNewTab) ? $info->items[$i]->openInNewTab : true
);
} else if(is_string($info)) {
$this->title = $info->title;
$nbrItems = count($info->items);
$this->items = new TArray($nbrItems);
for ($i = 0; $i < $nbrItems; $i++) {
$nameSet = isset($info->items[$i]->name);
$urlSet = isset($info->items[$i]->url);
$openInNewTabSet = isset($info->items[$i]->openInNewTab);
if ($nameSet && $urlSet) {
$this->items[$i] = new PanelItem(
$info->items[$i]->name,
$info->items[$i]->url,
$openInNewTabSet ? $info->items[$i]->openInNewTab : true
);
} else if (!$nameSet && $urlSet) {
throw new InvalidArgumentException('In panel "' . $this->title . '", item ' . ($i + 1) . ' is missing mandatory field "name".');
} else if ($nameSet && !$urlSet) {
throw new InvalidArgumentException('In panel "' . $this->title . '", item ' . ($i + 1) . ' is missing mandatory field "url".');
} else if (!$nameSet && !$urlSet && $openInNewTabSet) {
throw new InvalidArgumentException('In panel "' . $this->title . '", item ' . ($i + 1) . ' is missing mandatory fields "name" and "url".');
} else {
// None of the expected field is set, we assume the node is empty and we skip it
continue;
}
}
} else if(is_string($info)) {
$this->title = $info;
$this->items = new TArray(0);
} else if($info === null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment