From 6adeff6e3fe6b4e74623d01df7f9b82aba787bf2 Mon Sep 17 00:00:00 2001 From: andrewbelcher Date: Fri, 10 Mar 2017 09:09:46 -0500 Subject: [PATCH 1/3] by andrewbelcher: Switch to entity row display and do some initial styling. --- ..._view_mode.user.contacts_dashboard_row.yml | 9 + .../page_manager.page.contacts_dashboard.yml | 2 +- .../install/views.view.contacts_dashboard.yml | 1042 ----------------- .../views.view.contacts_dashboard_indexed.yml | 927 +-------------- contacts.libraries.yml | 3 +- contacts.module | 79 +- css/dashboard.css | 26 + .../user--contacts-dashboard-row.html.twig | 9 + 8 files changed, 155 insertions(+), 1942 deletions(-) create mode 100644 config/install/core.entity_view_mode.user.contacts_dashboard_row.yml delete mode 100644 config/install/views.view.contacts_dashboard.yml create mode 100644 css/dashboard.css create mode 100644 templates/user--contacts-dashboard-row.html.twig diff --git a/config/install/core.entity_view_mode.user.contacts_dashboard_row.yml b/config/install/core.entity_view_mode.user.contacts_dashboard_row.yml new file mode 100644 index 0000000..5fd6726 --- /dev/null +++ b/config/install/core.entity_view_mode.user.contacts_dashboard_row.yml @@ -0,0 +1,9 @@ +langcode: en +status: true +dependencies: + module: + - user +id: user.contacts_dashboard_row +label: 'Contacts dashboard row' +targetEntityType: user +cache: true diff --git a/config/install/page_manager.page.contacts_dashboard.yml b/config/install/page_manager.page.contacts_dashboard.yml index 8d0c39c..62c05be 100644 --- a/config/install/page_manager.page.contacts_dashboard.yml +++ b/config/install/page_manager.page.contacts_dashboard.yml @@ -7,7 +7,7 @@ id: contacts_dashboard label: 'Contacts Dashboard' description: null use_admin_theme: true -path: '/admin/contacts' +path: /admin/contacts access_logic: and access_conditions: admin_user_condition: diff --git a/config/install/views.view.contacts_dashboard.yml b/config/install/views.view.contacts_dashboard.yml deleted file mode 100644 index d83e698..0000000 --- a/config/install/views.view.contacts_dashboard.yml +++ /dev/null @@ -1,1042 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - decoupled_auth - - user -id: contacts_dashboard -label: 'Contacts Dashboard' -module: views -description: '' -tag: '' -base_table: users_field_data -base_field: uid -core: 8.x -display: - default: - display_plugin: default - id: default - display_title: Master - position: 0 - display_options: - access: - type: perm - options: - perm: 'access user profiles' - cache: - type: tag - options: { } - query: - type: views_query - options: - disable_sql_rewrite: false - distinct: false - replica: false - query_comment: '' - query_tags: { } - exposed_form: - type: basic - options: - submit_button: Apply - reset_button: false - reset_button_label: Reset - exposed_sorts_label: 'Sort by' - expose_sort_order: true - sort_asc_label: Asc - sort_desc_label: Desc - pager: - type: full - options: - items_per_page: 10 - offset: 0 - id: 0 - total_pages: null - expose: - items_per_page: false - items_per_page_label: 'Items per page' - items_per_page_options: '5, 10, 25, 50' - items_per_page_options_all: false - items_per_page_options_all_label: '- All -' - offset: false - offset_label: Offset - tags: - previous: '‹ Previous' - next: 'Next ›' - first: '« First' - last: 'Last »' - quantity: 9 - style: - type: table - options: - grouping: { } - row_class: '' - default_row_class: true - override: true - sticky: false - caption: '' - summary: '' - description: '' - columns: - uid: uid - name: name - mail: mail - status: status - roles_target_id: roles_target_id - decoupled: decoupled - view_user: edit_user - nothing: edit_user - edit_user: edit_user - info: - uid: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - name: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - mail: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - status: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - roles_target_id: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - decoupled: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - view_user: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - nothing: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - edit_user: - sortable: false - default_sort_order: asc - align: '' - separator: '' - empty_column: false - responsive: '' - default: '-1' - empty_table: false - row: - type: fields - options: - inline: { } - separator: '' - hide_empty: false - default_field_elements: true - fields: - uid: - id: uid - table: users_field_data - field: uid - 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: user - entity_field: uid - plugin_id: field - name: - id: name - table: users_field_data - field: name - relationship: none - group_type: group - admin_label: '' - label: Name - exclude: false - alter: - alter_text: false - text: '' - make_link: true - path: 'admin/contacts/{{uid}}' - 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: false - ellipsis: false - 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: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: Anonymous - hide_empty: false - empty_zero: false - hide_alter_empty: false - click_sort_column: value - type: user_name - 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: user - entity_field: name - plugin_id: field - mail: - id: mail - table: users_field_data - field: mail - relationship: none - group_type: group - admin_label: '' - label: Email - 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: true - 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: basic_string - settings: { } - 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: user - entity_field: mail - plugin_id: field - status: - id: status - table: users_field_data - field: status - relationship: none - group_type: group - admin_label: '' - label: 'User status' - 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: true - 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: boolean - settings: - format: custom - format_custom_true: Active - format_custom_false: Blocked - 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: user - entity_field: status - plugin_id: field - roles_target_id: - id: roles_target_id - table: user__roles - field: roles_target_id - relationship: none - group_type: group - admin_label: '' - label: Roles - 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: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - type: separator - separator: ', ' - plugin_id: user_roles - decoupled: - id: decoupled - table: users - field: decoupled - relationship: none - group_type: group - admin_label: '' - label: 'Web account' - 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: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - entity_type: user - plugin_id: user_decoupled - nothing: - id: nothing - table: views - field: nothing - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: false - alter: - alter_text: true - text: view - make_link: true - path: 'admin/contacts/{{uid}}' - 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 - edit_user: - id: edit_user - table: users - field: edit_user - relationship: none - group_type: group - admin_label: '' - label: Operations - 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: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - text: edit - entity_type: user - plugin_id: entity_link_edit - filters: - combine: - id: combine - table: views - field: combine - relationship: none - group_type: group - admin_label: '' - operator: contains - value: '' - group: 1 - exposed: true - expose: - operator_id: combine_op - label: Search - description: 'Search by name or email' - use_operator: false - operator: combine_op - identifier: combine - required: false - remember: false - multiple: false - remember_roles: - authenticated: authenticated - anonymous: '0' - administrator: '0' - crm_indiv: '0' - crm_org: '0' - is_grouped: false - group_info: - label: '' - description: '' - identifier: '' - optional: true - widget: select - multiple: false - remember: false - default_group: All - default_group_multiple: { } - group_items: { } - fields: - name: name - mail: mail - plugin_id: combine - decoupled: - id: decoupled - table: users - field: decoupled - relationship: none - group_type: group - admin_label: '' - operator: '=' - value: '1' - group: 1 - exposed: true - expose: - operator_id: '' - label: 'Has web account?' - description: '' - use_operator: false - operator: decoupled_op - identifier: decoupled - required: false - remember: false - multiple: false - remember_roles: - authenticated: authenticated - anonymous: '0' - administrator: '0' - crm_indiv: '0' - crm_org: '0' - is_grouped: false - group_info: - label: '' - description: '' - identifier: '' - optional: true - widget: select - multiple: false - remember: false - default_group: All - default_group_multiple: { } - group_items: { } - entity_type: user - plugin_id: user_decoupled - uuid: - id: uuid - table: users - field: uuid - relationship: none - group_type: group - admin_label: '' - operator: '!=' - value: '0' - group: 1 - exposed: false - expose: - operator_id: '' - label: '' - description: '' - use_operator: false - operator: '' - identifier: '' - required: false - remember: false - multiple: false - remember_roles: - authenticated: authenticated - is_grouped: false - group_info: - label: '' - description: '' - identifier: '' - optional: true - widget: select - multiple: false - remember: false - default_group: All - default_group_multiple: { } - group_items: { } - entity_type: user - entity_field: uuid - plugin_id: string - sorts: { } - header: - result: - id: result - table: views - field: result - relationship: none - group_type: group - admin_label: '' - empty: false - content: 'Displaying @start - @end of @total' - plugin_id: result - footer: { } - empty: { } - relationships: { } - arguments: { } - display_extenders: { } - title: '' - use_ajax: false - filter_groups: - operator: AND - groups: - 1: AND - css_class: 'view-contacts-dashboard flex-container flex-fill flex-content-fill' - cache_metadata: - max-age: 0 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - url - - url.query_args - - user - - user.permissions - tags: { } - full: - display_plugin: block - id: full - display_title: 'Full listings' - position: 2 - display_options: - display_extenders: { } - exposed_block: true - allow: - configure_filters: configure_filters - items_per_page: false - offset: '0' - pager: '0' - hide_fields: '0' - sort_fields: '0' - disable_filters: '0' - configure_sorts: '0' - display_description: '' - cache_metadata: - max-age: 0 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - url - - url.query_args - - user - - user.permissions - tags: { } - simple: - display_plugin: block - id: simple - display_title: 'Simplified listings' - position: 2 - display_options: - display_extenders: { } - exposed_block: true - allow: - configure_filters: configure_filters - items_per_page: false - offset: '0' - pager: '0' - hide_fields: '0' - sort_fields: '0' - disable_filters: '0' - configure_sorts: '0' - display_description: '' - fields: - uid: - id: uid - table: users_field_data - field: uid - 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: user - entity_field: uid - plugin_id: field - name: - id: name - table: users_field_data - field: name - relationship: none - group_type: group - admin_label: '' - label: Name - exclude: false - alter: - alter_text: false - text: '' - make_link: true - path: 'admin/contacts/{{uid}}' - 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: false - ellipsis: false - 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: true - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: Anonymous - hide_empty: false - empty_zero: false - hide_alter_empty: false - click_sort_column: value - type: user_name - 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: user - entity_field: name - plugin_id: field - mail: - id: mail - table: users_field_data - field: mail - relationship: none - group_type: group - admin_label: '' - label: Email - 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: true - 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: basic_string - settings: { } - 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: user - entity_field: mail - plugin_id: field - defaults: - fields: false - header: false - title: false - css_class: false - header: { } - title: '' - css_class: 'view-contacts-dashboard flex-container flex-fill flex-content-fill' - cache_metadata: - max-age: 0 - contexts: - - 'languages:language_content' - - 'languages:language_interface' - - url - - url.query_args - - user - - user.permissions - tags: { } diff --git a/config/install/views.view.contacts_dashboard_indexed.yml b/config/install/views.view.contacts_dashboard_indexed.yml index f50f87b..942bc55 100644 --- a/config/install/views.view.contacts_dashboard_indexed.yml +++ b/config/install/views.view.contacts_dashboard_indexed.yml @@ -2,15 +2,8 @@ langcode: en status: true dependencies: config: - - field.storage.profile.crm_address - - field.storage.profile.crm_name - - field.storage.profile.crm_org_name - - field.storage.profile.crm_photo - - image.style.thumbnail - search_api.index.contacts_index module: - - address - - image - profile - search_api id: contacts_dashboard_indexed @@ -32,7 +25,7 @@ display: type: none options: { } cache: - type: tag + type: none options: { } query: type: search_api_query @@ -50,12 +43,17 @@ display: sort_asc_label: Asc sort_desc_label: Desc pager: - type: mini + type: full options: items_per_page: 10 offset: 0 id: 0 total_pages: null + tags: + previous: ‹‹ + next: ›› + first: '« First' + last: 'Last »' expose: items_per_page: false items_per_page_label: 'Items per page' @@ -64,381 +62,20 @@ display: items_per_page_options_all_label: '- All -' offset: false offset_label: Offset - tags: - previous: ‹‹ - next: ›› + quantity: 9 style: type: default options: - grouping: { } - row_class: '' + row_class: 'contacts-row flex-container flex-container-rows clearfix' default_row_class: true uses_fields: false row: - type: fields + type: search_api options: - inline: { } - separator: '' - hide_empty: false - default_field_elements: true - fields: - uid: - id: uid - table: search_api_index_contacts_index - field: uid - relationship: none - group_type: group - admin_label: '' - label: ID - 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: true - 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 - field_rendering: true - fallback_handler: search_api_numeric - fallback_options: - set_precision: false - precision: 0 - decimal: . - format_plural: false - format_plural_string: '' - prefix: '' - suffix: '' - link_to_item: false - multi_separator: ', ' - format_plural_values: - - '' - - '' - entity_type: null - entity_field: null - plugin_id: search_api_field - crm_org_name: - id: crm_org_name - table: search_api_index_contacts_index - field: crm_org_name - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: true - alter: - alter_text: false - text: '' - make_link: true - path: 'admin/contacts/{{ uid }}' - 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 - field_rendering: false - fallback_handler: search_api - fallback_options: - link_to_item: false - multi_separator: ', ' - plugin_id: search_api_field - crm_name: - id: crm_name - table: search_api_index_contacts_index - field: crm_name - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: true - alter: - alter_text: false - text: '' - make_link: true - path: 'admin/contacts/{{ uid }}' - 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 - field_rendering: true - fallback_handler: search_api - fallback_options: - link_to_item: false - multi_separator: ', ' - plugin_id: search_api_field - name: - id: name - table: search_api_datasource_contacts_index_entity_user - field: name - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: false - alter: - alter_text: false - text: '' - make_link: true - path: 'admin/contacts/{{ uid }}' - 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: '{{ crm_name }}{{ crm_org_name }}' - 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 - field_rendering: true - fallback_handler: search_api - fallback_options: - link_to_item: false - multi_separator: ', ' - entity_type: user - plugin_id: search_api_field - roles: - id: roles - table: search_api_index_contacts_index - field: roles - 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: target_id - type: entity_reference_label - settings: - link: false - group_column: target_id - 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 - field_rendering: true - fallback_handler: search_api_entity - fallback_options: - link_to_item: false - multi_separator: ', ' - display_methods: - user_role: - display_method: label - plugin_id: search_api_field + view_modes: + 'entity:user': + user: contacts_dashboard_row + fields: { } filters: search_api_fulltext: id: search_api_fulltext @@ -529,545 +166,41 @@ display: cache_metadata: max-age: 0 contexts: - - 'languages:language_content' - 'languages:language_interface' - url.query_args - tags: - - 'config:field.storage.profile.crm_name' - - 'config:field.storage.profile.crm_org_name' - simple: + tags: { } + full: display_plugin: block - id: simple - display_title: Search - position: 1 + id: full + display_title: Full + position: 2 display_options: display_extenders: { } display_description: '' + css_class: 'flex-container flex-fill flex-content-fill' + defaults: + css_class: false + fields: false + fields: { } exposed_block: true cache_metadata: max-age: 0 contexts: - - 'languages:language_content' - 'languages:language_interface' - url.query_args - tags: - - 'config:field.storage.profile.crm_name' - - 'config:field.storage.profile.crm_org_name' - full: + tags: { } + simple: display_plugin: block - id: full - display_title: Operations - position: 2 + id: simple + display_title: Simple + position: 1 display_options: display_extenders: { } display_description: '' - css_class: 'flex-container flex-fill flex-content-fill' - defaults: - css_class: false - fields: false - fields: - crm_photo: - id: crm_photo - table: search_api_index_contacts_index - field: crm_photo - 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: target_id - type: image - settings: - image_style: thumbnail - image_link: '' - group_column: '' - 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 - field_rendering: true - fallback_handler: search_api - fallback_options: - link_to_item: false - multi_separator: ', ' - plugin_id: search_api_field - uid: - id: uid - table: search_api_index_contacts_index - field: uid - relationship: none - group_type: group - admin_label: '' - label: ID - 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: true - 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 - field_rendering: true - fallback_handler: search_api_numeric - fallback_options: - set_precision: false - precision: 0 - decimal: . - format_plural: false - format_plural_string: '' - prefix: '' - suffix: '' - link_to_item: false - multi_separator: ', ' - format_plural_values: - - '' - - '' - entity_type: null - entity_field: null - plugin_id: search_api_field - crm_org_name: - id: crm_org_name - table: search_api_index_contacts_index - field: crm_org_name - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: true - alter: - alter_text: false - text: '' - make_link: true - path: 'admin/contacts/{{ uid }}' - 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 - field_rendering: false - fallback_handler: search_api - fallback_options: - link_to_item: false - multi_separator: ', ' - plugin_id: search_api_field - crm_name: - id: crm_name - table: search_api_index_contacts_index - field: crm_name - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: true - alter: - alter_text: false - text: '' - make_link: true - path: 'admin/contacts/{{ uid }}' - 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 - field_rendering: true - fallback_handler: search_api - fallback_options: - link_to_item: false - multi_separator: ', ' - plugin_id: search_api_field - name: - id: name - table: search_api_datasource_contacts_index_entity_user - field: name - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: false - alter: - alter_text: false - text: '' - make_link: true - path: 'admin/contacts/{{ uid }}' - 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: '{{ crm_name }}{{ crm_org_name }}' - 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 - field_rendering: true - fallback_handler: search_api - fallback_options: - link_to_item: false - multi_separator: ', ' - entity_type: user - plugin_id: search_api_field - roles: - id: roles - table: search_api_index_contacts_index - field: roles - 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: target_id - type: entity_reference_label - settings: - link: false - group_column: target_id - 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 - field_rendering: true - fallback_handler: search_api_entity - fallback_options: - link_to_item: false - multi_separator: ', ' - display_methods: - user_role: - display_method: label - plugin_id: search_api_field - crm_address: - id: crm_address - table: search_api_entity_profile - field: crm_address - relationship: profile_crm_indiv - group_type: group - admin_label: '' - label: '' - exclude: false - alter: - alter_text: true - text: '{{ crm_address__administrative_area }} {{ crm_address__postal_code }}' - 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: langcode - type: address_default - settings: { } - group_column: '' - 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 - field_rendering: true - fallback_handler: search_api - fallback_options: - link_to_item: false - multi_separator: ', ' - entity_type: profile - plugin_id: search_api_field exposed_block: true cache_metadata: max-age: 0 contexts: - - 'languages:language_content' - 'languages:language_interface' - url.query_args - tags: - - 'config:field.storage.profile.crm_address' - - 'config:field.storage.profile.crm_name' - - 'config:field.storage.profile.crm_photo' + tags: { } diff --git a/contacts.libraries.yml b/contacts.libraries.yml index 9c929ea..88ffd1e 100644 --- a/contacts.libraries.yml +++ b/contacts.libraries.yml @@ -6,10 +6,11 @@ contacts-ajax-tabs: - core/jquery - core/drupal.ajax -contacts-dashboard: +dashboard: version: 1.x css: theme: + css/dashboard.css: {} css/dashboard-blocks.css: {} contacts.icons: diff --git a/contacts.module b/contacts.module index c279773..3083e96 100644 --- a/contacts.module +++ b/contacts.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Template\Attribute; +use Drupal\Core\Url; /** * Implements hook_theme(). @@ -32,6 +33,10 @@ function contacts_theme() { 'variables' => ['user' => NULL], 'template' => 'contacts-dash-summary', ], + 'user__contacts_dashboard_row' => [ + 'base hook' => 'user', + 'template' => 'user--contacts-dashboard-row', + ] ]; } @@ -156,6 +161,78 @@ function contacts_toolbar_alter(&$items) { function contacts_page_attachments(array &$attachments) { $current_path = \Drupal::service('path.current')->getPath(); if (substr($current_path, 0, 15) == '/admin/contacts') { - $attachments['#attached']['library'][] = 'contacts/contacts-dashboard'; + $attachments['#attached']['library'][] = 'contacts/dashboard'; + } +} + +/** + * Implements hook_theme_suggestions_HOOK(). + */ +function contacts_theme_suggestions_user(array $variables) { + $suggestions = []; + /* @var \Drupal\user\UserInterface $user */ + $user = $variables['elements']['#user']; + $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); + + $suggestions[] = 'user__' . $sanitized_view_mode; + foreach ($user->getRoles(TRUE) as $role) { + if (substr($role, 0, 4) == 'crm_') { + $suggestions[] = 'user__' . $role . '__'; + $suggestions[] = 'user__' . $role . '__' . $sanitized_view_mode; + + } + } + + return $suggestions; +} + +/** + * Implements hook_preprocess_HOOK(). + */ +function contacts_preprocess_user(&$variables) { + if ($variables['elements']['#view_mode'] != 'contacts_dashboard_row') { + return; + } + + /* @var \Drupal\user\UserInterface $user */ + $user = $variables['user']; + $image_display = [ + 'label' => 'hidden', + 'type' => 'image', + 'settings' => [ + 'image_style' => 'thumbnail', + ], + ]; + + // Set some defaults. + $variables['url'] = Url::fromRoute('page_manager.page_view_contacts_dashboard_contact', [ + 'user' => $user->id(), + ]); + $variables['label'] = $user->getDisplayName(); + $variables['image'] = ''; + $variables['address'] = ''; + + $roles = user_role_names(); + $variables['roles'] = implode(', ', array_intersect_key($roles, array_fill_keys($user->getRoles(), TRUE))); + + if ($user->hasRole('crm_indiv')) { + if ($profile = $user->profile_crm_indiv->entity) { + $variables['profile'] = $profile; + $variables['label'] = $profile->crm_name->value; + if ($profile->crm_photo[0]) { + $variables['image'] = $profile->crm_photo->view($image_display)[0]; + $variables['address'] = $profile->crm_address->locality; + } + } + } + elseif ($user->hasRole('crm_org')) { + if ($profile = $user->profile_crm_org->entity) { + $variables['profile'] = $profile; + $variables['label'] = $profile->crm_org_name->value; + if ($profile->crm_logo[0]) { + $variables['image'] = $profile->crm_logo->view($image_display)[0]; + } + $variables['address'] = $profile->crm_org_address->locality; + } } } diff --git a/css/dashboard.css b/css/dashboard.css new file mode 100644 index 0000000..c656f75 --- /dev/null +++ b/css/dashboard.css @@ -0,0 +1,26 @@ +.contacts-row { + padding: 0.5em 0; + border-bottom: 1px solid #ccc; +} +.contacts-row:last-child { + border-bottom: none; +} +.contacts-row > div { + margin: 0 0.5em; +} + +.contacts-row h3, +.contacts-row h6 { + margin: 0 0 0.5em; +} + +.contacts-row-image { + width: 100px; +} +.contacts-row-image img { + display: block; +} + +.contacts-row-supporting { + text-align: right; +} diff --git a/templates/user--contacts-dashboard-row.html.twig b/templates/user--contacts-dashboard-row.html.twig new file mode 100644 index 0000000..1d5ce13 --- /dev/null +++ b/templates/user--contacts-dashboard-row.html.twig @@ -0,0 +1,9 @@ +
{{ image }}
+
+ {% if label %}

{{ label }}

{% endif %} + {{ address }} +
+
+
ID: {{ user.id }}
+
{{ roles }}
+
From 83df4f0a063ac97e5bc2b0270333faa1d18c4974 Mon Sep 17 00:00:00 2001 From: andrewbelcher Date: Fri, 10 Mar 2017 09:54:04 -0500 Subject: [PATCH 2/3] by andrewbelcher: Switch to a block for the back to search link. --- ...cts_dashboard_contact-panels_variant-0.yml | 23 ++++++------ .../Block/ContactsDashboardBackLink.php | 36 +++++++++++++++++++ 2 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 src/Plugin/Block/ContactsDashboardBackLink.php diff --git a/config/install/page_manager.page_variant.contacts_dashboard_contact-panels_variant-0.yml b/config/install/page_manager.page_variant.contacts_dashboard_contact-panels_variant-0.yml index 316c2d0..fea7cbc 100644 --- a/config/install/page_manager.page_variant.contacts_dashboard_contact-panels_variant-0.yml +++ b/config/install/page_manager.page_variant.contacts_dashboard_contact-panels_variant-0.yml @@ -14,16 +14,6 @@ label: 'Contacts Dashboard - Contact' variant: panels_variant variant_settings: blocks: - 7c36ff39-3877-4db4-bc62-c6fb1388044e: - id: custom_text - label: 'Back to search' - provider: contacts - label_display: '0' - text: 'Back to search' - region: left - weight: -10 - uuid: 7c36ff39-3877-4db4-bc62-c6fb1388044e - context_mapping: { } ecd0d505-c665-4e76-830e-a6bb9ff91afc: id: 'views_block:contacts_dashboard_indexed-simple' label: '' @@ -33,7 +23,7 @@ variant_settings: items_per_page: none exposed: { } region: left - weight: -9 + weight: -2 uuid: ecd0d505-c665-4e76-830e-a6bb9ff91afc context_mapping: { } 659d4b6a-ca77-4e4a-a742-69fb23276995: @@ -74,7 +64,7 @@ variant_settings: label_display: '0' title: '[user:display-name]' region: header - weight: 0 + weight: -10 uuid: b1606cd6-76f3-4299-910d-79ad68b08223 context_mapping: { } d0612f8c-f829-405e-96b8-8e0bcc03018d: @@ -95,6 +85,15 @@ variant_settings: weight: -1 uuid: 4ffd41af-55d0-447e-8f50-19de97be6051 context_mapping: { } + 10589b20-3baa-41f2-93e4-c6d2c9b82bde: + id: contacts_back + label: 'Back to search' + provider: contacts + label_display: '0' + region: left + weight: -4 + uuid: 10589b20-3baa-41f2-93e4-c6d2c9b82bde + context_mapping: { } id: panels_variant uuid: 1b3702e1-e046-4560-b148-726eeb34f497 label: null diff --git a/src/Plugin/Block/ContactsDashboardBackLink.php b/src/Plugin/Block/ContactsDashboardBackLink.php new file mode 100644 index 0000000..49f9607 --- /dev/null +++ b/src/Plugin/Block/ContactsDashboardBackLink.php @@ -0,0 +1,36 @@ + 'link', + '#url' => Url::fromRoute('page_manager.page_view_contacts_dashboard'), + '#title' => $this->t('Back to search'), + '#options' => [ + 'attributes' => [ + 'class' => ['button'], + ], + ], + ]; + } + +} From d3df6862f7ff2d055210b549b37bba35dc14ac23 Mon Sep 17 00:00:00 2001 From: andrewbelcher Date: Fri, 10 Mar 2017 13:51:10 -0500 Subject: [PATCH 3/3] by andrewbelcher: Slight tidy up of listing preprocess and add test coverage. --- contacts.module | 3 +- .../user--contacts-dashboard-row.html.twig | 14 +- .../src/Functional/ContactsDashboardTest.php | 180 +++++++++++++++++- 3 files changed, 186 insertions(+), 11 deletions(-) diff --git a/contacts.module b/contacts.module index 3083e96..97deac2 100644 --- a/contacts.module +++ b/contacts.module @@ -205,6 +205,7 @@ function contacts_preprocess_user(&$variables) { ]; // Set some defaults. + // @todo: Simplify this when we have 'primary fields'. $variables['url'] = Url::fromRoute('page_manager.page_view_contacts_dashboard_contact', [ 'user' => $user->id(), ]); @@ -221,8 +222,8 @@ function contacts_preprocess_user(&$variables) { $variables['label'] = $profile->crm_name->value; if ($profile->crm_photo[0]) { $variables['image'] = $profile->crm_photo->view($image_display)[0]; - $variables['address'] = $profile->crm_address->locality; } + $variables['address'] = $profile->crm_address->locality; } } elseif ($user->hasRole('crm_org')) { diff --git a/templates/user--contacts-dashboard-row.html.twig b/templates/user--contacts-dashboard-row.html.twig index 1d5ce13..a96c43d 100644 --- a/templates/user--contacts-dashboard-row.html.twig +++ b/templates/user--contacts-dashboard-row.html.twig @@ -1,9 +1,13 @@ - +
+ {% if image %} + {{ image }} + {% endif %} +
- {% if label %}

{{ label }}

{% endif %} - {{ address }} + {% if label %}

{{ label }}

{% endif %} + {% if address %}
{{ address }}
{% endif %}
-
ID: {{ user.id }}
-
{{ roles }}
+
ID: {{ user.id }}
+ {% if roles %}
{{ roles }}
{% endif %}
diff --git a/tests/src/Functional/ContactsDashboardTest.php b/tests/src/Functional/ContactsDashboardTest.php index 70de298..b258980 100644 --- a/tests/src/Functional/ContactsDashboardTest.php +++ b/tests/src/Functional/ContactsDashboardTest.php @@ -2,6 +2,9 @@ namespace Drupal\Tests\contacts\Functional; +use Drupal\decoupled_auth\Entity\DecoupledAuthUser; +use Drupal\file\Entity\File; +use Drupal\profile\Entity\Profile; use Drupal\Tests\BrowserTestBase; /** @@ -35,10 +38,98 @@ protected function setUp() { $this->adminUser->save(); } + /** + * Create a contact of the given type. + * + * @param string $type + * The type of contact, either 'crm_indiv' or 'crm_org'. + * @param bool $decoupled + * Whether the user should be decoupled. Defaults to TRUE. + * + * @return \Drupal\decoupled_auth\Entity\DecoupledAuthUser + * The contact that was created. + */ + protected function createContact($type, $decoupled = TRUE) { + // Create our user. + $name = $this->randomMachineName(); + $contact = DecoupledAuthUser::create([ + 'name' => $decoupled ? NULL : $name, + 'mail' => $name . '@example.com', + 'status' => 1, + ]); + $contact->addRole($type); + $contact->save(); + + // Generate a random image. + $filesystem = $this->container->get('file_system'); + $tmp_file = $filesystem->tempnam('temporary://', 'contactImage_'); + $destination = $tmp_file . '.jpg'; + file_unmanaged_move($tmp_file, $destination, FILE_CREATE_DIRECTORY); + $path = $this->getRandomGenerator()->image($filesystem->realpath($destination), '100x100', '100x100'); + $image = File::create(); + $image->setFileUri($path); + $image->setOwnerId($contact->id()); + $image->setMimeType($this->container->get('file.mime_type.guesser')->guess($path)); + $image->setFileName($filesystem->basename($path)); + $destination = 'public://contactImage_' . $contact->id(); + $file = file_move($image, $destination, FILE_CREATE_DIRECTORY); + + // Build our profile. + switch ($type) { + case 'crm_indiv': + $values = [ + 'type' => 'crm_indiv', + 'crm_name' => $this->randomString(20), + 'crm_gender' => 'female', + 'crm_email' => $contact->getEmail(), + 'crm_address' => [ + 'country_code' => 'GB', + 'locality' => $this->randomString(), + ], + 'crm_photo' => $file->id(), + ]; + break; + + case 'crm_org': + $values = [ + 'type' => 'crm_org', + 'crm_org_name' => $this->randomString(20), + 'crm_org_email' => $contact->getEmail(), + 'crm_org_address' => [ + 'country_code' => 'GB', + 'locality' => $this->randomString(), + ], + 'crm_logo' => $file->id(), + ]; + break; + + default: + return $contact; + } + $values += [ + 'uid' => $contact->id(), + 'status' => 1, + 'is_default' => 1, + ]; + $profile = Profile::create($values); + $profile->save(); + + // @todo: Remove when onUpdate is added. + $contact->updateProfileFields([$type]); + return $contact; + } + /** * Test installing contacts and accessing the contact dashboard. */ public function testViewDashboard() { + // Create some same users. + $contacts[] = DecoupledAuthUser::load(1); + $contacts[] = $this->adminUser; + $contacts[] = $this->createContact('crm_indiv'); + $contacts[] = $this->createContact('crm_indiv', FALSE); + $contacts[] = $this->createContact('crm_org'); + // Check the site has installed successfully. $this->drupalGet(''); $this->assertSession()->statusCodeEquals(200); @@ -63,12 +154,91 @@ public function testViewDashboard() { $session->statusCodeEquals(200); $session->elementTextContains('css', '.page-title', 'Contacts'); + // Sort our contacts. + usort($contacts, function($a, $b) { + $a_indiv = $a->hasRole('crm_indiv'); + $b_indiv = $b->hasRole('crm_indiv'); + + // Deal with the scenario when one or more is not an individual as the + // sort is currently on an individual field. + if (!$a_indiv && !$b_indiv) { + return 0; + } + elseif (!$a_indiv) { + return -1; + } + elseif (!$b_indiv) { + return 1; + } + + // Otherwise we use strnatcmp() on the name. + $a_name = $a->profile_crm_indiv->entity->crm_name->value; + $b_name = $b->profile_crm_indiv->entity->crm_name->value; + return strnatcmp($a_name, $b_name); + }); + // Check our expected users are listed. - // @todo: Expand this as we get a proper listing in. - $session->elementTextContains('css', '.views-row:nth-child(1) .views-field-uid .field-content', 1); - $session->elementTextContains('css', '.views-row:nth-child(1) .views-field-name .field-content', 'admin'); - $session->elementTextContains('css', '.views-row:nth-child(2) .views-field-uid .field-content', 2); - $session->elementTextContains('css', '.views-row:nth-child(2) .views-field-name .field-content', $this->adminUser->getAccountName()); + $index = 1; + foreach ($contacts as $contact) { + // Gather our relevant values. + $values = []; + + $roles = user_role_names(); + $values['roles'] = implode(', ', array_intersect_key($roles, array_fill_keys($contact->getRoles(), TRUE))); + + if ($contact->hasRole('crm_indiv')) { + /* @var \Drupal\profile\Entity\ProfileInterface $profile */ + $profile = $contact->profile_crm_indiv->entity; + $values['label'] = $profile->crm_name->value; + $values['city'] = $profile->crm_address->locality; + $values['image'] = $profile->crm_photo->entity->getFileUri() ?: FALSE; + } + elseif ($contact->hasRole('crm_org')) { + /* @var \Drupal\profile\Entity\ProfileInterface $profile */ + $profile = $contact->profile_crm_org->entity; + $values['label'] = $profile->crm_org_name->value; + $values['city'] = $profile->crm_org_address->locality; + $values['image'] = $profile->crm_logo->entity->getFileUri() ?: FALSE; + } + else { + $values['label'] = $contact->getDisplayName(); + $values['city'] = FALSE; + $values['image'] = FALSE; + } + + // Check our row is correctly rendered. + $base_selector = ".views-row:nth-child({$index}) "; + + if ($values['image']) { + $session->elementAttributeContains('css', $base_selector . '.contacts-row-image a', 'href', 'admin/contacts/' . $contact->id()); + $session->elementAttributeContains('css', $base_selector . '.contacts-row-image img', 'src', 'contactImage_' . $contact->id()); + } + else { + $session->elementNotExists('css', $base_selector . '.contacts-row-image a'); + $session->elementNotExists('css', $base_selector . '.contacts-row-image img'); + } + + if ($values['label']) { + $session->elementAttributeContains('css', $base_selector . '.contacts-row-main h3.contact-label a', 'href', 'admin/contacts/' . $contact->id()); + $session->elementTextContains('css', $base_selector . '.contacts-row-main h3.contact-label a', $values['label']); + } + else { + $session->elementNotExists('css', $base_selector . '.contacts-row-main h3.contact-label'); + } + + $session->elementAttributeContains('css', $base_selector . '.contacts-row-supporting h6.contact-id a', 'href', 'admin/contacts/' . $contact->id()); + $session->elementTextContains('css', $base_selector . '.contacts-row-supporting h6.contact-id a', 'ID: ' . $contact->id()); + $element = $session->elementExists('css', $base_selector . '.contacts-row-supporting .contact-roles'); + + if ($values['roles']) { + $session->elementTextContains('css', $base_selector . '.contacts-row-supporting .contact-roles', $values['roles']); + } + else { + $session->elementNotExists('css', $base_selector . '.contacts-row-supporting .contact-roles'); + } + + $index++; + } } }