Skip to content

Commit

Permalink
Added special logic for showing redirect metadata view.
Browse files Browse the repository at this point in the history
  • Loading branch information
kepol committed Dec 2, 2023
1 parent 4d32e85 commit f10650b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/optional/views.view.quant_metadata_redirect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ display:
position: 1
display_options:
display_extenders: { }
path: admin/config/quant/metadata/redirect
path: admin/config/quant/metadata/redirectview
cache_metadata:
max-age: -1
contexts:
Expand Down
2 changes: 1 addition & 1 deletion quant.links.task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ quant.metadata_file:
weight: 30

quant.metadata_redirect:
route_name: view.quant_metadata_redirect.quant_metadata_redirect_page
route_name: quant.metadata_redirect
title: 'Redirect Metadata'
parent_id: quant.metadata
weight: 40
Expand Down
8 changes: 8 additions & 0 deletions quant.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ quant.metadata:
requirements:
_permission: 'configure quant'

quant.metadata_redirect:
path: '/admin/config/quant/metadata/redirect'
defaults:
_controller: '\Drupal\quant\Page\QuantRedirectMetadata::build'
_title: 'Redirect Metadata'
requirements:
_permission: 'configure quant'

quant.queue:
path: '/admin/config/quant/queue-info'
defaults:
Expand Down
56 changes: 56 additions & 0 deletions src/Page/QuantRedirectMetadata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Drupal\quant\Page;

use Drupal\Core\Controller\ControllerBase;
use Drupal\views\Views;

/**
* Page controller for the redirect metadata page.
*/
class QuantRedirectMetadata extends ControllerBase {

/**
* Page callback for the redirect metadata page.
*
* If the redirect module is enabled and the metadata view exists, then show
* the view. Otherwise, show a help message.
*
* @return array
* A render array.
*/
public function build() {

$view = NULL;
$message = '';
// Check module is installed.
if (!\Drupal::moduleHandler()->moduleExists('redirect')) {
$message = $this->t('The redirect module is not enabled.');
}
// Check view is found.
else {
$view = Views::getView('quant_metadata_redirect');
if (!$view) {
$message = $this->t('The redirect metadata view was not found.');
}
}

// Show message.
if (!empty($message)) {
$build['info'] = [
'#type' => 'markup',
'#markup' => $message,
];
return $build;
}

// Render the view display.
//$output = views_embed_view('quant_metadata_redirect', 'quant_metadata_redirect_page');
$view->setDisplay('quant_metadata_redirect_page');
$view->preExecute();
$view->execute();

return $view->buildRenderable();
}

}

0 comments on commit f10650b

Please sign in to comment.