Skip to content
Snippets Groups Projects

Draft: Add Queue API to populate views url alias table

Open Nicholas Stees requested to merge issue/views_url_alias-3396617:8.x-2.x into 8.x-2.x
3 files
+ 104
11
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -18,11 +18,68 @@ class ViewsURLAliasAdminForm extends ConfirmFormBase {
return 'views_url_alias_admin_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
// Get the number of items left in the queue.
$queue = \Drupal::queue('views_url_alias_queue_worker');
$remaining_items = $queue->numberOfItems();
// Fetch total paths from path_alias table.
$database = \Drupal::database();
$total_paths = $database->select('path_alias', 'pa')
->countQuery()
->execute()
->fetchField();
// Fetch total records in views_url_alias table.
$total_views_url_aliases = $database->select('views_url_alias', 'vua') // assuming your table name is views_url_alias
->countQuery()
->execute()
->fetchField();
$form['paths_info'] = [
'#markup' => $this->t('Total paths in Drupal: @total_paths. Total paths in Views URL alias table: @total_views_url.', [
'@total_paths' => $total_paths,
'@total_views_url' => $total_views_url_aliases
]),
'#prefix' => '<p>',
'#suffix' => '</p>',
];
if ($remaining_items > 0) {
$form['status'] = [
'#markup' => $this->t('There are currently @count items remaining in the queue to be processed. Run cron to process the queue.', ['@count' => $remaining_items]),
'#prefix' => '<p>',
'#suffix' => '</p>',
];
} else {
$form['status'] = [
'#markup' => $this->t('All items have been processed and the views URL table is up to date.'),
'#prefix' => '<p>',
'#suffix' => '</p>',
];
}
return $form;
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to rebuild the Views URL alias table?');
$queue = \Drupal::queue('views_url_alias_queue_worker');
$remaining_items = $queue->numberOfItems();
if ($remaining_items > 0) {
return $this->t('There are @count items remaining. Are you sure you want to rebuild the Views URL alias table?', ['@count' => $remaining_items]);
} else {
return $this->t('All items have been processed. Are you sure you want to rebuild the Views URL alias table?');
}
}
/**
@@ -53,5 +110,4 @@ class ViewsURLAliasAdminForm extends ConfirmFormBase {
views_url_alias_rebuild_path();
$form_state->setRedirectUrl(new Url('views_ui.settings_basic'));
}
}
Loading