diff --git a/src/Controller/ProfileController.php b/src/Controller/ProfileController.php new file mode 100644 index 0000000..82661e4 --- /dev/null +++ b/src/Controller/ProfileController.php @@ -0,0 +1,34 @@ + $type, + 'person' => $person_id + ); + + $node = \Drupal::entityTypeManager() + ->getStorage('profile') + ->create($values); + + $form = \Drupal::entityTypeManager() + ->getFormObject('profile', 'default') + ->setEntity($node); + return \Drupal::formBuilder()->getForm($form); + } + +} diff --git a/src/Plugin/Block/ProfileCreator.php b/src/Plugin/Block/ProfileCreator.php new file mode 100644 index 0000000..b6d11ef --- /dev/null +++ b/src/Plugin/Block/ProfileCreator.php @@ -0,0 +1,44 @@ +getParameter('person')->id(); + $markup = ""; + + // Only offer profile creation on profiles they don't already have. + $profile_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('profile'); + foreach($profile_types as $id => $type) { + $profiles = \Drupal::entityTypeManager() + ->getStorage('profile') + ->loadByProperties(['type' => $id, 'person' => $person_id]); + if (!reset($profiles)) { + $label = $type['label']; + $markup .= "

Create $label Profile

"; + } + } + return [ + '#cache' => [ + 'max-age' => 0, + ], + '#markup' => "
$markup
" + ]; + + } + +} diff --git a/zencrm.routing.yml b/zencrm.routing.yml new file mode 100644 index 0000000..256f6be --- /dev/null +++ b/zencrm.routing.yml @@ -0,0 +1,7 @@ +zencrm.profile.create: + path: '/zencrm/profile/add/{type}/{person_id}' + defaults: + _controller: '\Drupal\zencrm\Controller\ProfileController::createProfileForPerson' + _title: 'Add New Profile' + requirements: + _permission: 'access content'