getParameter('person')->id(); $markup = ""; $person = \Drupal::entityTypeManager()->getStorage('person')->load($person_id); // If the person has no contact details, suggest they create some $link_to_add = "/zencrm/contact_details/$person_id/add?destination=/zencrm/person/$person_id"; $contact_details = \Drupal::entityTypeManager() ->getStorage('contact_details') ->loadByProperties(['person' => $person_id]); if (!reset($contact_details)) { $markup .= "

This person has no contact details yet. To get started, "; $markup .= "Add a set of contact details"; $markup .= "

"; } else { // They have contact details, so they are able to create hats. // If the person has no hats, suggest they create one, by rendering the hat creator block $link_to_add = "/zencrm/hat/$person_id/add?destination=/zencrm/person/$person_id"; $hats = \Drupal::entityTypeManager() ->getStorage('hat') ->loadByProperties(['person' => $person_id]); if (!reset($hats)) { $markup .= "

This person has no hats yet. A hat is a role that the person plays in the organisation. To get started, add a hat for this person.

"; $plugin_manager = \Drupal::service('plugin.manager.block'); $block = $plugin_manager->createInstance('hat_creator', array()); $markup .= render($block->build()); } else { // they have hats, so display the case view for each hat. foreach($hats as $hat) { $markup .= $this->show_cases_for_hat($hat); } } } return [ '#cache' => [ 'max-age' => 0, ], '#markup' => "
$markup
" ]; } private function show_cases_for_hat($hat) { $markup = ''; $markup .= "

" . $hat->name->getString() . "

"; $markup .= drupal_render(views_embed_view('this_hat_s_cases', 'block_1', $hat->id())); error_log(print_r(views_embed_view('this_hat_s_cases', 'block_1', $hat->id()), true)); return $markup; } }