From a2b4a94967f71ae67f5a13bd625e6f471a958486 Mon Sep 17 00:00:00 2001 From: berliner Date: Thu, 27 Jul 2023 16:23:02 +0200 Subject: [PATCH 1/2] HPC-9197: Add base object information to section subpage listing --- .../Entity/BaseObjectAwareEntityInterface.php | 26 +++++++++++++++++++ .../src/Entity/PlanCluster.php | 23 +++++++++++++++- .../src/Form/SubpagesPagesForm.php | 23 +++++++++++++--- 3 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 html/modules/custom/ghi_base_objects/src/Entity/BaseObjectAwareEntityInterface.php diff --git a/html/modules/custom/ghi_base_objects/src/Entity/BaseObjectAwareEntityInterface.php b/html/modules/custom/ghi_base_objects/src/Entity/BaseObjectAwareEntityInterface.php new file mode 100644 index 000000000..98d637d67 --- /dev/null +++ b/html/modules/custom/ghi_base_objects/src/Entity/BaseObjectAwareEntityInterface.php @@ -0,0 +1,26 @@ +getStorage('base_object_type')->load('governing_entity'); + } + /** * Get the plan cluster manager. * diff --git a/html/modules/custom/ghi_subpages/src/Form/SubpagesPagesForm.php b/html/modules/custom/ghi_subpages/src/Form/SubpagesPagesForm.php index 76fcbf768..f58fd0719 100644 --- a/html/modules/custom/ghi_subpages/src/Form/SubpagesPagesForm.php +++ b/html/modules/custom/ghi_subpages/src/Form/SubpagesPagesForm.php @@ -12,6 +12,7 @@ use Drupal\Core\Render\Markup; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\Url; +use Drupal\ghi_base_objects\Entity\BaseObjectAwareEntityInterface; use Drupal\ghi_sections\Entity\Section; use Drupal\ghi_subpages\SubpageManager; use Drupal\ghi_subpages\SubpageTrait; @@ -132,7 +133,7 @@ public function buildForm(array $form, FormStateInterface $form_state, NodeInter $form['#attached']['library'][] = 'ghi_subpages/admin.subpages_form'; $header = [ - $this->t('Page'), + $this->t('Page title'), $this->t('Status'), $this->t('Team'), $this->t('Created'), @@ -225,14 +226,19 @@ public function buildForm(array $form, FormStateInterface $form_state, NodeInter /** @var \Drupal\node\NodeInterface[] $subpage_nodes */ $subpage_nodes = $this->subpageManager->getCustomSubpagesForBaseNode($node, $node_type); - $header = [ - $this->t('Page'), + // See if this subpage type has a base object associated. + $bundle_class = $this->entityTypeManager->getStorage('node')->getEntityClass($node_type->id()); + $has_base_object = $bundle_class && is_subclass_of($bundle_class, BaseObjectAwareEntityInterface::class); + + $header = array_filter([ + $this->t('Page title'), + $has_base_object ? $bundle_class::getBaseObjectType()->label() : NULL, $this->t('Status'), $this->t('Team'), $this->t('Created'), $this->t('Updated'), $this->t('Operations'), - ]; + ]); $rows = []; if (!empty($subpage_nodes)) { foreach ($subpage_nodes as $subpage_node) { @@ -241,6 +247,15 @@ public function buildForm(array $form, FormStateInterface $form_state, NodeInter $row = []; $row[] = $subpage_node->toLink(); + if ($has_base_object) { + /** @var \Drupal\ghi_base_objects\Entity\BaseObjectAwareEntityInterface $subpage_node */ + $base_object = $subpage_node->getBaseObject(); + $row[] = $base_object ? $this->t('@label (@id)', [ + '@label' => $base_object->label(), + '@url' => $base_object->toUrl('edit-form')->toString(), + '@id' => $base_object->getSourceId(), + ]) : NULL; + } $row[] = $subpage_node->isPublished() ? $this->t('Published') : $this->t('Unpublished'); $row[] = $subpage_team ? $subpage_team->getName() : $section_team . ' (' . $this->t('Inherit from section') . ')'; $row[] = $this->dateFormatter->format($subpage_node->getCreatedTime(), 'custom', 'F j, Y h:ia'); From 4b406df7d35914ebe74454b2911c0735a358068d Mon Sep 17 00:00:00 2001 From: berliner Date: Thu, 27 Jul 2023 17:54:21 +0200 Subject: [PATCH 2/2] HPC-9197: Add sublinks to base object menu items in admin menu for easier access --- .../ghi_base_objects.deploy.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 html/modules/custom/ghi_base_objects/ghi_base_objects.deploy.php diff --git a/html/modules/custom/ghi_base_objects/ghi_base_objects.deploy.php b/html/modules/custom/ghi_base_objects/ghi_base_objects.deploy.php new file mode 100644 index 000000000..c73d611ed --- /dev/null +++ b/html/modules/custom/ghi_base_objects/ghi_base_objects.deploy.php @@ -0,0 +1,37 @@ +getStorage('base_object_type')->loadMultiple(); + usort($types, function ($a, $b) { + return strnatcasecmp($a->label(), $b->label()); + }); + foreach (array_values($types) as $weight => $type) { + $route_name = 'view.base_objects.' . $type->id(); + try { + \Drupal::service('router.route_provider')->getRouteByName($route_name); + } + catch (Exception $e) { + continue; + } + MenuLinkContent::create([ + 'title' => $type->label(), + 'link' => [ + 'uri' => 'internal:' . Url::fromRoute($route_name)->toString(), + ], + 'menu_name' => 'admin', + 'parent' => 'base_object.collection', + 'weight' => $weight, + ])->save(); + } +}