Added controller for creating new cases.

This commit is contained in:
naomi 2018-04-12 18:39:07 +02:00
parent 12ccecdd55
commit 109c3e14c9
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,34 @@
<?php
namespace Drupal\zencrm\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Class CaseController.
*/
class CaseController extends ControllerBase {
/**
* Displays a form for creating a case.
* The type of case and the hat are prepopulated.
*
* @return form for creating a case
*/
public function createCaseForHat($hat_id, $case_type_id) {
$values = array(
'type' => $case_type_id,
);
$case = \Drupal::entityTypeManager()
->getStorage('case_entity')
->create($values);
$case->hats_involved->appendItem($hat_id);
$form = \Drupal::entityTypeManager()
->getFormObject('case_entity', 'default')
->setEntity($case);
return \Drupal::formBuilder()->getForm($form);
}
}

View File

@ -21,3 +21,12 @@ zencrm.contact_details.create:
_title: 'Add New Contact Details'
requirements:
_permission: 'access content'
zencrm.case.create:
path: '/zencrm/case/{hat_id}/add/{case_type_id}'
defaults:
_controller: '\Drupal\zencrm\Controller\CaseController::createCaseForHat'
_title: 'Add New Case'
requirements:
_permission: 'access content'