diff --git a/src/Plugin/Block/ContextualMenu.php b/src/Plugin/Block/ContextualMenu.php
index 4afa082..c8b71f8 100644
--- a/src/Plugin/Block/ContextualMenu.php
+++ b/src/Plugin/Block/ContextualMenu.php
@@ -5,6 +5,7 @@ namespace Drupal\opencase\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Link;
use Drupal\Core\Url;
+use Drupal\opencase\Utils;
/**
* Provides a 'ContextualMenu' block.
@@ -48,7 +49,7 @@ class ContextualMenu extends BlockBase {
$actor = \Drupal::routeMatch()->getParameter('oc_actor');
$url = Url::fromRoute('view.cases.page_1', array('actor_id' => $actor->id()));
$link = Link::fromTextAndUrl(t("Case List"), $url)->toString();
- return "
";
+ return "";
}
/**
@@ -60,18 +61,8 @@ class ContextualMenu extends BlockBase {
$actor_id = \Drupal::routeMatch()->getParameter('actor_id');
$actor = \Drupal::entityTypeManager()->getStorage('oc_actor')->load($actor_id);
$link = $actor->toLink()->toString();
- $markup = "";
-
- $case_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_case');
- $add_links = '';
- foreach($case_types as $case_type_id => $type) {
- $label = $type['label'];
- $url = Url::fromRoute('entity.oc_case.add_form', ['oc_case_type' => $case_type_id]);
- $url->setOption('query', ['actor_id' => $actor_id]);
- $link = Link::fromTextAndUrl(t("Add a $label case"), $url)->toString();
- $add_links .= "$link
";
- }
- $markup .= "";
+ $markup = "";
+ $markup .= Utils::generateAddLinks('oc_case', ['actor_id' => $actor_id]);
return $markup;
}
diff --git a/src/Utils.php b/src/Utils.php
new file mode 100644
index 0000000..a4a4911
--- /dev/null
+++ b/src/Utils.php
@@ -0,0 +1,33 @@
+ value format)
+ *
+ * returns html markup.
+ */
+ public static function generateAddLinks($baseEntityType, $query = []) {
+
+ $bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo($baseEntityType);
+ $markup = '';
+ foreach($bundles as $bundle_id => $bundle) {
+ $label = $bundle['label'];
+ $url = \Drupal\Core\Url::fromRoute("entity.$baseEntityType.add_form", [$baseEntityType . '_type' => $bundle_id]);
+ $url->setOption('query', $query);
+ $link = \Drupal\Core\Link::fromTextAndUrl(t("Add $label"), $url)->toString();
+ $markup .= "$link
";
+ }
+ return "$markup
";
+ }
+}