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

Integrate tree configuration feature with menu links

parent f8c85edf
No related branches found
No related tags found
No related merge requests found
......@@ -231,7 +231,8 @@ class HmMenuController extends ControllerBase {
* @return NULL|object
*/
protected function getDisplayPlugin() {
return $this->hmPluginTypeManager->getDisplayPluginInstance('hm_setup_menu');
$display_profile = $this->hmPluginTypeManager->getDisplayProfile('hm_setup_menu');
return $this->hmPluginTypeManager->getDisplayPluginInstance($display_profile);
}
/**
......
......@@ -112,9 +112,11 @@ class HmTaxonomyController extends ControllerBase {
}
}
}
// Display profile.
$display_profile = $this->hmPluginTypeManager->getDisplayProfile('hm_setup_taxonomy');
// Display plugin instance.
$display_plugin = $this->hmPluginTypeManager->getDisplayPluginInstance('hm_setup_taxonomy');
$display_plugin = $this->hmPluginTypeManager->getDisplayPluginInstance($display_profile);
if (empty($display_plugin)) {
return new JsonResponse(['result' => 'Display profile has not been set up.']);
......
......@@ -71,9 +71,14 @@ class HmMenuForm extends MenuForm {
* @return NULL|array
*/
protected function buildOverviewTree(array $form, FormStateInterface $form_state) {
global $base_path;
$display_profile = $this->hmPluginTypeManager->getDisplayProfile('hm_setup_menu');
if (empty($display_profile)) {
return [];
}
$display_plugin_instance = $this->hmPluginTypeManager->getDisplayPluginInstance('hm_setup_menu');
$display_plugin_instance = $this->hmPluginTypeManager->getDisplayPluginInstance($display_profile);
if (!empty($display_plugin_instance)) {
if (method_exists($display_plugin_instance, 'getForm')) {
......@@ -91,8 +96,15 @@ class HmMenuForm extends MenuForm {
}
// 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);
$update_url = Url::fromRoute('hierarchy_manager.menu.tree.update', ['mid' => $mid], ['query' => ['token' => $token]])->toString();
$config = $display_profile->get("config");
if (!empty($config)) {
$options = json_decode($config);
}
else {
$options = NULL;
}
return $display_plugin_instance->getForm($source_url, $update_url, $form, $form_state, $options);
}
}
......
......@@ -2,9 +2,11 @@
namespace Drupal\hierarchy_manager;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\hierarchy_manager\Plugin\HmDisplayPluginManager;
use Drupal\hierarchy_manager\Plugin\HmSetupPluginManager;
use DrupalCodeGenerator\Command\Drupal_8\Module\ConfigurationEntity;
class PluginTypeManager {
......@@ -65,27 +67,36 @@ class PluginTypeManager {
/**
* Get a display plugin instance according to a setup plugin.
*
* @param string $setup_plugin_id
* setup plugin ID.
* @param \Drupal\Core\Config\Entity\ConfigEntityBase; $display_profile
* Display profile entity.
* @return NULL|object
* The display plugin instance.
*/
public function getDisplayPluginInstance(string $setup_plugin_id) {
// The setup plugin instance.
$setup_plugin = $this->setupManager->createInstance($setup_plugin_id);
// Display profile.
$display_profile = $this->entityTypeManager->getStorage('hm_display_profile')->load($setup_plugin->getDispalyProfileId());
public function getDisplayPluginInstance(ConfigEntityBase $display_profile) {
if (empty($display_profile)) {
return NULL;
}
// Display plugin ID.
$display_plugin_id = $display_profile->get("plugin");
return $this->displayManager->createInstance($display_plugin_id);
}
/**
* Get a display profile entity according to a setup plugin.
*
* @param string $setup_plugin_id
* setup plugin ID.
* @return NULL|\DrupalCodeGenerator\Command\Drupal_8\Module\ConfigurationEntity
* The display profile entity.
*/
public function getDisplayProfile(string $setup_plugin_id) {
// The setup plugin instance.
$setup_plugin = $this->setupManager->createInstance($setup_plugin_id);
// Return the display profile.
return $this->entityTypeManager->getStorage('hm_display_profile')->load($setup_plugin->getDispalyProfileId());
}
/**
* Update the items for a hierarchy
*
......
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