|
|
|
|
@ -8,6 +8,10 @@ use Drupal\Core\Messenger\MessengerTrait;
|
|
|
|
|
use Drupal\Core\Session\AccountInterface; |
|
|
|
|
use Drupal\zombie_reference_hunter\Service\ZombieReferenceHunterQuery; |
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
use Drupal\Core\Link; |
|
|
|
|
use Drupal\Core\Url; |
|
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creating a controller. |
|
|
|
|
@ -42,30 +46,108 @@ class ZombieReferenceHunterController extends ControllerBase
|
|
|
|
|
* Returns the Report page. |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
public function view(): array |
|
|
|
|
public function view(Request $request): array|RedirectResponse |
|
|
|
|
{ |
|
|
|
|
$issues = $this->query->scan(); |
|
|
|
|
// Force a new scan when requested. |
|
|
|
|
if ($request->query->getBoolean('rescan')) { |
|
|
|
|
$this->query->rebuildCache(); |
|
|
|
|
|
|
|
|
|
// Redirect back to the clean report URL so refreshing the browser |
|
|
|
|
// doesn't perform another scan. |
|
|
|
|
return new RedirectResponse( |
|
|
|
|
Url::fromRoute('zombie_reference_hunter.prepare')->toString() |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// This now returns cached results unless no cache exists yet. |
|
|
|
|
$issues = $this->query->getIssues(); |
|
|
|
|
$count = count($issues); |
|
|
|
|
|
|
|
|
|
$build = [ |
|
|
|
|
'#cache' => ['max-age' => 0], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$build['summary'] = [ |
|
|
|
|
'#markup' => $this->t('Found @count broken reference(s).', ['@count' => $count]), |
|
|
|
|
'#type' => 'container', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$build['summary']['count'] = [ |
|
|
|
|
'#markup' => $this->formatPlural( |
|
|
|
|
$count, |
|
|
|
|
'Found 1 broken reference.', |
|
|
|
|
'Found @count broken references.', |
|
|
|
|
), |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
// Rescan button. |
|
|
|
|
$build['summary']['rescan'] = [ |
|
|
|
|
'#type' => 'link', |
|
|
|
|
'#title' => $this->t('Rescan'), |
|
|
|
|
'#url' => Url::fromRoute( |
|
|
|
|
'zombie_reference_hunter.prepare', |
|
|
|
|
[], |
|
|
|
|
[ |
|
|
|
|
'query' => [ |
|
|
|
|
'rescan' => 1, |
|
|
|
|
], |
|
|
|
|
] |
|
|
|
|
), |
|
|
|
|
'#attributes' => [ |
|
|
|
|
'class' => [ |
|
|
|
|
'button', |
|
|
|
|
'button--primary', |
|
|
|
|
], |
|
|
|
|
'style' => 'margin-left: 1em;', |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
if ($count === 0) { |
|
|
|
|
$build['empty'] = [ |
|
|
|
|
'#markup' => $this->t('No broken references found.'), |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
return $build; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Pager. |
|
|
|
|
$limit = 50; |
|
|
|
|
|
|
|
|
|
$pager = \Drupal::service('pager.manager') |
|
|
|
|
->createPager($count, $limit); |
|
|
|
|
|
|
|
|
|
$current_page = $pager->getCurrentPage(); |
|
|
|
|
|
|
|
|
|
// Only build rows for the current page. |
|
|
|
|
$issues = array_slice( |
|
|
|
|
$issues, |
|
|
|
|
$current_page * $limit, |
|
|
|
|
$limit |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$rows = []; |
|
|
|
|
|
|
|
|
|
foreach ($issues as $issue) { |
|
|
|
|
$entity_type_id = $issue['source_entity_type']; |
|
|
|
|
$entity_type = $this->entityTypeManager() |
|
|
|
|
->getDefinition($entity_type_id); |
|
|
|
|
|
|
|
|
|
$source_id = $issue['source_id']; |
|
|
|
|
|
|
|
|
|
if ($entity_type->hasLinkTemplate('edit-form')) { |
|
|
|
|
$source_id = Link::fromTextAndUrl( |
|
|
|
|
(string) $issue['source_id'], |
|
|
|
|
Url::fromRoute( |
|
|
|
|
'entity.' . $entity_type_id . '.edit_form', |
|
|
|
|
[ |
|
|
|
|
$entity_type_id => $issue['source_id'], |
|
|
|
|
] |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$rows[] = [ |
|
|
|
|
$issue['source_entity_type'], |
|
|
|
|
$issue['source_id'], |
|
|
|
|
$entity_type_id, |
|
|
|
|
$source_id, |
|
|
|
|
$issue['field_name'], |
|
|
|
|
$issue['field_type'], |
|
|
|
|
$issue['target_type'], |
|
|
|
|
@ -87,6 +169,10 @@ class ZombieReferenceHunterController extends ControllerBase
|
|
|
|
|
'#empty' => $this->t('No broken references found.'), |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$build['pager'] = [ |
|
|
|
|
'#type' => 'pager', |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
return $build; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|