first_name->getString(); $middle_names = $entity->middle_names->getString(); $last_name = $entity->last_name->getString(); if ($middle_names) { $middle_names .= ' '; } $first_and_last_name = $first_name . ' ' . $last_name; $full_name = $first_name . ' ' . $middle_names . $last_name; $entity->set('full_name', $full_name); $entity->set('first_and_last_name', $first_and_last_name); } /** * Implements hook_ENTITY_TYPE_presave(). * Computes the name field from the full name of the referenced person * plus the profile type. */ function zencrm_entities_profile_presave($entity) { $person_id = $entity->person->first()->getValue()['target_id']; $person = \Drupal\zencrm_entities\Entity\Person::load($person_id); $full_name = $person->full_name->getString(); $bundle_name = $entity->type->entity->label(); $entity->set('name', $full_name . ' - ' . $bundle_name); } /** * Implements hook_help(). */ function zencrm_entities_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { // Main module help for the zencrm_entities module. case 'help.page.zencrm_entities': $output = ''; $output .= '

' . t('About') . '

'; $output .= '

' . t('Zen CRM Entities') . '

'; return $output; default: } } /** * Implements hook_theme(). */ function zencrm_entities_theme() { $theme = []; $theme['zencrm_entities'] = [ 'render element' => 'children', ]; $theme['profile'] = [ 'render element' => 'elements', 'file' => 'profile.page.inc', 'template' => 'profile', ]; $theme['profile_content_add_list'] = [ 'render element' => 'content', 'variables' => ['content' => NULL], 'file' => 'profile.page.inc', ]; return $theme; } /** * Implements hook_theme_suggestions_HOOK(). */ function zencrm_entities_theme_suggestions_profile(array $variables) { $suggestions = []; $entity = $variables['elements']['#profile']; $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); $suggestions[] = 'profile__' . $sanitized_view_mode; $suggestions[] = 'profile__' . $entity->bundle(); $suggestions[] = 'profile__' . $entity->bundle() . '__' . $sanitized_view_mode; $suggestions[] = 'profile__' . $entity->id(); $suggestions[] = 'profile__' . $entity->id() . '__' . $sanitized_view_mode; return $suggestions; }