diff --git a/app/src/Controller/CosController.php b/app/src/Controller/CosController.php index 6b52e61f0..646de9281 100644 --- a/app/src/Controller/CosController.php +++ b/app/src/Controller/CosController.php @@ -42,6 +42,21 @@ class CosController extends StandardController { ] ]; + /** + * Callback run prior to the view rendering. + * + * @since COmanage Registry v5.0.0 + * @param EventInterface $event Cake Event + */ + + public function beforeRender(\Cake\Event\EventInterface $event) { + // In order to get the sidebar to render we need to set the current CO, + // which for cos is the COmanage CO. + $this->set('vv_cur_co', $this->Cos->find('COmanageCO')->firstOrFail()); + + return parent::beforeRender($event); + } + /* * XXX implement, also REST API * diff --git a/app/src/Model/Table/CosTable.php b/app/src/Model/Table/CosTable.php index 673452a9a..816130336 100644 --- a/app/src/Model/Table/CosTable.php +++ b/app/src/Model/Table/CosTable.php @@ -164,6 +164,18 @@ public function duplicate($id) { // XXX document AR-CO-4, use TableMetaTrait to determine which tables are configuration }*/ + /** + * Find the COmanage CO. + * + * @since COmanage Registry v5.0.0 + * @param \Cake\ORM\Query $query Query + * @return \Cake\ORM\Query Query + */ + + public function findCOmanageCO(Query $query): Query { + return $query->where(['lower(name)' => 'comanage']); + } + /** * Determine if this is a Read Only record. * @@ -172,7 +184,7 @@ public function duplicate($id) { * @return boolean true if the entity is read only, false otherwise */ - public function isReadOnly($entity) { + public function isReadOnly($entity): bool { // The COmanage CO is read only return $entity->isCOmanageCO(); @@ -187,7 +199,7 @@ public function isReadOnly($entity) { * @return boolean true if the Rule check passes, false otherwise */ - public function ruleIsCOmanageCO($entity, $options) { + public function ruleIsCOmanageCO($entity, $options): bool { // We want negative logic since we want to fail if we're editing the COmanage CO if($entity->isCOmanageCO()) { return __d('error', 'edit.comanage'); @@ -205,7 +217,7 @@ public function ruleIsCOmanageCO($entity, $options) { * @return boolean true if the Rule check passes, false otherwise */ - public function ruleIsActive($entity, $options) { + public function ruleIsActive($entity, $options): bool { // We want negative logic since we want to fail if the record is Active if($entity->status == TemplateableStatusEnum::Active) { return __d('error', 'delete.active'); @@ -222,7 +234,7 @@ public function ruleIsActive($entity, $options) { * @return bool True on success */ - public function setup(int $id) { + public function setup(int $id): bool { $Types = TableRegistry::getTableLocator()->get('Types'); // AR-Type-1 Set up the default values for extended types