Skip to content

Commit

Permalink
Utility that calculates the view and breadcrump title
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Jan 26, 2024
1 parent a557a28 commit 56fd9b5
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 177 deletions.
6 changes: 0 additions & 6 deletions app/resources/locales/en_US/operation.po
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ msgstr "Edit"
msgid "edit.a"
msgstr "Edit {0}"

msgid "edit.ai"
msgstr "Edit {0}"

msgid "ExternalIdentitySourceRecords.retrieve"
msgstr "Retrieve from External Identity Source"

Expand Down Expand Up @@ -186,6 +183,3 @@ msgstr "View"
msgid "view.a"
msgstr "View {0}"

msgid "view.ai"
msgstr "View {0}"

7 changes: 6 additions & 1 deletion app/src/Controller/ApiUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

namespace App\Controller;

use App\Lib\Util\StringUtilities;

class ApiUsersController extends StandardController {
public $paginate = [
'order' => [
Expand Down Expand Up @@ -56,7 +58,10 @@ public function generate(string $id) {

// Let the view render, but tell it to use a different fields file
$this->set('vv_fields_inc', 'fields-generate.inc');
$this->set('vv_title', __d('operation', 'api.key.generate'));
[$title, , ] = StringUtilities::entityAndActionToTitle(null,
'api.key',
$this->request->getParam('action'));
$this->set('vv_title', $title);

$this->render('/Standard/add-edit-view');
}
Expand Down
32 changes: 16 additions & 16 deletions app/src/Controller/Component/BreadcrumbComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa

// Construct the get<Request Action>Contains function name
$requestAction = $this->getController()->getRequest()->getParam('action');
// In the case we are dealing with non-standard actions we need to fallback to a standard one
// in order to get access to the contain array. We will use the permissions to decide which
// action to fallback to
if(!in_array($requestAction, [
'index', 'view', 'delete', 'add', 'edit'
])) {
$permissionsArray = $this->getController()->RegistryAuth->calculatePermissionsForView($requestAction);
$id = $this->getController()->getRequest()->getParam('pass')[0] ?? null;
if (isset($id)) {
$requestAction = ( isset($permissionsArray['edit']) && $permissionsArray['edit'] ) ? 'edit' : 'view';
} else {
$requestAction = 'index';
}
}
$containsList = "get" . ucfirst($requestAction) . "Contains";

$linkTable = TableRegistry::getTableLocator()->get($modelPath);
Expand Down Expand Up @@ -226,21 +240,7 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa
'edit';

// The action in the following injectParents dictates the action here
// XXX This is a duplicate from StandardController.
if(method_exists($linkTable, 'generateDisplayField')) {
// We don't use a trait for this since each table will implement different logic

$label = __d('operation', "{$breadcrumbAction}.ai", $linkTable->generateDisplayField($linkObj));
} else {
// Default view title is edit object display field
$field = $linkTable->getDisplayField();

if(!empty($obj->$field)) {
$label = __d('operation', "{$breadcrumbAction}.ai", $obj->$field);
} else {
$label = __d('operation', "{$breadcrumbAction}.ai", __d('controller', $modelsName, [1]));
}
}
[$title,,] = StringUtilities::entityAndActionToTitle($linkObj, $modelPath, $breadcrumbAction);

$this->injectParents[ $linkTable->getTable() . $linkObj->id ] = [
'target' => [
Expand All @@ -249,7 +249,7 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa
'action' => $breadcrumbAction,
$linkObj->id
],
'label' => $linkLabel ?? $label
'label' => $linkLabel ?? $title
];
}

Expand Down
Loading

0 comments on commit 56fd9b5

Please sign in to comment.