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.
This commit is contained in:
naomi 2018-04-12 15:11:25 +02:00
parent a2373ea7e7
commit 61c969d7f4
3 changed files with 339 additions and 1 deletions

View File

@ -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: { }

View File

@ -236,7 +236,7 @@ display:
admin_label: '' admin_label: ''
empty: true empty: true
tokenize: true tokenize: true
content: '<div class="content"><p><a class=''use-ajax'' data-dialog-type=''modal'' href=''/zencrm/contact_details/add/{{ raw_arguments.person }}?destination=/zencrm/person/{{ raw_arguments.person }}''>Add a set of contact details</a></p></div>' content: '<div class="content"><p><a class=''use-ajax'' data-dialog-type=''modal'' href=''/zencrm/contact_details/{{ raw_arguments.person }}/add?destination=/zencrm/person/{{ raw_arguments.person }}''>Add a set of contact details</a></p></div>'
plugin_id: text_custom plugin_id: text_custom
empty: { } empty: { }
relationships: { } relationships: { }
@ -302,3 +302,259 @@ display:
- 'languages:language_interface' - 'languages:language_interface'
- url - url
tags: { } 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: '<a class=''use-ajax'' data-dialog-type=''modal'' href=''/zencrm/contact_details/{{ id }}/edit?destination=/zencrm/person/{{ raw_arguments.person }}''>Edit</a>'
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: { }

View File

@ -0,0 +1,57 @@
<?php
namespace Drupal\zencrm\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'PersonPanel' block.
* If the person has no contact details it advises to create them.
* If they have no hats it advises to create them.
*
* @Block(
* id = "person_panel",
* admin_label = @Translation("Person Panel"),
* )
*/
class PersonPanel extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$person_id = \Drupal::routeMatch()->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 .= "<p>This person has no contact details yet. To get started, ";
$markup .= "<a class='use-ajax' data-dialog-type='modal' href = $link_to_add>Add a set of contact details</a>";
$markup .= "</p>";
}
// 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 .= "<p>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. </p>";
$plugin_manager = \Drupal::service('plugin.manager.block');
$block = $plugin_manager->createInstance('hat_creator', array());
}
$markup .= render($block->build());
return [
'#cache' => [
'max-age' => 0,
],
'#markup' => "<div>$markup</div>"
];
}
}