Added route and controller for adding new contact details to a person

This commit is contained in:
naomi 2018-04-11 14:24:29 +02:00
parent 32803ff8a8
commit 689d208463
3 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace Drupal\zencrm\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Class ContactDetailsController.
*/
class ContactDetailsController extends ControllerBase {
/**
* Outputs a form for creating contact details, with the person
* already populated (person is not shown on the form).
*/
public function createContactDetailsForPerson($person_id) {
$values = array(
'person' => $person_id
);
$node = \Drupal::entityTypeManager()
->getStorage('contact_details')
->create($values);
$form = \Drupal::entityTypeManager()
->getFormObject('contact_details', 'default')
->setEntity($node);
return \Drupal::formBuilder()->getForm($form);
}
}

View File

@ -31,7 +31,7 @@ class HatCreator extends BlockBase {
->loadByProperties(['type' => $id, 'person' => $person_id]);
if (!reset($hats)) {
$label = $type['label'];
$markup .= "<p><a class='use-ajax' data-dialog-type='modal' href='/zencrm/hat/add/$id/$person_id?destination=/zencrm/person/$person_id'>Create $label Hat</a></p>";
$markup .= "<p><a class='use-ajax' data-dialog-type='modal' href='/zencrm/hat/add/$id/$person_id?destination=/zencrm/person/$person_id'>Add a $label Hat</a></p>";
}
}
return [

View File

@ -5,3 +5,11 @@ zencrm.hat.create:
_title: 'Add New Hat'
requirements:
_permission: 'access content'
zencrm.contact_details.create:
path: '/zencrm/contact_details/add/{person_id}'
defaults:
_controller: '\Drupal\zencrm\Controller\ContactDetailsController::createContactDetailsForPerson'
_title: 'Add New Contact Details'
requirements:
_permission: 'access content'