Refactored global and contextual menu
This commit is contained in:
@ -13,19 +13,21 @@ class Utils {
|
||||
* Generates a set of links for adding different types of a base entity
|
||||
*
|
||||
* $baseEntityType the type of entity to generate the links for (it will generate one for each bundle of the base type)
|
||||
* $query optionally append a query string to the links (key => value format)
|
||||
* $title the title to be placed above the set of links)
|
||||
* $query optionally append a query string to the links (key => value format
|
||||
*
|
||||
* returns html markup.
|
||||
*/
|
||||
public static function generateAddLinks($baseEntityType, $query = []) {
|
||||
public static function generateAddLinks($baseEntityType, $title, $query = []) {
|
||||
|
||||
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo($baseEntityType);
|
||||
$markup = '';
|
||||
$title = t($title);
|
||||
$markup = "<h1>$title: </h1>";
|
||||
foreach($bundles as $bundle_id => $bundle) {
|
||||
$label = $bundle['label'];
|
||||
$label = t($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();
|
||||
$link = \Drupal\Core\Link::fromTextAndUrl($label, $url)->toString();
|
||||
$markup .= "<p>$link</p>";
|
||||
}
|
||||
return "<div class='opencase_add_links'>$markup</div>";
|
||||
|
Reference in New Issue
Block a user