diff --git a/app/src/Controller/StandardController.php b/app/src/Controller/StandardController.php index 4d5844905..8d5f7e6ab 100644 --- a/app/src/Controller/StandardController.php +++ b/app/src/Controller/StandardController.php @@ -260,17 +260,39 @@ public function delete($id) { $useHardDelete = ($modelsName == "Cos"); $table->deleteOrFail($obj, ['useHardDelete' => $useHardDelete]); - + $msgid = 'deleted'; + // Use the display field to generate the flash message - + // TODO: This needs to be moved to its own function. Keeping for now while we confirm + // everything is working correctly $field = $table->getDisplayField(); - - if(!empty($obj->$field)) { - $this->Flash->success(__d('result', 'deleted.a', [$obj->$field])); - } else { - $this->Flash->success(__d('result', 'deleted')); + $primaryLinks = $table->getPrimaryLinks(); + + if ($modelsName === 'People') { + $Names = TableRegistry::getTableLocator()->get('Names'); + $personName = $Names->primaryName( + id:(int)$obj->id, + options: ['archived' => true], + )->full_name; + $message = "$personName ($obj->id)"; + } elseif (in_array('person_id', $primaryLinks)) { + $Names = TableRegistry::getTableLocator()->get('Names'); + $personName = $Names->primaryName((int)$obj->person_id)->full_name; + $displayValue = !empty($obj->$field) ? $obj->$field : $modelsName; + $message = "$personName/$displayValue ($obj->id)"; + } elseif(!empty($obj->$field)) { + $displayValue = !empty($obj->$field) ? $obj->$field : $modelsName; + $message = $displayValue; } - + + // By default, we pass the empty msgid. Then one with no placeholder. + // If we have a message use the text rich one. + if (!empty($message)) { + $msgid = "$msgid.a"; + } + + $this->Flash->success(__d('result', $msgid, [$message])); + // Trigger provisioning, letting errors bubble up (AR-GMR-5) // In general, tables should check that they were passed a deleted // record and martial data/set eligibility appropriately diff --git a/app/src/Model/Table/NamesTable.php b/app/src/Model/Table/NamesTable.php index b672681c0..2d06b0e93 100644 --- a/app/src/Model/Table/NamesTable.php +++ b/app/src/Model/Table/NamesTable.php @@ -233,23 +233,23 @@ public function localAfterSave(\Cake\Event\EventInterface $event, \Cake\Datasour * @since COmanage Registry v5.0.0 * @param int $id Record ID * @param string $recordType Type of record to find primary name for, 'person' or 'external_identity' + * @param array $options * @return Name Name Entity */ - public function primaryName(int $id, string $recordType='person') { + public function primaryName(int $id, string $recordType='person', array $options = []) { + $query = empty($options) ? $this->find() : $this->find('all', $options); if($recordType == 'person') { // Return the Primary Name - return $this->find() - ->where(['person_id' => $id, + return $query->where(['person_id' => $id, 'primary_name' => true]) - ->firstOrFail(); + ->firstOrFail(); } else { // Return the first name, whatever it is - return $this->find() - ->where(['external_identity_id' => $id]) - ->firstOrFail(); + return $query->where(['external_identity_id' => $id]) + ->firstOrFail(); } }