This repository has been archived on 2022-07-12. You can view files and clone it, but cannot push or open issues or pull requests.
opencase/modules/opencase_cases/src/Plugin/Block/AddCase.php

41 lines
893 B
PHP

<?php
namespace Drupal\opencase_cases\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a Block for adding a case for the current client
*
* @Block(
* id = "add_case",
* admin_label = @Translation("Add Case"),
* category = @Translation("Opencase"),
* )
*/
class AddCase extends BlockBase {
/**
* {@inheritdoc}
*/
public function build():array {
$target_id = \Drupal::routeMatch()->getParameter('oc_actor')->id();
$case_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_case');
$markup = "<ul>";
foreach($case_types as $id => $info) {
$label = $info['label'];
$markup .= "<li><a href='/opencase/oc_case/add/$id?target_id=$target_id'>$label</a></li>";
}
$markup .= "</ul>";
return array(
'#markup' => $markup
);
}
public function getCacheMaxAge():int {
return 0;
}
}