pm-4.1.x-dev/src/Service/PmConfig.php
src/Service/PmConfig.php
<?php
declare(strict_types=1);
namespace Drupal\pm\Service;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
/**
* @todo Add class description.
*/
final class PmConfig {
/**
* Constructs a PmConfig object.
*/
public function __construct(
private readonly ConfigFactoryInterface $configFactory,
private readonly EntityTypeManagerInterface $entityTypeManager,
) {}
/**
* @todo Add method description.
*/
public function doSomething(): void {
// @todo Place your code here.
}
/**
* Get hierarchy info.
*/
private function getHierarchyConfig(): array {
// @TODO: Convert to DTO for better DX.
// @TODO: Make sure every entity_type that can have bundle have bundle
// specific configuration.
return [
"parent_type" => [
"pm_sub_task" => "pm_task",
"pm_task" => "pm_story",
"pm_story" => "pm_feature",
"pm_feature" => "pm_epic",
"pm_board_column" => "pm_board",
],
"children_type" => [
"pm_epic" => "pm_feature",
"pm_feature" => "pm_story",
"pm_story" => "pm_task",
"pm_task" => "pm_sub_task",
"pm_board" => "pm_board_column",
"pm_board_column" => [
"pm_epic" => "pm_epic",
"pm_feature" => "pm_feature",
"pm_story" => "pm_story",
"pm_task" => "pm_task",
],
],
"parent_reference_field" => [
"pm_feature" => "pm_parent_pm_epic",
"pm_story" => "pm_parent_pm_feature",
"pm_task" => "pm_parent_pm_story",
"pm_sub_task" => "pm_parent_pm_task",
"pm_board_column" => "pm_parent_pm_board",
],
"child_reference_field" => [
"pm_epic" => "pm_feature_list",
"pm_feature" => "pm_story_list",
"pm_story" => "pm_task_list",
"pm_task" => "pm_sub_task_list",
"pm_board" => [
"kanban" => "pm_board_column",
"scrum" => "pm_board_column",
],
"pm_board_column" => [
"pm_epic" => "pm_epic",
"pm_feature" => "pm_feature",
"pm_story" => "pm_story",
"pm_task" => "pm_task",
],
],
];
}
/**
* Get parent entity type.
*/
public function getParentType(string $entity_type): ?string {
$parent_entity_type = NULL;
$config = $this->getHierarchyConfig()["parent_type"];
if (!empty($config[$entity_type])) {
$parent_entity_type = $config[$entity_type];
}
return $parent_entity_type;
}
/**
* Get child entity type.
*/
public function getChildEntityType(string $entity_type, string $bundle): ?string {
$child_entity_type = NULL;
$config = $this->getHierarchyConfig()["children_type"];
if (!empty($config[$entity_type])) {
if (is_array($config[$entity_type])) {
$child_entity_type = $config[$entity_type][$bundle];
}
else {
$child_entity_type = $config[$entity_type];
}
}
return $child_entity_type;
}
/**
* Get Child reference field.
*/
public function getChildReferenceFieldName(string $entity_type, string $bundle): ?string {
$field_name = NULL;
$config = $this->getHierarchyConfig()["child_reference_field"];
if (!empty($config[$entity_type])) {
if (is_array($config[$entity_type])) {
$field_name = $config[$entity_type][$bundle];
}
else {
$field_name = $config[$entity_type];
}
}
return $field_name;
}
/**
* Get Child reference field.
*/
public function getParentReferenceFieldName(string $entity_type): ?string {
$field_name = NULL;
$config = $this->getHierarchyConfig()["parent_reference_field"];
if (!empty($config[$entity_type])) {
$field_name = $config[$entity_type];
}
return $field_name;
}
}
