Skip to content

Commit

Permalink
Merge pull request #741 from UN-OCHA/release-versions/v1.4.2
Browse files Browse the repository at this point in the history
release versions/v1.4.2
  • Loading branch information
berliner authored Jul 27, 2023
2 parents 918a324 + fe3cde2 commit f935042
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 5 deletions.
37 changes: 37 additions & 0 deletions html/modules/custom/ghi_base_objects/ghi_base_objects.deploy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* @file
* Deploy functions for GHI Base objects.
*/

use Drupal\Core\Url;
use Drupal\menu_link_content\Entity\MenuLinkContent;

/**
* Update links in the admin menu.
*/
function ghi_base_objects_deploy_base_object_bundles_admin_menu_2() {
$types = \Drupal::entityTypeManager()->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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Drupal\ghi_base_objects\Entity;

/**
* Defines an interface for entities that have a connection with a base object.
*/
interface BaseObjectAwareEntityInterface {

/**
* Get the base object that is connected to the entity.
*
* @return \Drupal\ghi_base_objects\Entity\BaseObjectInterface
* The base object connected to the entity.
*/
public function getBaseObject();

/**
* Get the base object type associated with this bundle.
*
* @return \Drupal\ghi_base_objects\Entity\BaseObjectTypeInterface
* The base object type.
*/
public static function getBaseObjectType();

}
23 changes: 22 additions & 1 deletion html/modules/custom/ghi_plan_clusters/src/Entity/PlanCluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

namespace Drupal\ghi_plan_clusters\Entity;

use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\ghi_base_objects\Entity\BaseObjectAwareEntityInterface;
use Drupal\ghi_base_objects\Helpers\BaseObjectHelper;
use Drupal\ghi_plans\Entity\GoverningEntity;
use Drupal\ghi_sections\Entity\SectionNodeInterface;
use Drupal\ghi_subpages\Entity\SubpageNode;
use Drupal\ghi_subpages\Entity\SubpageNodeInterface;

/**
* Bundle class for plan cluster nodes.
*/
class PlanCluster extends SubpageNode implements SubpageNodeInterface {
class PlanCluster extends SubpageNode implements SubpageNodeInterface, BaseObjectAwareEntityInterface {

use StringTranslationTrait;

/**
* {@inheritdoc}
Expand All @@ -19,6 +25,21 @@ public function getParentNode() {
return $entity instanceof SectionNodeInterface ? $entity : NULL;
}

/**
* {@inheritdoc}
*/
public function getBaseObject() {
$base_object = BaseObjectHelper::getBaseObjectFromNode($this);
return $base_object instanceof GoverningEntity ? $base_object : NULL;
}

/**
* {@inheritdoc}
*/
public static function getBaseObjectType() {
return \Drupal::entityTypeManager()->getStorage('base_object_type')->load('governing_entity');
}

/**
* Get the plan cluster manager.
*
Expand Down
23 changes: 19 additions & 4 deletions html/modules/custom/ghi_subpages/src/Form/SubpagesPagesForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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) {
Expand All @@ -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 (<a href="@url">@id</a>)', [
'@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');
Expand Down

0 comments on commit f935042

Please sign in to comment.