Skip to content

CFM-274_Breadcrumps_fixes #171

merged 6 commits into from Mar 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix breadcrumps failing when trying to add new MVEA
Ioannis committed Mar 12, 2024
commit 482d705ca62612a392c8f1c2386432412f9e65f7
16 changes: 9 additions & 7 deletions app/src/Controller/Component/BreadcrumbComponent.php
@@ -181,26 +181,27 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa

if(!empty($link->plugin)) {
// eg: "CoreEnroller.AttributeCollectors"
$modelPath = $link->plugin . "." . $modelsName;
$modelPath = $link->plugin . '.' . $modelsName;
}

// Construct the get<Request Action>Contains function name
$requestAction = $this->getController()->getRequest()->getParam('action');
$mappedRequestAction = $requestAction;
// 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
// action to fall back 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';
$mappedRequestAction = ( isset($permissionsArray['edit']) && $permissionsArray['edit'] ) ? 'edit' : 'view';
} else {
$requestAction = 'index';
$mappedRequestAction = 'index';
}
}
$containsList = "get" . ucfirst($requestAction) . "Contains";
$containsList = 'get' . ucfirst($mappedRequestAction) . 'Contains';

$linkTable = TableRegistry::getTableLocator()->get($modelPath);
$contain = method_exists($linkTable, $containsList) ? $linkTable->$containsList() : [];
@@ -236,8 +237,9 @@ public function injectPrimaryLink(object $link, bool $index=true, string $linkLa

// Find the allowed action
$breadcrumbAction = method_exists($linkObj, 'isReadOnly') ?
($linkObj->isReadOnly() ? 'view' : 'edit') :
'edit';
($linkObj->isReadOnly() ? 'view' : $mappedRequestAction) :
$mappedRequestAction;


// The action in the following injectParents dictates the action here
[$title,,] = StringUtilities::entityAndActionToTitle($linkObj, $modelPath, $breadcrumbAction);
6 changes: 5 additions & 1 deletion app/src/Lib/Util/StringUtilities.php
@@ -180,7 +180,11 @@ public static function entityAndActionToTitle($entity,
}

// Add/Edit/View
if(method_exists($linkTable, 'generateDisplayField')) {
// The MVEA Models have a entityId. The one from the parent model.
// We need to have a condition for this and exclude it.
if($entity->id !== null
&& $action != 'add'
&& method_exists($linkTable, 'generateDisplayField')) {
// We don't use a trait for this since each table will implement different logic

$title = __d($domain, $msgId, $linkTable->generateDisplayField($entity));