Added route and controller for adding activity to case

This commit is contained in:
naomi
2018-04-14 14:40:37 +02:00
parent 7eb0ee092b
commit 0dec481020
4 changed files with 85 additions and 2 deletions

View File

@ -0,0 +1,35 @@
<?php
namespace Drupal\zencrm\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Class ActivityController.
*/
class ActivityController extends ControllerBase {
/**
* Displays a form for creating a activity.
* The type of activity and the case are prepopulated.
*
* @return form for creating a activity
*/
public function createActivityForCase($case_id, $activity_type_id) {
error_log( "$case_id, $activity_type_id");
$values = array(
'type' => $activity_type_id,
'case_entity' => $case_id,
);
$activity = \Drupal::entityTypeManager()
->getStorage('activity')
->create($values);
$form = \Drupal::entityTypeManager()
->getFormObject('activity', 'default')
->setEntity($activity);
return \Drupal::formBuilder()->getForm($form);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Drupal\zencrm\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'ActivityCreator' block.
* Block contains links for creating activities with.
* The links open an entity create form in a popup, passing in the activity type and case id in the url.
*
* @Block(
* id = "activity_creator",
* admin_label = @Translation("Activity creator"),
* )
*/
class ActivityCreator extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$case_id = \Drupal::routeMatch()->getParameter('case_entity')->id();
$markup = "";
$activity_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('activity');
foreach($activity_types as $activity_type_id => $type) {
$label = $type['label'];
$markup .= "<p><a class='use-ajax' data-dialog-type='modal' href='/zencrm/activity/$case_id/add/$activity_type_id?destination=/zencrm/case/$case_id'>Add a $label Activity</a></p>";
}
return [
'#cache' => [
'max-age' => 0,
],
'#markup' => "<div class='zencrm_creation_links'>$markup</div>"
];
}
}