From 0dec481020bf49ac5eba0fe92727c6ad33bfc32f Mon Sep 17 00:00:00 2001 From: naomi Date: Sat, 14 Apr 2018 14:40:37 +0200 Subject: [PATCH] Added route and controller for adding activity to case --- .../zencrm_entities/src/Entity/Activity.php | 4 +- src/Controller/ActivityController.php | 35 ++++++++++++++++ src/Plugin/Block/ActivityCreator.php | 40 +++++++++++++++++++ zencrm.routing.yml | 8 ++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/Controller/ActivityController.php create mode 100644 src/Plugin/Block/ActivityCreator.php diff --git a/modules/zencrm_entities/src/Entity/Activity.php b/modules/zencrm_entities/src/Entity/Activity.php index 14016a3..8ef11d5 100644 --- a/modules/zencrm_entities/src/Entity/Activity.php +++ b/modules/zencrm_entities/src/Entity/Activity.php @@ -182,14 +182,14 @@ class Activity extends ContentEntityBase implements ActivityInterface { // This field is always implied from the context, // so has no form or view display. - $fields['case'] = BaseFieldDefinition::create('entity_reference') + $fields['case_entity'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Case')) ->setDescription(t('The case this activity belongs to.')) ->setSetting('target_type', 'case_entity'); $fields['name'] = BaseFieldDefinition::create('string') ->setLabel(t('Name')) - ->setDescription(t('The name of the Activity entity.')) + ->setDescription(t('The name of the Activity.')) ->setSettings([ 'max_length' => 50, 'text_processing' => 0, diff --git a/src/Controller/ActivityController.php b/src/Controller/ActivityController.php new file mode 100644 index 0000000..a611c06 --- /dev/null +++ b/src/Controller/ActivityController.php @@ -0,0 +1,35 @@ + $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); + } +} diff --git a/src/Plugin/Block/ActivityCreator.php b/src/Plugin/Block/ActivityCreator.php new file mode 100644 index 0000000..21f689f --- /dev/null +++ b/src/Plugin/Block/ActivityCreator.php @@ -0,0 +1,40 @@ +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 .= "

Add a $label Activity

"; + } + return [ + '#cache' => [ + 'max-age' => 0, + ], + '#markup' => "" + ]; + + } + +} diff --git a/zencrm.routing.yml b/zencrm.routing.yml index 3266263..54e5717 100644 --- a/zencrm.routing.yml +++ b/zencrm.routing.yml @@ -30,3 +30,11 @@ zencrm.case.create: requirements: _permission: 'access content' +zencrm.activity.create: + path: '/zencrm/activity/{case_id}/add/{activity_type_id}' + defaults: + _controller: '\Drupal\zencrm\Controller\ActivityController::createActivityForCase' + _title: 'Add New Activity' + requirements: + _permission: 'access content' +