public function newDashletAction() { $form = new DashletForm(); $this->createTabs(); $dashboard = $this->dashboard; $form->setDashboard($dashboard); if ($this->_request->getParam('url')) { $params = $this->_request->getParams(); $params['url'] = rawurldecode($this->_request->getParam('url')); $form->populate($params); } $action = $this; $form->setOnSuccess(function (Form $form) use($dashboard, $action) { try { $pane = $dashboard->getPane($form->getValue('pane')); } catch (ProgrammingError $e) { $pane = new Dashboard\Pane($form->getValue('pane')); $pane->setUserWidget(); $dashboard->addPane($pane); } $dashlet = new Dashboard\Dashlet($form->getValue('dashlet'), $form->getValue('url'), $pane); $dashlet->setUserWidget(); $pane->addDashlet($dashlet); $dashboardConfig = $dashboard->getConfig(); try { $dashboardConfig->saveIni(); } catch (Exception $e) { $action->view->error = $e; $action->view->config = $dashboardConfig; $action->render('error'); return false; } Notification::success(t('Dashlet created')); return true; }); $form->setTitle($this->translate('Add Dashlet To Dashboard')); $form->setRedirectUrl('dashboard'); $form->handleRequest(); $this->view->form = $form; }
/** * @return bool */ private function loadUserDashboards() { try { $config = Config::fromIni($this->getConfigFile()); } catch (NotReadableError $e) { return; } if (!count($config)) { return false; } $panes = array(); $dashlets = array(); foreach ($config as $key => $part) { if (strpos($key, '.') === false) { if ($this->hasPane($part->title)) { $panes[$key] = $this->getPane($part->title); } else { $panes[$key] = new Pane($key); $panes[$key]->setTitle($part->title); } $panes[$key]->setUserWidget(); if ((bool) $part->get('disabled', false) === true) { $panes[$key]->setDisabled(); } } else { list($paneName, $dashletName) = explode('.', $key, 2); $part->pane = $paneName; $part->dashlet = $dashletName; $dashlets[] = $part; } } foreach ($dashlets as $dashletData) { $pane = null; if (array_key_exists($dashletData->pane, $panes) === true) { $pane = $panes[$dashletData->pane]; } elseif (array_key_exists($dashletData->pane, $this->panes) === true) { $pane = $this->panes[$dashletData->pane]; } else { continue; } $dashlet = new DashboardDashlet($dashletData->title, $dashletData->url, $pane); if ((bool) $dashletData->get('disabled', false) === true) { $dashlet->setDisabled(true); } $dashlet->setUserWidget(); $pane->addDashlet($dashlet); } $this->mergePanes($panes); return true; }