/** * Model 'related' sidebar * * @param SidebarController $sidebar * @param DataObject $model * @param array $whitelist only show actions with these names in the related sidebar */ protected function sidebarRelatedItems(SidebarController $sidebar, DataObject $model, $whitelist = NULL) { $sidebarlist = array(); // need to get the module name from the controller name $action_name = array('new' => 'new'); foreach ($model->getLinkRules() as $name => $hasmany) { if (method_exists($this, $name)) { $controller_name = $this->name; $action_name['link'] = $name; $field = $hasmany['field']; } elseif (method_exists($this, 'view' . $name)) { $controller_name = $this->name; $action_name['link'] = 'view' . $name; $field = $hasmany['field']; } elseif (method_exists($this, 'view_' . $name)) { $controller_name = $this->name; $action_name['link'] = 'view_' . $name; $field = $hasmany['field']; } else { $controller_name = $hasmany['do'] . 's'; $action_name['link'] = 'view_' . strtolower(str_replace(' ', '_', $model->getTitle())); $field = $hasmany['fkfield']; } $link = array(); foreach ($hasmany['actions'] as $action) { if (!is_null($whitelist) && !in_array($name, $whitelist)) { continue; } if ($action == 'new') { $controller_name = $hasmany['do'] . 's'; $field = $hasmany['fkfield']; } $modules = isset($hasmany['modules'][$action]) ? $hasmany['modules'][$action] : $this->_modules; if (isset($hasmany['newtab'][$action])) { $link[$action] = array('modules' => $modules, 'controller' => $controller_name, 'action' => strtolower($action_name[$action]), $field => $model->{$model->idField}, 'newtab' => TRUE); } else { $link[$action] = array('modules' => $modules, 'controller' => $controller_name, 'action' => strtolower($action_name[$action]), $field => $model->{$model->idField}); } } if (!empty($link)) { $sidebarlist[$name] = array_merge(array('tag' => isset($hasmany['label']) ? $hasmany['label'] : 'Show ' . $name), $link); } } $sidebar->addList('related_items', $sidebarlist); }