diff --git a/app/src/Controller/Component/BreadcrumbComponent.php b/app/src/Controller/Component/BreadcrumbComponent.php index 2b01f506e..5e2dc9683 100644 --- a/app/src/Controller/Component/BreadcrumbComponent.php +++ b/app/src/Controller/Component/BreadcrumbComponent.php @@ -37,6 +37,18 @@ class BreadcrumbComponent extends Component { + /* + * Breadcrump example + * COmanage Registry > Alfa Community > Configuration > External Identity Sources > Test Filesource Plugin > Configure Test Filesource Plugin + * + * Root link(prepend): COmanage Registry // Root node (link) + * CO Level Link: Alfa Community // if Current CO is defined (link) + * configuration: Configuration // Configuration breadcrumb (link) + * path: Parent // Render the path from dashboard (link) + * Title Links: + * Page Title: Title // e.g. Configure Test Filesource Plugin (string) + */ + // Configuration provided by the controller // Don't render any breadcrumbs protected $skipAllPaths = []; @@ -45,6 +57,11 @@ class BreadcrumbComponent extends Component // Don't render the parent links protected $skipParentPaths = []; // Inject parent links (these render before the index link, if set) + // The parent links are constructed as part of the injectPrimaryLink function. This in the StandardController as well + // as in the StandardPluginController, MVEAController, ProvisioningHistoryRecordController, etc. These controllers are + // a descendant from the StandardController we will calculate the Parents twice. In order to avoid duplicates the + // injectParents table has to be an associative array. The uniqueness of the key will preserve the uniqueness of the parent + // path while the order of firing will create the correct breadcumb path order protected $injectParents = []; // Inject title links (immediately before the title breadcrumb) protected $injectTitleLinks = []; @@ -165,7 +182,8 @@ public function freezeParents() { * @param string $linkLabel Label to use for Primary Link instead of displayField */ - public function injectPrimaryLink(object $link, bool $index=true, $linkLabel=null) { + public function injectPrimaryLink(object $link, bool $index=true, $linkLabel=null): void + { if($this->parentsFrozen) { return; } @@ -179,10 +197,13 @@ public function injectPrimaryLink(object $link, bool $index=true, $linkLabel=nul $modelPath = $link->plugin . "." . $modelsName; } - $contain = []; - $primaryName = null; + // Construct the Contains get function name + $requestAction = $this->getController()->getRequest()->getParam('action'); + $containsList = "get" . ucfirst($requestAction) . "Contains"; $linkTable = TableRegistry::getTableLocator()->get($modelPath); + $contain = method_exists($linkTable, $containsList) ? $linkTable->$containsList() : []; + $linkObj = $linkTable->get($link->value, ['contain' => $contain]); $displayField = $linkTable->getDisplayField(); @@ -195,7 +216,7 @@ public function injectPrimaryLink(object $link, bool $index=true, $linkLabel=nul $parentLink = $linkTable->findPrimaryLink($linkObj->id); - $this->injectParents[] = [ + $this->injectParents[ $modelPath . $parentLink->value] = [ 'target' => [ 'plugin' => $parentLink->plugin ?? null, 'controller' => $modelsName, @@ -215,27 +236,37 @@ public function injectPrimaryLink(object $link, bool $index=true, $linkLabel=nul $label = $linkLabel ?? $linkObj->$displayField; - if($modelsName == 'People' || $modelsName == 'ExternalIdentities') { - // We need the Primary Name (or first name found) to render it + // Find the allowed action + $breadcrumbAction = method_exists($linkObj, 'isReadOnly') ? + ($linkObj->isReadOnly() ? 'view' : 'edit') : + 'edit'; - $Names = TableRegistry::getTableLocator()->get('Names'); + // The action in the following injectParents dictates the action here + if(method_exists($linkTable, 'generateDisplayField')) { + // We don't use a trait for this since each table will implement different logic - // This will throw an error on failure - $primaryName = $Names->primaryName($linkObj->id, Inflector::underscore(Inflector::singularize($modelsName))); - - $label = $primaryName->full_name; + $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])); + } } // If we don't have a visible label use the record ID if(empty($label)) { $label = $linkObj->id; } - - $this->injectParents[] = [ + + $this->injectParents[ $linkTable->getTable() . $linkObj->id ] = [ 'target' => [ 'plugin' => $link->plugin ?? null, 'controller' => $modelsName, - 'action' => 'edit', + 'action' => $breadcrumbAction, $linkObj->id ], 'label' => $label diff --git a/app/src/Controller/DashboardsController.php b/app/src/Controller/DashboardsController.php index 89ec5c8f7..5c66ae07e 100644 --- a/app/src/Controller/DashboardsController.php +++ b/app/src/Controller/DashboardsController.php @@ -50,7 +50,8 @@ public function initialize(): void { $this->Breadcrumb->skipConfig([ '/^\/dashboards\/artifacts/', '/^\/dashboards\/dashboard/', - '/^\/dashboards\/registries/' + '/^\/dashboards\/registries/', + '/^\/dashboards\/search/' ]); // There is currently no inventory of dashboards, so we skip parents // for configuration, dashboard, and registries actions diff --git a/app/src/Controller/StandardPluggableController.php b/app/src/Controller/StandardPluggableController.php index 0fb8234b7..e8f33c287 100644 --- a/app/src/Controller/StandardPluggableController.php +++ b/app/src/Controller/StandardPluggableController.php @@ -42,7 +42,7 @@ class StandardPluggableController extends StandardController { */ public function configure(string $id) { - // We basically implement a redirect here to faciliate view rendering. + // We basically implement a redirect here to facilitate view rendering. // (We only need to map into the plugin on actual link click, instead of // potentially many times on an index view for links that may not be used.) diff --git a/app/src/Model/Table/PeopleTable.php b/app/src/Model/Table/PeopleTable.php index 98b44a90a..b4a6527fd 100644 --- a/app/src/Model/Table/PeopleTable.php +++ b/app/src/Model/Table/PeopleTable.php @@ -145,7 +145,8 @@ public function initialize(array $config): void { 'Urls' ]); $this->setIndexContains(['PrimaryName']); - + $this->setViewContains(['PrimaryName']); + $this->setAutoViewVars([ 'statuses' => [ 'type' => 'enum',