Skip to content
Snippets Groups Projects
Commit e065469a authored by Mingsong Hu's avatar Mingsong Hu
Browse files

Use Url::fromRoute() instead of hardcode URL string

parent 10864436
No related branches found
No related tags found
No related merge requests found
......@@ -114,9 +114,6 @@ class HmMenuController extends ControllerBase {
$parent = '';
}
if (empty($destination)) {
$destination = '';
}
// We indicate that a menu administrator is running the menu access check.
$request->attributes->set('_menu_admin', TRUE);
......
......@@ -79,6 +79,7 @@ class HmTaxonomyController extends ControllerBase {
}
$parent = $request->get('parent') ?: 0;
$depth = $request->get('depth');
$destination = $request->get('destination');
if(!empty($depth)) {
$depth = intval($depth);
......@@ -95,12 +96,18 @@ class HmTaxonomyController extends ControllerBase {
if ($term instanceof Term) {
// User can only access the terms that they can update.
if ($access_control_handler->access($term, 'update')) {
if (empty($destination)) {
$url = $term->toUrl('edit-form')->toString();
}
else {
$url = $term->toUrl('edit-form', ['query' => ['destination' => $destination]])->toString();
}
$term_array[] = $this->hmPluginTypeManager->buildHierarchyItem(
$term->id(),
$term->label(),
$term->parents[0],
$term->toUrl('edit-form')->toString());
$url);
}
}
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\hierarchy_manager\Form;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Drupal\menu_ui\MenuForm;
......@@ -80,24 +81,17 @@ class HmMenuForm extends MenuForm {
$mid = $this->entity->id();
// CSRF token.
$token = \Drupal::csrfToken()->get($mid);
// Get current language.
$language = \Drupal::languageManager()->getCurrentLanguage();
// Destination for edit link.
$destination = $this->getDestinationArray();
if (isset($destination['destination'])) {
$destination = $destination['destination'];
}
else {
$destination = '';
}
if ($language->isDefault()) {
$source_url = $base_path . 'admin/hierarchy_manager/menu/json/' . $mid . '?token=' . $token . '&destination=' . $destination;
$update_url = $base_path . 'admin/hierarchy_manager/menu/update/' . $mid . '?token=' . $token;
}
else {
$source_url = $base_path . $language->getId() . '/admin/hierarchy_manager/menu/json/' . $mid . '?token=' . $token . '&destination=' . $destination;
$update_url = $base_path . $language->getId() . '/admin/hierarchy_manager/menu/update/' . $mid . '?token=' . $token;
$destination = '/';
}
// Urls
$source_url = Url::fromRoute('hierarchy_manager.menu.tree.json', ['mid' => $mid], ['query' => ['token' => $token, 'destination' => $destination]])->toString();
$update_url = Url::fromRoute('hierarchy_manager.menu.tree.update', ['mid' => $mid], ['query' => ['token' => $token]])->toString();
return $display_plugin_instance->getForm($source_url, $update_url, $form, $form_state);
}
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\hierarchy_manager\Form;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Drupal\taxonomy\VocabularyInterface;
use Drupal\taxonomy\Form\OverviewTerms;
......@@ -51,16 +52,17 @@ class HmOverviewTerms extends OverviewTerms {
$vid = $taxonomy_vocabulary->id();
// CSRF token.
$token = \Drupal::csrfToken()->get($vid);
// Get current language.
$language = \Drupal::languageManager()->getCurrentLanguage();
if ($language->isDefault()) {
$source_url = $base_path . 'admin/hierarchy_manager/taxonomy/json/' . $vid . '?token=' . $token;
$update_url = $base_path . 'admin/hierarchy_manager/taxonomy/update/' . $vid . '?token=' . $token;
// Destination for edit link.
$destination = $this->getDestinationArray();
if (isset($destination['destination'])) {
$destination = $destination['destination'];
}
else {
$source_url = $base_path . $language->getId() . '/admin/hierarchy_manager/taxonomy/json/' . $vid . '?token=' . $token;
$update_url = $base_path . $language->getId() . '/admin/hierarchy_manager/taxonomy/update/' . $vid . '?token=' . $token;
$destination = '/';
}
// Urls.
$source_url = Url::fromRoute('hierarchy_manager.taxonomy.tree.json', ['vid' => $vid], ['query' => ['token' => $token, 'destination' => $destination]])->toString();
$update_url = Url::fromRoute('hierarchy_manager.taxonomy.tree.update', ['vid' => $vid], ['query' => ['token' => $token]])->toString();
return $instance->getForm($source_url, $update_url, $form, $form_state);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment