From 61c969d7f42e88aafa48a889e7fac0812fb2349d Mon Sep 17 00:00:00 2001 From: naomi Date: Thu, 12 Apr 2018 15:11:25 +0200 Subject: [PATCH] Created "person panel" block which displays in content area for a person Also moved contact details view config to zencrm_entities because it is referenced as an entity reference view in a base field on Hat. --- config/optional/block.block.personpanel.yml | 25 ++ ...ews.view.this_person_s_contact_details.yml | 258 +++++++++++++++++- src/Plugin/Block/PersonPanel.php | 57 ++++ 3 files changed, 339 insertions(+), 1 deletion(-) create mode 100644 config/optional/block.block.personpanel.yml rename {config => modules/zencrm_entities/config}/optional/views.view.this_person_s_contact_details.yml (52%) create mode 100644 src/Plugin/Block/PersonPanel.php diff --git a/config/optional/block.block.personpanel.yml b/config/optional/block.block.personpanel.yml new file mode 100644 index 0000000..8da71f5 --- /dev/null +++ b/config/optional/block.block.personpanel.yml @@ -0,0 +1,25 @@ +langcode: en +status: true +dependencies: + module: + - system + - zencrm + theme: + - bartik +id: personpanel +theme: bartik +region: content +weight: 0 +provider: null +plugin: person_panel +settings: + id: person_panel + label: 'Person Panel' + provider: zencrm + label_display: '0' +visibility: + request_path: + id: request_path + pages: '/zencrm/person/*' + negate: false + context_mapping: { } diff --git a/config/optional/views.view.this_person_s_contact_details.yml b/modules/zencrm_entities/config/optional/views.view.this_person_s_contact_details.yml similarity index 52% rename from config/optional/views.view.this_person_s_contact_details.yml rename to modules/zencrm_entities/config/optional/views.view.this_person_s_contact_details.yml index e734510..67e207f 100644 --- a/config/optional/views.view.this_person_s_contact_details.yml +++ b/modules/zencrm_entities/config/optional/views.view.this_person_s_contact_details.yml @@ -236,7 +236,7 @@ display: admin_label: '' empty: true tokenize: true - content: '

Add a set of contact details

' + content: '

Add a set of contact details

' plugin_id: text_custom empty: { } relationships: { } @@ -302,3 +302,259 @@ display: - 'languages:language_interface' - url tags: { } + entity_reference_1: + display_plugin: entity_reference + id: entity_reference_1 + display_title: 'Entity Reference' + position: 2 + display_options: + display_extenders: { } + fields: + id: + id: id + table: contact_details + field: id + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: number_integer + settings: + thousand_separator: '' + prefix_suffix: true + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: contact_details + entity_field: id + plugin_id: field + rendered_entity: + id: rendered_entity + table: contact_details + field: rendered_entity + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + view_mode: default + entity_type: contact_details + plugin_id: rendered_entity + nothing: + id: nothing + table: views + field: nothing + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: true + text: 'Edit' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: false + plugin_id: custom + type: + id: type + table: contact_details + field: type + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: false + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: contact_details + entity_field: type + plugin_id: field + defaults: + fields: false + style: + type: entity_reference + options: + search_fields: + type: type + id: '0' + rendered_entity: '0' + nothing: '0' + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url + tags: { } diff --git a/src/Plugin/Block/PersonPanel.php b/src/Plugin/Block/PersonPanel.php new file mode 100644 index 0000000..359185a --- /dev/null +++ b/src/Plugin/Block/PersonPanel.php @@ -0,0 +1,57 @@ +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 .= "

"; + } + + // 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()); + return [ + '#cache' => [ + 'max-age' => 0, + ], + '#markup' => "
$markup
" + ]; + + } +}