Skip to content

Commit

Permalink
Calculate injectPrimaryLink only once for Plugins, inside StandardPlu…
Browse files Browse the repository at this point in the history
…ginController

remove configuration crumb from search page
  • Loading branch information
Ioannis Igoumenos authored and Ioannis committed Jan 16, 2024
1 parent 90ad78b commit 87614cd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
60 changes: 47 additions & 13 deletions app/src/Controller/Component/BreadcrumbComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();

Expand All @@ -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,
Expand All @@ -215,27 +236,40 @@ 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');
// XXX This is a duplicate from Standard Controller. We need to globalize it.
// XXX The action in the trailing 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[] = [
// XXX We assume that edit will always be the case. The external identities are immutable. This means
// we need the view action instead of the edit one.
$this->injectParents[ $linkTable->getTable() . $linkObj->id ] = [
'target' => [
'plugin' => $link->plugin ?? null,
'controller' => $modelsName,
'action' => 'edit',
'action' => $breadcrumbAction,
$linkObj->id
],
'label' => $label
Expand Down
3 changes: 2 additions & 1 deletion app/src/Controller/DashboardsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/Controller/StandardPluggableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.)

Expand Down
3 changes: 2 additions & 1 deletion app/src/Model/Table/PeopleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public function initialize(array $config): void {
'Urls'
]);
$this->setIndexContains(['PrimaryName']);

$this->setViewContains(['PrimaryName']);

$this->setAutoViewVars([
'statuses' => [
'type' => 'enum',
Expand Down

0 comments on commit 87614cd

Please sign in to comment.