From 1cb8e99928a0a155b09a09ae73e2968899c529e6 Mon Sep 17 00:00:00 2001 From: paul121 Date: Wed, 19 May 2021 16:37:10 -0700 Subject: [PATCH 01/23] Include a url property to view assets in the geojson export view. --- .../views.view.farm_asset_geojson.yml | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/modules/core/location/config/optional/views.view.farm_asset_geojson.yml b/modules/core/location/config/optional/views.view.farm_asset_geojson.yml index 58f16751c..5b774b881 100644 --- a/modules/core/location/config/optional/views.view.farm_asset_geojson.yml +++ b/modules/core/location/config/optional/views.view.farm_asset_geojson.yml @@ -278,6 +278,59 @@ display: field_api_classes: false entity_type: asset plugin_id: asset_geometry + view_asset: + id: view_asset + table: asset + field: view_asset + relationship: none + group_type: group + admin_label: '' + label: url + 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: view + output_url_as_text: true + absolute: true + entity_type: asset + plugin_id: entity_link filters: { } sorts: { } header: { } @@ -561,6 +614,59 @@ display: field_api_classes: false entity_type: asset plugin_id: asset_geometry + view_asset: + id: view_asset + table: asset + field: view_asset + relationship: none + group_type: group + admin_label: '' + label: url + 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: view + output_url_as_text: true + absolute: true + entity_type: asset + plugin_id: entity_link defaults: fields: false cache_metadata: From 0a94bbb6d97df1cbeb1bbadf5465a836098b73af Mon Sep 17 00:00:00 2001 From: paul121 Date: Wed, 19 May 2021 16:45:47 -0700 Subject: [PATCH 02/23] Render the feature name as a link in popups if a url is provided. --- .../core/map/js/farmOS.map.behaviors.popup.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/core/map/js/farmOS.map.behaviors.popup.js b/modules/core/map/js/farmOS.map.behaviors.popup.js index 44efeab62..d7b20c3de 100644 --- a/modules/core/map/js/farmOS.map.behaviors.popup.js +++ b/modules/core/map/js/farmOS.map.behaviors.popup.js @@ -2,6 +2,18 @@ farmOS.map.behaviors.popup = { attach: function (instance) { + // Helper function to build the feature name as a link. + const featureName = function (feature) { + // Bail if either the name or url aren't defined. + const name = feature.get('name'); + const url = feature.get('url'); + if (name === undefined || url === undefined) { + return name; + } + // Build a link with the url and name. + return `${name}`; + } + // Create a popup and add it to the instance for future reference. instance.popup = instance.addPopup(function (event) { var content = ''; @@ -14,8 +26,9 @@ if (features !== undefined) { var names = []; features.forEach(function (item) { - if (item.get('name') !== undefined) { - names.push(item.get('name')); + const name = featureName(item); + if (name !== undefined) { + names.push(name); } }); if (names.length !== 0) { @@ -24,7 +37,7 @@ feature.set('name', names.length + ' item(s):'); } - var name = feature.get('name') || ''; + var name = featureName(feature) || ''; var description = feature.get('description') || ''; var measurement = instance.measureGeometry(feature.getGeometry(), instance.units); if (name !== '' || measurement !== '' || description !== '') { From 2ccf64541fe48021845b3262ba470798a375e762 Mon Sep 17 00:00:00 2001 From: paul121 Date: Tue, 9 Mar 2021 12:46:13 -0800 Subject: [PATCH 03/23] Create a map_popup view mode for assets. --- .../install/core.entity_view_mode.asset.map_popup.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 modules/ui/map/config/install/core.entity_view_mode.asset.map_popup.yml diff --git a/modules/ui/map/config/install/core.entity_view_mode.asset.map_popup.yml b/modules/ui/map/config/install/core.entity_view_mode.asset.map_popup.yml new file mode 100644 index 000000000..26dbea65f --- /dev/null +++ b/modules/ui/map/config/install/core.entity_view_mode.asset.map_popup.yml @@ -0,0 +1,9 @@ +langcode: en +status: true +dependencies: + module: + - asset +id: asset.map_popup +label: 'Map popup' +targetEntityType: asset +cache: true From b1b30889cca882b81c89c2a2883ae81f59a624fe Mon Sep 17 00:00:00 2001 From: paul121 Date: Tue, 9 Mar 2021 12:46:57 -0800 Subject: [PATCH 04/23] Render the asset map_popup view mode at /asset/*/map_popup --- modules/ui/map/farm_ui_map.module | 11 +++++++ modules/ui/map/farm_ui_map.routing.yml | 6 ++++ .../html--asset--map-popup.html.twig | 29 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 modules/ui/map/farm_ui_map.routing.yml create mode 100644 modules/ui/map/templates/html--asset--map-popup.html.twig diff --git a/modules/ui/map/farm_ui_map.module b/modules/ui/map/farm_ui_map.module index c2f4d4d89..44f7b2e1e 100644 --- a/modules/ui/map/farm_ui_map.module +++ b/modules/ui/map/farm_ui_map.module @@ -5,6 +5,17 @@ * The farmOS UI Map module. */ +/** + * Implements hook_theme(). + */ +function farm_ui_map_theme($existing, $type, $theme, $path) { + return [ + 'html__asset__map_popup' => [ + 'base hook' => 'html', + ], + ]; +} + /** * Implements hook_farm_dashboard_panes(). */ diff --git a/modules/ui/map/farm_ui_map.routing.yml b/modules/ui/map/farm_ui_map.routing.yml new file mode 100644 index 000000000..9ce3badf9 --- /dev/null +++ b/modules/ui/map/farm_ui_map.routing.yml @@ -0,0 +1,6 @@ +farm_ui_map.asset.map_popup: + path: '/asset/{asset}/map_popup' + defaults: + _entity_view: 'asset.map_popup' + requirements: + _entity_access: asset.view diff --git a/modules/ui/map/templates/html--asset--map-popup.html.twig b/modules/ui/map/templates/html--asset--map-popup.html.twig new file mode 100644 index 000000000..5878d2c46 --- /dev/null +++ b/modules/ui/map/templates/html--asset--map-popup.html.twig @@ -0,0 +1,29 @@ +{# +/** + * @file + * Theme override for rendering the asset map_popup view mode. + * + * Only renders the page content. This includes the asset, local actions + * and any other blocks added to this route. + * + * Variables: + * - logged_in: A flag indicating if user is logged in. + * - root_path: The root path of the current page (e.g., node, admin, user). + * - node_type: The content type for the current node, if the page is a node. + * - head_title: List of text elements that make up the head_title variable. + * May contain one or more of the following: + * - title: The title of the page. + * - name: The name of the site. + * - slogan: The slogan of the site. + * - page_top: Initial rendered markup. This should be printed before 'page'. + * - page: The rendered page markup. + * - page_bottom: Closing rendered markup. This variable should be printed after + * 'page'. + * - db_offline: A flag indicating if the database is offline. + * - placeholder_token: The token for generating head, css, js and js-bottom + * placeholders. + * + * @see template_preprocess_html() + */ +#} +{{ page.content }} From 77102245f3ab0561eba16d86db8068684c2ff3d8 Mon Sep 17 00:00:00 2001 From: paul121 Date: Tue, 9 Mar 2021 13:26:46 -0800 Subject: [PATCH 05/23] Add map_popup entity_view_display config for assets. --- ...ty_view_display.asset.animal.map_popup.yml | 115 ++++++++++++++++++ ...y_view_display.asset.compost.map_popup.yml | 69 +++++++++++ ...view_display.asset.equipment.map_popup.yml | 100 +++++++++++++++ ...ity_view_display.asset.group.map_popup.yml | 76 ++++++++++++ ...tity_view_display.asset.land.map_popup.yml | 69 +++++++++++ ...ity_view_display.asset.plant.map_popup.yml | 85 +++++++++++++ ...ty_view_display.asset.sensor.map_popup.yml | 69 +++++++++++ ...view_display.asset.structure.map_popup.yml | 76 ++++++++++++ ...ity_view_display.asset.water.map_popup.yml | 69 +++++++++++ 9 files changed, 728 insertions(+) create mode 100644 modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml create mode 100644 modules/asset/compost/config/optional/core.entity_view_display.asset.compost.map_popup.yml create mode 100644 modules/asset/equipment/config/optional/core.entity_view_display.asset.equipment.map_popup.yml create mode 100644 modules/asset/group/config/optional/core.entity_view_display.asset.group.map_popup.yml create mode 100644 modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml create mode 100644 modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml create mode 100644 modules/asset/sensor/config/optional/core.entity_view_display.asset.sensor.map_popup.yml create mode 100644 modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml create mode 100644 modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml diff --git a/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml b/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml new file mode 100644 index 000000000..3d9129421 --- /dev/null +++ b/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml @@ -0,0 +1,115 @@ +langcode: en +status: true +dependencies: + config: + - asset.type.animal + - core.entity_view_mode.asset.map_popup + module: + - farm_field + - farm_id_tag + - options + - text +id: asset.animal.map_popup +targetEntityType: asset +bundle: animal +mode: map_popup +content: + animal_type: + label: inline + type: entity_reference_label + weight: 3 + settings: + link: false + region: content + third_party_settings: { } + birthdate: + label: inline + type: timestamp + settings: + date_format: medium + custom_date_format: '' + timezone: '' + weight: 5 + region: content + third_party_settings: { } + flag: + label: inline + type: list_default + weight: 1 + region: content + settings: { } + third_party_settings: { } + group: + label: inline + type: entity_reference_label + weight: 10 + settings: + link: true + region: content + third_party_settings: { } + id_tag: + label: inline + type: id_tag + weight: 9 + region: content + settings: { } + third_party_settings: { } + is_castrated: + label: inline + type: hideable_boolean + settings: + format: default + format_custom_false: '' + format_custom_true: '' + hide_if_false: true + hide_if_true: false + weight: 7 + region: content + third_party_settings: { } + nickname: + label: inline + type: string + weight: 4 + region: content + settings: + link_to_entity: false + third_party_settings: { } + notes: + label: inline + type: text_default + weight: 2 + region: content + settings: { } + third_party_settings: { } + parent: + label: inline + type: entity_reference_label + weight: 8 + settings: + link: true + region: content + third_party_settings: { } + sex: + label: inline + type: list_default + weight: 6 + region: content + settings: { } + third_party_settings: { } + status: + label: inline + type: list_default + weight: 0 + region: content + settings: { } + third_party_settings: { } +hidden: + data: true + file: true + geometry: true + image: true + intrinsic_geometry: true + is_fixed: true + is_location: true + location: true + uid: true diff --git a/modules/asset/compost/config/optional/core.entity_view_display.asset.compost.map_popup.yml b/modules/asset/compost/config/optional/core.entity_view_display.asset.compost.map_popup.yml new file mode 100644 index 000000000..fd18c13e3 --- /dev/null +++ b/modules/asset/compost/config/optional/core.entity_view_display.asset.compost.map_popup.yml @@ -0,0 +1,69 @@ +langcode: en +status: true +dependencies: + config: + - asset.type.compost + - core.entity_view_mode.asset.map_popup + module: + - farm_id_tag + - options + - text +id: asset.compost.map_popup +targetEntityType: asset +bundle: compost +mode: map_popup +content: + flag: + label: inline + type: list_default + weight: 1 + region: content + settings: { } + third_party_settings: { } + group: + label: inline + type: entity_reference_label + weight: 5 + settings: + link: true + region: content + third_party_settings: { } + id_tag: + label: inline + type: id_tag + weight: 4 + region: content + settings: { } + third_party_settings: { } + notes: + label: inline + type: text_default + weight: 2 + region: content + settings: { } + third_party_settings: { } + parent: + label: inline + type: entity_reference_label + weight: 3 + settings: + link: true + region: content + third_party_settings: { } + status: + label: inline + type: list_default + weight: 0 + region: content + settings: { } + third_party_settings: { } +hidden: + data: true + file: true + geometry: true + image: true + intrinsic_geometry: true + is_fixed: true + is_location: true + location: true + uid: true diff --git a/modules/asset/equipment/config/optional/core.entity_view_display.asset.equipment.map_popup.yml b/modules/asset/equipment/config/optional/core.entity_view_display.asset.equipment.map_popup.yml new file mode 100644 index 000000000..98d04c299 --- /dev/null +++ b/modules/asset/equipment/config/optional/core.entity_view_display.asset.equipment.map_popup.yml @@ -0,0 +1,100 @@ +langcode: en +status: true +dependencies: + config: + - asset.type.equipment + - core.entity_view_mode.asset.map_popup + module: + - farm_id_tag + - options + - text +id: asset.equipment.map_popup +targetEntityType: asset +bundle: equipment +mode: map_popup +content: + flag: + label: inline + type: list_default + weight: 1 + region: content + settings: { } + third_party_settings: { } + group: + label: inline + type: entity_reference_label + weight: 8 + settings: + link: true + region: content + third_party_settings: { } + id_tag: + label: inline + type: id_tag + weight: 7 + region: content + settings: { } + third_party_settings: { } + location: + type: entity_reference_label + weight: 9 + region: content + label: inline + settings: + link: true + third_party_settings: { } + manufacturer: + label: inline + type: string + weight: 2 + region: content + settings: + link_to_entity: false + third_party_settings: { } + model: + label: inline + type: string + weight: 3 + region: content + settings: + link_to_entity: false + third_party_settings: { } + notes: + label: inline + type: text_default + weight: 5 + region: content + settings: { } + third_party_settings: { } + parent: + label: inline + type: entity_reference_label + weight: 6 + settings: + link: true + region: content + third_party_settings: { } + serial_number: + label: inline + type: string + weight: 4 + region: content + settings: + link_to_entity: false + third_party_settings: { } + status: + label: inline + type: list_default + weight: 0 + region: content + settings: { } + third_party_settings: { } +hidden: + data: true + file: true + geometry: true + image: true + intrinsic_geometry: true + is_fixed: true + is_location: true + uid: true diff --git a/modules/asset/group/config/optional/core.entity_view_display.asset.group.map_popup.yml b/modules/asset/group/config/optional/core.entity_view_display.asset.group.map_popup.yml new file mode 100644 index 000000000..d49532b39 --- /dev/null +++ b/modules/asset/group/config/optional/core.entity_view_display.asset.group.map_popup.yml @@ -0,0 +1,76 @@ +langcode: en +status: true +dependencies: + config: + - asset.type.group + - core.entity_view_mode.asset.map_popup + module: + - farm_id_tag + - options + - text +id: asset.group.map_popup +targetEntityType: asset +bundle: group +mode: map_popup +content: + flag: + label: inline + type: list_default + weight: 1 + region: content + settings: { } + third_party_settings: { } + group: + label: inline + type: entity_reference_label + weight: 5 + settings: + link: true + region: content + third_party_settings: { } + id_tag: + label: inline + type: id_tag + weight: 4 + region: content + settings: { } + third_party_settings: { } + location: + type: entity_reference_label + weight: 6 + region: content + label: inline + settings: + link: true + third_party_settings: { } + notes: + label: inline + type: text_default + weight: 2 + region: content + settings: { } + third_party_settings: { } + parent: + label: inline + type: entity_reference_label + weight: 3 + settings: + link: true + region: content + third_party_settings: { } + status: + label: inline + type: list_default + weight: 0 + region: content + settings: { } + third_party_settings: { } +hidden: + data: true + file: true + geometry: true + image: true + intrinsic_geometry: true + is_fixed: true + is_location: true + uid: true diff --git a/modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml b/modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml new file mode 100644 index 000000000..f254944f1 --- /dev/null +++ b/modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml @@ -0,0 +1,69 @@ +langcode: en +status: true +dependencies: + config: + - asset.type.land + - core.entity_view_mode.asset.map_popup + module: + - options + - text +id: asset.land.map_popup +targetEntityType: asset +bundle: land +mode: map_popup +content: + flag: + label: inline + type: list_default + weight: 1 + region: content + settings: { } + third_party_settings: { } + group: + label: inline + type: entity_reference_label + weight: 5 + settings: + link: true + region: content + third_party_settings: { } + land_type: + label: inline + type: list_default + weight: 2 + region: content + settings: { } + third_party_settings: { } + notes: + label: inline + type: text_default + weight: 3 + region: content + settings: { } + third_party_settings: { } + parent: + label: inline + type: entity_reference_label + weight: 4 + settings: + link: true + region: content + third_party_settings: { } + status: + label: inline + type: list_default + weight: 0 + region: content + settings: { } + third_party_settings: { } +hidden: + data: true + file: true + geometry: true + id_tag: true + image: true + intrinsic_geometry: true + is_fixed: true + is_location: true + location: true + uid: true diff --git a/modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml b/modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml new file mode 100644 index 000000000..4c58a8696 --- /dev/null +++ b/modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml @@ -0,0 +1,85 @@ +langcode: en +status: true +dependencies: + config: + - asset.type.plant + - core.entity_view_mode.asset.map_popup + module: + - farm_id_tag + - options + - text +id: asset.plant.map_popup +targetEntityType: asset +bundle: plant +mode: map_popup +content: + flag: + label: inline + type: list_default + weight: 2 + region: content + settings: { } + third_party_settings: { } + group: + label: inline + type: entity_reference_label + weight: 7 + settings: + link: true + region: content + third_party_settings: { } + id_tag: + label: inline + type: id_tag + weight: 6 + region: content + settings: { } + third_party_settings: { } + notes: + label: inline + type: text_default + weight: 4 + region: content + settings: { } + third_party_settings: { } + parent: + label: inline + type: entity_reference_label + weight: 5 + settings: + link: true + region: content + third_party_settings: { } + plant_type: + label: inline + type: entity_reference_label + weight: 0 + settings: + link: false + region: content + third_party_settings: { } + season: + label: inline + type: entity_reference_label + weight: 3 + settings: + link: false + region: content + third_party_settings: { } + status: + label: inline + type: list_default + weight: 1 + region: content + settings: { } + third_party_settings: { } +hidden: + data: true + file: true + geometry: true + image: true + intrinsic_geometry: true + is_fixed: true + is_location: true + location: true + uid: true diff --git a/modules/asset/sensor/config/optional/core.entity_view_display.asset.sensor.map_popup.yml b/modules/asset/sensor/config/optional/core.entity_view_display.asset.sensor.map_popup.yml new file mode 100644 index 000000000..085b7090e --- /dev/null +++ b/modules/asset/sensor/config/optional/core.entity_view_display.asset.sensor.map_popup.yml @@ -0,0 +1,69 @@ +langcode: en +status: true +dependencies: + config: + - asset.type.sensor + - core.entity_view_mode.asset.map_popup + module: + - farm_id_tag + - options + - text +id: asset.sensor.map_popup +targetEntityType: asset +bundle: sensor +mode: map_popup +content: + flag: + label: inline + type: list_default + weight: 1 + region: content + settings: { } + third_party_settings: { } + group: + label: inline + type: entity_reference_label + weight: 5 + settings: + link: true + region: content + third_party_settings: { } + id_tag: + label: inline + type: id_tag + weight: 4 + region: content + settings: { } + third_party_settings: { } + notes: + label: inline + type: text_default + weight: 2 + region: content + settings: { } + third_party_settings: { } + parent: + label: inline + type: entity_reference_label + weight: 3 + settings: + link: true + region: content + third_party_settings: { } + status: + label: inline + type: list_default + weight: 0 + region: content + settings: { } + third_party_settings: { } +hidden: + data: true + file: true + geometry: true + image: true + intrinsic_geometry: true + is_fixed: true + is_location: true + location: true + uid: true diff --git a/modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml b/modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml new file mode 100644 index 000000000..6b618900b --- /dev/null +++ b/modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml @@ -0,0 +1,76 @@ +langcode: en +status: true +dependencies: + config: + - asset.type.structure + - core.entity_view_mode.asset.map_popup + module: + - farm_id_tag + - options + - text +id: asset.structure.map_popup +targetEntityType: asset +bundle: structure +mode: map_popup +content: + flag: + label: inline + type: list_default + weight: 1 + region: content + settings: { } + third_party_settings: { } + group: + label: inline + type: entity_reference_label + weight: 6 + settings: + link: true + region: content + third_party_settings: { } + id_tag: + label: inline + type: id_tag + weight: 5 + region: content + settings: { } + third_party_settings: { } + notes: + label: inline + type: text_default + weight: 3 + region: content + settings: { } + third_party_settings: { } + parent: + label: inline + type: entity_reference_label + weight: 4 + settings: + link: true + region: content + third_party_settings: { } + status: + label: inline + type: list_default + weight: 0 + region: content + settings: { } + third_party_settings: { } + structure_type: + label: inline + type: list_default + weight: 2 + region: content + settings: { } + third_party_settings: { } +hidden: + data: true + file: true + geometry: true + image: true + intrinsic_geometry: true + is_fixed: true + is_location: true + location: true + uid: true diff --git a/modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml b/modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml new file mode 100644 index 000000000..516bca9d4 --- /dev/null +++ b/modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml @@ -0,0 +1,69 @@ +langcode: en +status: true +dependencies: + config: + - asset.type.water + - core.entity_view_mode.asset.map_popup + module: + - farm_id_tag + - options + - text +id: asset.water.map_popup +targetEntityType: asset +bundle: water +mode: map_popup +content: + flag: + label: inline + type: list_default + weight: 1 + region: content + settings: { } + third_party_settings: { } + group: + label: inline + type: entity_reference_label + weight: 5 + settings: + link: true + region: content + third_party_settings: { } + id_tag: + label: inline + type: id_tag + weight: 4 + region: content + settings: { } + third_party_settings: { } + notes: + label: inline + type: text_default + weight: 2 + region: content + settings: { } + third_party_settings: { } + parent: + label: inline + type: entity_reference_label + weight: 3 + settings: + link: true + region: content + third_party_settings: { } + status: + label: inline + type: list_default + weight: 0 + region: content + settings: { } + third_party_settings: { } +hidden: + data: true + file: true + geometry: true + image: true + intrinsic_geometry: true + is_fixed: true + is_location: true + location: true + uid: true From 8a1802ffd3928a4f98e595c6fa1ed07fcaa46fc3 Mon Sep 17 00:00:00 2001 From: paul121 Date: Wed, 19 May 2021 16:47:36 -0700 Subject: [PATCH 06/23] The asset_type_layers behavior depends on the popup behavior. --- modules/ui/map/farm_ui_map.libraries.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ui/map/farm_ui_map.libraries.yml b/modules/ui/map/farm_ui_map.libraries.yml index 0830a819c..276e6f79e 100644 --- a/modules/ui/map/farm_ui_map.libraries.yml +++ b/modules/ui/map/farm_ui_map.libraries.yml @@ -2,4 +2,5 @@ behavior_asset_type_layers: js: js/farmOS.map.behaviors.asset_type_layers.js: { } dependencies: + - farm_map/behavior_popup - farm_map/farm_map From 9f7906d2c65693a4eb342273ccd9c4eca6eff00c Mon Sep 17 00:00:00 2001 From: paul121 Date: Tue, 9 Mar 2021 12:56:35 -0800 Subject: [PATCH 07/23] Render the asset map_popup view inside map popups. --- .../farmOS.map.behaviors.asset_type_layers.js | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js b/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js index bdf116228..fa03d2bf1 100644 --- a/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js +++ b/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js @@ -59,30 +59,22 @@ }); } - // @todo: Display area details in popup. // Load area details via AJAX when an area popup is displayed. - // instance.popup.on('farmOS-map.popup', function (event) { - // var area_details = jQuery('.ol-popup-description .area-details'); - // if (area_details.attr('id') === undefined) { - // return; - // } - // area_details.html('test!'); - // var area_id = area_details.attr('id').replace('area-details-', ''); - // if (area_id) { - // area_details.html('Loading area details...'); - // jQuery.getJSON(Drupal.settings.farm_map.base_path + 'farm/area/' + area_id + '/details', function(data) { - // if (data) { - // area_details.html(data); - // var position = event.target.getPosition(); - // event.target.setPosition(); - // event.target.setPosition(position); - // } - // else { - // area_details.html(''); - // } - // }); - // } - // }); + instance.popup.on('farmOS-map.popup', function (event) { + var link = event.target.element.querySelector('.ol-popup-name a'); + if (link) { + var assetLink = link.getAttribute('href') + var description = event.target.element.querySelector('.ol-popup-description'); + description.innerHTML = 'Loading asset details...'; + fetch(assetLink + '/map_popup') + .then((response) => { + return response.text(); + }) + .then((html) => { + description.innerHTML = html; + }); + } + }); } }; }()); From fb995a061ccc9e998efb9ceb07bde731f6639552 Mon Sep 17 00:00:00 2001 From: paul121 Date: Tue, 9 Mar 2021 12:57:13 -0800 Subject: [PATCH 08/23] Ensure the popup is displayed inside the map. --- modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js b/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js index fa03d2bf1..dd71093e3 100644 --- a/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js +++ b/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js @@ -72,6 +72,7 @@ }) .then((html) => { description.innerHTML = html; + instance.popup.panIntoView(); }); } }); From 027adf68a2b7c595128ee8e096391c9867b5d7dd Mon Sep 17 00:00:00 2001 From: paul121 Date: Fri, 21 May 2021 11:43:19 -0700 Subject: [PATCH 09/23] Do not render asset urls as absolute urls. --- .../config/optional/views.view.farm_asset_geojson.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/location/config/optional/views.view.farm_asset_geojson.yml b/modules/core/location/config/optional/views.view.farm_asset_geojson.yml index 5b774b881..1c81f9f8d 100644 --- a/modules/core/location/config/optional/views.view.farm_asset_geojson.yml +++ b/modules/core/location/config/optional/views.view.farm_asset_geojson.yml @@ -328,7 +328,7 @@ display: hide_alter_empty: true text: view output_url_as_text: true - absolute: true + absolute: false entity_type: asset plugin_id: entity_link filters: { } @@ -664,7 +664,7 @@ display: hide_alter_empty: true text: view output_url_as_text: true - absolute: true + absolute: false entity_type: asset plugin_id: entity_link defaults: From 7ec99e10f2e9c56ba7edb1ba9107b93393741eb8 Mon Sep 17 00:00:00 2001 From: paul121 Date: Fri, 4 Jun 2021 12:14:28 -0700 Subject: [PATCH 10/23] Add link to view logs from the asset popup. --- modules/ui/map/farm_ui_map.module | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/modules/ui/map/farm_ui_map.module b/modules/ui/map/farm_ui_map.module index 44f7b2e1e..9009f6758 100644 --- a/modules/ui/map/farm_ui_map.module +++ b/modules/ui/map/farm_ui_map.module @@ -5,6 +5,10 @@ * The farmOS UI Map module. */ +use Drupal\Core\Entity\Display\EntityViewDisplayInterface; +use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Url; + /** * Implements hook_theme(). */ @@ -41,3 +45,26 @@ function farm_ui_map_module_implements_alter(&$implementations, $hook) { $implementations = array_merge([$module => $group], $implementations); } } + +/** + * Implements hook_ENTITY_TYPE_view(). + */ +function farm_ui_map_asset_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { + /** @var \Drupal\farm_entity\Plugin\Asset\AssetType\AssetTypeInterface $entity */ + + // Bail if not the map_popup view mode. + if ($view_mode !== 'map_popup') { + return $build; + } + + // Build link to view logs referencing the asset. + $url = Url::fromRoute('view.farm_log.page_asset', ['asset' => $entity->id(), 'log_type' => 'all']); + $build['logs_links'] = [ + '#type' => 'link', + '#title' => t('View logs'), + '#url' => $url, + '#weight' => -100, + ]; + + return $build; +} From 07416c6601669ceed97d4f533ce1da8607ae49da Mon Sep 17 00:00:00 2001 From: paul121 Date: Tue, 8 Jun 2021 14:45:26 -0700 Subject: [PATCH 11/23] Remove birthdate, is_castrated, nickname and sex fields from animal asset map_popup view mode. --- ...ty_view_display.asset.animal.map_popup.yml | 50 +++---------------- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml b/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml index 3d9129421..994a735b8 100644 --- a/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml +++ b/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml @@ -5,7 +5,6 @@ dependencies: - asset.type.animal - core.entity_view_mode.asset.map_popup module: - - farm_field - farm_id_tag - options - text @@ -22,16 +21,6 @@ content: link: false region: content third_party_settings: { } - birthdate: - label: inline - type: timestamp - settings: - date_format: medium - custom_date_format: '' - timezone: '' - weight: 5 - region: content - third_party_settings: { } flag: label: inline type: list_default @@ -42,38 +31,18 @@ content: group: label: inline type: entity_reference_label - weight: 10 + weight: 6 settings: link: true region: content - third_party_settings: { } + third_party_settings: { } id_tag: label: inline type: id_tag - weight: 9 + weight: 5 region: content settings: { } third_party_settings: { } - is_castrated: - label: inline - type: hideable_boolean - settings: - format: default - format_custom_false: '' - format_custom_true: '' - hide_if_false: true - hide_if_true: false - weight: 7 - region: content - third_party_settings: { } - nickname: - label: inline - type: string - weight: 4 - region: content - settings: - link_to_entity: false - third_party_settings: { } notes: label: inline type: text_default @@ -84,18 +53,11 @@ content: parent: label: inline type: entity_reference_label - weight: 8 + weight: 4 settings: link: true region: content third_party_settings: { } - sex: - label: inline - type: list_default - weight: 6 - region: content - settings: { } - third_party_settings: { } status: label: inline type: list_default @@ -104,12 +66,16 @@ content: settings: { } third_party_settings: { } hidden: + birthdate: true data: true file: true geometry: true image: true intrinsic_geometry: true + is_castrated: true is_fixed: true is_location: true location: true + nickname: true + sex: true uid: true From 8df4b1677217c60b9f6bbf7fc9f335ce096d05bf Mon Sep 17 00:00:00 2001 From: paul121 Date: Tue, 8 Jun 2021 14:48:17 -0700 Subject: [PATCH 12/23] Remove map_popup view modes for compost, group and sensor assets. --- ...y_view_display.asset.compost.map_popup.yml | 69 ----------------- ...ity_view_display.asset.group.map_popup.yml | 76 ------------------- ...ty_view_display.asset.sensor.map_popup.yml | 69 ----------------- 3 files changed, 214 deletions(-) delete mode 100644 modules/asset/compost/config/optional/core.entity_view_display.asset.compost.map_popup.yml delete mode 100644 modules/asset/group/config/optional/core.entity_view_display.asset.group.map_popup.yml delete mode 100644 modules/asset/sensor/config/optional/core.entity_view_display.asset.sensor.map_popup.yml diff --git a/modules/asset/compost/config/optional/core.entity_view_display.asset.compost.map_popup.yml b/modules/asset/compost/config/optional/core.entity_view_display.asset.compost.map_popup.yml deleted file mode 100644 index fd18c13e3..000000000 --- a/modules/asset/compost/config/optional/core.entity_view_display.asset.compost.map_popup.yml +++ /dev/null @@ -1,69 +0,0 @@ -langcode: en -status: true -dependencies: - config: - - asset.type.compost - - core.entity_view_mode.asset.map_popup - module: - - farm_id_tag - - options - - text -id: asset.compost.map_popup -targetEntityType: asset -bundle: compost -mode: map_popup -content: - flag: - label: inline - type: list_default - weight: 1 - region: content - settings: { } - third_party_settings: { } - group: - label: inline - type: entity_reference_label - weight: 5 - settings: - link: true - region: content - third_party_settings: { } - id_tag: - label: inline - type: id_tag - weight: 4 - region: content - settings: { } - third_party_settings: { } - notes: - label: inline - type: text_default - weight: 2 - region: content - settings: { } - third_party_settings: { } - parent: - label: inline - type: entity_reference_label - weight: 3 - settings: - link: true - region: content - third_party_settings: { } - status: - label: inline - type: list_default - weight: 0 - region: content - settings: { } - third_party_settings: { } -hidden: - data: true - file: true - geometry: true - image: true - intrinsic_geometry: true - is_fixed: true - is_location: true - location: true - uid: true diff --git a/modules/asset/group/config/optional/core.entity_view_display.asset.group.map_popup.yml b/modules/asset/group/config/optional/core.entity_view_display.asset.group.map_popup.yml deleted file mode 100644 index d49532b39..000000000 --- a/modules/asset/group/config/optional/core.entity_view_display.asset.group.map_popup.yml +++ /dev/null @@ -1,76 +0,0 @@ -langcode: en -status: true -dependencies: - config: - - asset.type.group - - core.entity_view_mode.asset.map_popup - module: - - farm_id_tag - - options - - text -id: asset.group.map_popup -targetEntityType: asset -bundle: group -mode: map_popup -content: - flag: - label: inline - type: list_default - weight: 1 - region: content - settings: { } - third_party_settings: { } - group: - label: inline - type: entity_reference_label - weight: 5 - settings: - link: true - region: content - third_party_settings: { } - id_tag: - label: inline - type: id_tag - weight: 4 - region: content - settings: { } - third_party_settings: { } - location: - type: entity_reference_label - weight: 6 - region: content - label: inline - settings: - link: true - third_party_settings: { } - notes: - label: inline - type: text_default - weight: 2 - region: content - settings: { } - third_party_settings: { } - parent: - label: inline - type: entity_reference_label - weight: 3 - settings: - link: true - region: content - third_party_settings: { } - status: - label: inline - type: list_default - weight: 0 - region: content - settings: { } - third_party_settings: { } -hidden: - data: true - file: true - geometry: true - image: true - intrinsic_geometry: true - is_fixed: true - is_location: true - uid: true diff --git a/modules/asset/sensor/config/optional/core.entity_view_display.asset.sensor.map_popup.yml b/modules/asset/sensor/config/optional/core.entity_view_display.asset.sensor.map_popup.yml deleted file mode 100644 index 085b7090e..000000000 --- a/modules/asset/sensor/config/optional/core.entity_view_display.asset.sensor.map_popup.yml +++ /dev/null @@ -1,69 +0,0 @@ -langcode: en -status: true -dependencies: - config: - - asset.type.sensor - - core.entity_view_mode.asset.map_popup - module: - - farm_id_tag - - options - - text -id: asset.sensor.map_popup -targetEntityType: asset -bundle: sensor -mode: map_popup -content: - flag: - label: inline - type: list_default - weight: 1 - region: content - settings: { } - third_party_settings: { } - group: - label: inline - type: entity_reference_label - weight: 5 - settings: - link: true - region: content - third_party_settings: { } - id_tag: - label: inline - type: id_tag - weight: 4 - region: content - settings: { } - third_party_settings: { } - notes: - label: inline - type: text_default - weight: 2 - region: content - settings: { } - third_party_settings: { } - parent: - label: inline - type: entity_reference_label - weight: 3 - settings: - link: true - region: content - third_party_settings: { } - status: - label: inline - type: list_default - weight: 0 - region: content - settings: { } - third_party_settings: { } -hidden: - data: true - file: true - geometry: true - image: true - intrinsic_geometry: true - is_fixed: true - is_location: true - location: true - uid: true From e7af56fe5fada70db2e60d0eeb38cd387e01e633 Mon Sep 17 00:00:00 2001 From: paul121 Date: Tue, 8 Jun 2021 14:57:15 -0700 Subject: [PATCH 13/23] Only display common fields on asset bundles that don't provide a map_popup view mode. --- modules/ui/map/farm_ui_map.module | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/ui/map/farm_ui_map.module b/modules/ui/map/farm_ui_map.module index 9009f6758..3879d55ab 100644 --- a/modules/ui/map/farm_ui_map.module +++ b/modules/ui/map/farm_ui_map.module @@ -57,6 +57,15 @@ function farm_ui_map_asset_view(array &$build, EntityInterface $entity, EntityVi return $build; } + // The default view mode is used if a map_popup view mode is not provided. + // Alter the default view mode to only include common fields. + if ($display->getMode() === 'default') { + $common_fields = ['flag', 'group', 'id_tag', 'location', 'notes', 'parent', 'status']; + $build = array_filter($build, function ($key) use ($common_fields) { + return strpos($key, '#') === 0 || in_array($key, $common_fields); + }, ARRAY_FILTER_USE_KEY); + } + // Build link to view logs referencing the asset. $url = Url::fromRoute('view.farm_log.page_asset', ['asset' => $entity->id(), 'log_type' => 'all']); $build['logs_links'] = [ From 7894368f2083668b9611155433d5752176aface5 Mon Sep 17 00:00:00 2001 From: paul121 Date: Tue, 8 Jun 2021 15:19:07 -0700 Subject: [PATCH 14/23] Add location field to map_popup view modes. --- ...ore.entity_view_display.asset.animal.map_popup.yml | 9 ++++++++- .../core.entity_view_display.asset.land.map_popup.yml | 11 +++++++++-- ...core.entity_view_display.asset.plant.map_popup.yml | 9 ++++++++- ....entity_view_display.asset.structure.map_popup.yml | 9 ++++++++- ...core.entity_view_display.asset.water.map_popup.yml | 9 ++++++++- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml b/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml index 994a735b8..ecaffa1c3 100644 --- a/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml +++ b/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml @@ -43,6 +43,14 @@ content: region: content settings: { } third_party_settings: { } + location: + type: entity_reference_label + weight: 7 + region: content + label: above + settings: + link: true + third_party_settings: { } notes: label: inline type: text_default @@ -75,7 +83,6 @@ hidden: is_castrated: true is_fixed: true is_location: true - location: true nickname: true sex: true uid: true diff --git a/modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml b/modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml index f254944f1..ad787fb5f 100644 --- a/modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml +++ b/modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml @@ -26,7 +26,7 @@ content: settings: link: true region: content - third_party_settings: { } + third_party_settings: { } land_type: label: inline type: list_default @@ -34,6 +34,14 @@ content: region: content settings: { } third_party_settings: { } + location: + type: entity_reference_label + weight: 6 + region: content + label: above + settings: + link: true + third_party_settings: { } notes: label: inline type: text_default @@ -65,5 +73,4 @@ hidden: intrinsic_geometry: true is_fixed: true is_location: true - location: true uid: true diff --git a/modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml b/modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml index 4c58a8696..aaf6de6e2 100644 --- a/modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml +++ b/modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml @@ -35,6 +35,14 @@ content: region: content settings: { } third_party_settings: { } + location: + type: entity_reference_label + weight: 8 + region: content + label: above + settings: + link: true + third_party_settings: { } notes: label: inline type: text_default @@ -81,5 +89,4 @@ hidden: intrinsic_geometry: true is_fixed: true is_location: true - location: true uid: true diff --git a/modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml b/modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml index 6b618900b..de1b17dea 100644 --- a/modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml +++ b/modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml @@ -35,6 +35,14 @@ content: region: content settings: { } third_party_settings: { } + location: + type: entity_reference_label + weight: 7 + region: content + label: above + settings: + link: true + third_party_settings: { } notes: label: inline type: text_default @@ -72,5 +80,4 @@ hidden: intrinsic_geometry: true is_fixed: true is_location: true - location: true uid: true diff --git a/modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml b/modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml index 516bca9d4..b5e2f1f41 100644 --- a/modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml +++ b/modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml @@ -35,6 +35,14 @@ content: region: content settings: { } third_party_settings: { } + location: + type: entity_reference_label + weight: 6 + region: content + label: above + settings: + link: true + third_party_settings: { } notes: label: inline type: text_default @@ -65,5 +73,4 @@ hidden: intrinsic_geometry: true is_fixed: true is_location: true - location: true uid: true From 3320662303b4a8501b2903aad71d54f123832b14 Mon Sep 17 00:00:00 2001 From: paul121 Date: Tue, 8 Jun 2021 15:21:30 -0700 Subject: [PATCH 15/23] Remove the farm_powered block from the map_popup view mode template. --- modules/ui/map/templates/html--asset--map-popup.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ui/map/templates/html--asset--map-popup.html.twig b/modules/ui/map/templates/html--asset--map-popup.html.twig index 5878d2c46..c46528b2f 100644 --- a/modules/ui/map/templates/html--asset--map-popup.html.twig +++ b/modules/ui/map/templates/html--asset--map-popup.html.twig @@ -26,4 +26,4 @@ * @see template_preprocess_html() */ #} -{{ page.content }} +{{ page.content|without('farm_powered') }} From a7c50858761c180c3db92410f0ed81c9784af0e8 Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Tue, 8 Jun 2021 22:07:19 -0400 Subject: [PATCH 16/23] Remove map_popup view modes for water assets. --- ...ity_view_display.asset.water.map_popup.yml | 76 ------------------- 1 file changed, 76 deletions(-) delete mode 100644 modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml diff --git a/modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml b/modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml deleted file mode 100644 index b5e2f1f41..000000000 --- a/modules/asset/water/config/optional/core.entity_view_display.asset.water.map_popup.yml +++ /dev/null @@ -1,76 +0,0 @@ -langcode: en -status: true -dependencies: - config: - - asset.type.water - - core.entity_view_mode.asset.map_popup - module: - - farm_id_tag - - options - - text -id: asset.water.map_popup -targetEntityType: asset -bundle: water -mode: map_popup -content: - flag: - label: inline - type: list_default - weight: 1 - region: content - settings: { } - third_party_settings: { } - group: - label: inline - type: entity_reference_label - weight: 5 - settings: - link: true - region: content - third_party_settings: { } - id_tag: - label: inline - type: id_tag - weight: 4 - region: content - settings: { } - third_party_settings: { } - location: - type: entity_reference_label - weight: 6 - region: content - label: above - settings: - link: true - third_party_settings: { } - notes: - label: inline - type: text_default - weight: 2 - region: content - settings: { } - third_party_settings: { } - parent: - label: inline - type: entity_reference_label - weight: 3 - settings: - link: true - region: content - third_party_settings: { } - status: - label: inline - type: list_default - weight: 0 - region: content - settings: { } - third_party_settings: { } -hidden: - data: true - file: true - geometry: true - image: true - intrinsic_geometry: true - is_fixed: true - is_location: true - uid: true From a7f2ea885f647d80c4be10c90d579767529f3952 Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Tue, 8 Jun 2021 23:26:26 -0400 Subject: [PATCH 17/23] Hide more fields in map popups: group, id_tag, parent, season, status. --- ...ty_view_display.asset.animal.map_popup.yml | 42 +++----------- ...view_display.asset.equipment.map_popup.yml | 46 +++------------- ...tity_view_display.asset.land.map_popup.yml | 35 +++--------- ...ity_view_display.asset.plant.map_popup.yml | 55 ++++--------------- ...view_display.asset.structure.map_popup.yml | 44 +++------------ modules/ui/map/farm_ui_map.module | 2 +- 6 files changed, 42 insertions(+), 182 deletions(-) diff --git a/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml b/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml index ecaffa1c3..9f5d11050 100644 --- a/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml +++ b/modules/asset/animal/config/optional/core.entity_view_display.asset.animal.map_popup.yml @@ -5,7 +5,6 @@ dependencies: - asset.type.animal - core.entity_view_mode.asset.map_popup module: - - farm_id_tag - options - text id: asset.animal.map_popup @@ -16,7 +15,7 @@ content: animal_type: label: inline type: entity_reference_label - weight: 3 + weight: 1 settings: link: false region: content @@ -24,30 +23,15 @@ content: flag: label: inline type: list_default - weight: 1 - region: content - settings: { } - third_party_settings: { } - group: - label: inline - type: entity_reference_label - weight: 6 - settings: - link: true - region: content - third_party_settings: { } - id_tag: - label: inline - type: id_tag - weight: 5 + weight: 0 region: content settings: { } third_party_settings: { } location: type: entity_reference_label - weight: 7 + weight: 3 region: content - label: above + label: inline settings: link: true third_party_settings: { } @@ -58,31 +42,19 @@ content: region: content settings: { } third_party_settings: { } - parent: - label: inline - type: entity_reference_label - weight: 4 - settings: - link: true - region: content - third_party_settings: { } - status: - label: inline - type: list_default - weight: 0 - region: content - settings: { } - third_party_settings: { } hidden: birthdate: true data: true file: true geometry: true + id_tag: true image: true intrinsic_geometry: true is_castrated: true is_fixed: true is_location: true nickname: true + parent: true sex: true + status: true uid: true diff --git a/modules/asset/equipment/config/optional/core.entity_view_display.asset.equipment.map_popup.yml b/modules/asset/equipment/config/optional/core.entity_view_display.asset.equipment.map_popup.yml index 98d04c299..1bec970aa 100644 --- a/modules/asset/equipment/config/optional/core.entity_view_display.asset.equipment.map_popup.yml +++ b/modules/asset/equipment/config/optional/core.entity_view_display.asset.equipment.map_popup.yml @@ -5,7 +5,6 @@ dependencies: - asset.type.equipment - core.entity_view_mode.asset.map_popup module: - - farm_id_tag - options - text id: asset.equipment.map_popup @@ -16,28 +15,13 @@ content: flag: label: inline type: list_default - weight: 1 - region: content - settings: { } - third_party_settings: { } - group: - label: inline - type: entity_reference_label - weight: 8 - settings: - link: true - region: content - third_party_settings: { } - id_tag: - label: inline - type: id_tag - weight: 7 + weight: 0 region: content settings: { } third_party_settings: { } location: type: entity_reference_label - weight: 9 + weight: 5 region: content label: inline settings: @@ -46,7 +30,7 @@ content: manufacturer: label: inline type: string - weight: 2 + weight: 1 region: content settings: link_to_entity: false @@ -54,7 +38,7 @@ content: model: label: inline type: string - weight: 3 + weight: 2 region: content settings: link_to_entity: false @@ -62,39 +46,27 @@ content: notes: label: inline type: text_default - weight: 5 + weight: 4 region: content settings: { } third_party_settings: { } - parent: - label: inline - type: entity_reference_label - weight: 6 - settings: - link: true - region: content - third_party_settings: { } serial_number: label: inline type: string - weight: 4 + weight: 3 region: content settings: link_to_entity: false third_party_settings: { } - status: - label: inline - type: list_default - weight: 0 - region: content - settings: { } - third_party_settings: { } hidden: data: true file: true geometry: true + id_tag: true image: true intrinsic_geometry: true is_fixed: true is_location: true + parent: true + status: true uid: true diff --git a/modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml b/modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml index ad787fb5f..f052faa8d 100644 --- a/modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml +++ b/modules/asset/land/config/optional/core.entity_view_display.asset.land.map_popup.yml @@ -15,52 +15,29 @@ content: flag: label: inline type: list_default - weight: 1 + weight: 0 region: content settings: { } third_party_settings: { } - group: - label: inline - type: entity_reference_label - weight: 5 - settings: - link: true - region: content - third_party_settings: { } land_type: label: inline type: list_default - weight: 2 + weight: 1 region: content settings: { } third_party_settings: { } location: type: entity_reference_label - weight: 6 + weight: 3 region: content - label: above + label: inline settings: link: true third_party_settings: { } notes: label: inline type: text_default - weight: 3 - region: content - settings: { } - third_party_settings: { } - parent: - label: inline - type: entity_reference_label - weight: 4 - settings: - link: true - region: content - third_party_settings: { } - status: - label: inline - type: list_default - weight: 0 + weight: 2 region: content settings: { } third_party_settings: { } @@ -73,4 +50,6 @@ hidden: intrinsic_geometry: true is_fixed: true is_location: true + parent: true + status: true uid: true diff --git a/modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml b/modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml index aaf6de6e2..1f8d6f3e5 100644 --- a/modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml +++ b/modules/asset/plant/config/optional/core.entity_view_display.asset.plant.map_popup.yml @@ -5,7 +5,6 @@ dependencies: - asset.type.plant - core.entity_view_mode.asset.map_popup module: - - farm_id_tag - options - text id: asset.plant.map_popup @@ -16,77 +15,43 @@ content: flag: label: inline type: list_default - weight: 2 - region: content - settings: { } - third_party_settings: { } - group: - label: inline - type: entity_reference_label - weight: 7 - settings: - link: true - region: content - third_party_settings: { } - id_tag: - label: inline - type: id_tag - weight: 6 + weight: 0 region: content settings: { } third_party_settings: { } location: type: entity_reference_label - weight: 8 + weight: 3 region: content - label: above + label: inline settings: link: true third_party_settings: { } notes: label: inline type: text_default - weight: 4 + weight: 2 region: content settings: { } third_party_settings: { } - parent: - label: inline - type: entity_reference_label - weight: 5 - settings: - link: true - region: content - third_party_settings: { } plant_type: label: inline type: entity_reference_label - weight: 0 - settings: - link: false - region: content - third_party_settings: { } - season: - label: inline - type: entity_reference_label - weight: 3 - settings: - link: false - region: content - third_party_settings: { } - status: - label: inline - type: list_default weight: 1 + settings: + link: false region: content - settings: { } third_party_settings: { } hidden: data: true file: true geometry: true + id_tag: true image: true intrinsic_geometry: true is_fixed: true is_location: true + parent: true + season: true + status: true uid: true diff --git a/modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml b/modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml index de1b17dea..4126beb51 100644 --- a/modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml +++ b/modules/asset/structure/config/optional/core.entity_view_display.asset.structure.map_popup.yml @@ -5,7 +5,6 @@ dependencies: - asset.type.structure - core.entity_view_mode.asset.map_popup module: - - farm_id_tag - options - text id: asset.structure.map_popup @@ -16,59 +15,29 @@ content: flag: label: inline type: list_default - weight: 1 - region: content - settings: { } - third_party_settings: { } - group: - label: inline - type: entity_reference_label - weight: 6 - settings: - link: true - region: content - third_party_settings: { } - id_tag: - label: inline - type: id_tag - weight: 5 + weight: 0 region: content settings: { } third_party_settings: { } location: type: entity_reference_label - weight: 7 + weight: 3 region: content - label: above + label: inline settings: link: true third_party_settings: { } notes: label: inline type: text_default - weight: 3 - region: content - settings: { } - third_party_settings: { } - parent: - label: inline - type: entity_reference_label - weight: 4 - settings: - link: true - region: content - third_party_settings: { } - status: - label: inline - type: list_default - weight: 0 + weight: 2 region: content settings: { } third_party_settings: { } structure_type: label: inline type: list_default - weight: 2 + weight: 1 region: content settings: { } third_party_settings: { } @@ -76,8 +45,11 @@ hidden: data: true file: true geometry: true + id_tag: true image: true intrinsic_geometry: true is_fixed: true is_location: true + parent: true + status: true uid: true diff --git a/modules/ui/map/farm_ui_map.module b/modules/ui/map/farm_ui_map.module index 3879d55ab..77a3a09d6 100644 --- a/modules/ui/map/farm_ui_map.module +++ b/modules/ui/map/farm_ui_map.module @@ -60,7 +60,7 @@ function farm_ui_map_asset_view(array &$build, EntityInterface $entity, EntityVi // The default view mode is used if a map_popup view mode is not provided. // Alter the default view mode to only include common fields. if ($display->getMode() === 'default') { - $common_fields = ['flag', 'group', 'id_tag', 'location', 'notes', 'parent', 'status']; + $common_fields = ['flag', 'notes', 'location']; $build = array_filter($build, function ($key) use ($common_fields) { return strpos($key, '#') === 0 || in_array($key, $common_fields); }, ARRAY_FILTER_USE_KEY); From bfcdcf4bbdf434ef84557b9d13366a6e4959734e Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Tue, 8 Jun 2021 23:34:07 -0400 Subject: [PATCH 18/23] Add "View logs" to an array of links rendered as markup with a pipe separator. --- modules/ui/map/farm_ui_map.module | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/ui/map/farm_ui_map.module b/modules/ui/map/farm_ui_map.module index 77a3a09d6..b4edd51ba 100644 --- a/modules/ui/map/farm_ui_map.module +++ b/modules/ui/map/farm_ui_map.module @@ -7,7 +7,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Url; +use Drupal\Core\Link; /** * Implements hook_theme(). @@ -66,12 +66,15 @@ function farm_ui_map_asset_view(array &$build, EntityInterface $entity, EntityVi }, ARRAY_FILTER_USE_KEY); } + // Build links. + $links = []; + // Build link to view logs referencing the asset. - $url = Url::fromRoute('view.farm_log.page_asset', ['asset' => $entity->id(), 'log_type' => 'all']); - $build['logs_links'] = [ - '#type' => 'link', - '#title' => t('View logs'), - '#url' => $url, + $links[] = Link::createFromRoute(t('View logs'), 'view.farm_log.page_asset', ['asset' => $entity->id(), 'log_type' => 'all'])->toString(); + + // Render links in a list. + $build['links'] = [ + '#markup' => '

' . implode(' | ', $links) . '

', '#weight' => -100, ]; From 85efcaf324d31621bd408a512def5a3aae88cb7b Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Tue, 8 Jun 2021 23:34:34 -0400 Subject: [PATCH 19/23] Add a link to "View assets in this location", if the asset is a location. --- modules/ui/map/farm_ui_map.module | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/ui/map/farm_ui_map.module b/modules/ui/map/farm_ui_map.module index b4edd51ba..482f53830 100644 --- a/modules/ui/map/farm_ui_map.module +++ b/modules/ui/map/farm_ui_map.module @@ -69,6 +69,12 @@ function farm_ui_map_asset_view(array &$build, EntityInterface $entity, EntityVi // Build links. $links = []; + // Build link to view assets located here. + // Only show this link on location assets. + if (\Drupal::service('asset.location')->isLocation($entity)) { + $links[] = Link::createFromRoute(t('View assets in this location'), 'view.farm_asset.page_location', ['asset' => $entity->id()])->toString(); + } + // Build link to view logs referencing the asset. $links[] = Link::createFromRoute(t('View logs'), 'view.farm_log.page_asset', ['asset' => $entity->id(), 'log_type' => 'all'])->toString(); From dbc2245d22fcb56c69a3e1c0c87708f24b707a06 Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Wed, 9 Jun 2021 08:21:09 -0400 Subject: [PATCH 20/23] Add name and type to allowed default fields. --- modules/ui/map/farm_ui_map.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ui/map/farm_ui_map.module b/modules/ui/map/farm_ui_map.module index 482f53830..b2e677228 100644 --- a/modules/ui/map/farm_ui_map.module +++ b/modules/ui/map/farm_ui_map.module @@ -60,7 +60,7 @@ function farm_ui_map_asset_view(array &$build, EntityInterface $entity, EntityVi // The default view mode is used if a map_popup view mode is not provided. // Alter the default view mode to only include common fields. if ($display->getMode() === 'default') { - $common_fields = ['flag', 'notes', 'location']; + $common_fields = ['name', 'type', 'flag', 'notes', 'location']; $build = array_filter($build, function ($key) use ($common_fields) { return strpos($key, '#') === 0 || in_array($key, $common_fields); }, ARRAY_FILTER_USE_KEY); From d4d54927a7f85e904b1cf4de683bbae873b37cab Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Wed, 9 Jun 2021 08:21:28 -0400 Subject: [PATCH 21/23] Fix default view mode condition. $display->getMode() never returns "default". Instead load the view mode options by bundle to see if map_popup options are defined. --- modules/ui/map/farm_ui_map.module | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ui/map/farm_ui_map.module b/modules/ui/map/farm_ui_map.module index b2e677228..cfe9a3498 100644 --- a/modules/ui/map/farm_ui_map.module +++ b/modules/ui/map/farm_ui_map.module @@ -59,7 +59,8 @@ function farm_ui_map_asset_view(array &$build, EntityInterface $entity, EntityVi // The default view mode is used if a map_popup view mode is not provided. // Alter the default view mode to only include common fields. - if ($display->getMode() === 'default') { + $view_mode_options = \Drupal::service('entity_display.repository')->getViewModeOptionsByBundle('asset', $entity->bundle()); + if (!array_key_exists($view_mode, $view_mode_options)) { $common_fields = ['name', 'type', 'flag', 'notes', 'location']; $build = array_filter($build, function ($key) use ($common_fields) { return strpos($key, '#') === 0 || in_array($key, $common_fields); From 1da9527d3df46cf821d9cd600e8ca47016bfa595 Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Wed, 9 Jun 2021 10:18:25 -0400 Subject: [PATCH 22/23] Add flag CSS to maps so that flags in popups are styled. --- modules/ui/theme/farm_ui_theme.module | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/ui/theme/farm_ui_theme.module b/modules/ui/theme/farm_ui_theme.module index 99cf87eb4..bddddc96e 100644 --- a/modules/ui/theme/farm_ui_theme.module +++ b/modules/ui/theme/farm_ui_theme.module @@ -25,6 +25,17 @@ function farm_ui_theme_preprocess_block(&$variables) { } } +/** + * Implements hook_preprocess_HOOK(). + */ +function farm_ui_theme_preprocess_farm_map(&$variables) { + + // We need to add the flag CSS to pages with maps in them because a user MAY + // click a popup which MAY have flags in it. Otherwise the flags do not get + // styled. + $variables['#attached']['library'] = 'farm_ui_theme/flag'; +} + /** * Implements hook_preprocess_HOOK(). */ From 26f55878cb5348161b4cf42acee6a0944b9628e2 Mon Sep 17 00:00:00 2001 From: Pedro Cambra Date: Wed, 9 Jun 2021 17:04:50 +0200 Subject: [PATCH 23/23] Map popup custom controller --- modules/ui/map/farm_ui_map.module | 11 ----- modules/ui/map/farm_ui_map.routing.yml | 9 ++++- .../farmOS.map.behaviors.asset_type_layers.js | 2 +- modules/ui/map/src/Controller/MapPopup.php | 40 +++++++++++++++++++ .../html--asset--map-popup.html.twig | 29 -------------- 5 files changed, 48 insertions(+), 43 deletions(-) create mode 100644 modules/ui/map/src/Controller/MapPopup.php delete mode 100644 modules/ui/map/templates/html--asset--map-popup.html.twig diff --git a/modules/ui/map/farm_ui_map.module b/modules/ui/map/farm_ui_map.module index cfe9a3498..9a4b7a358 100644 --- a/modules/ui/map/farm_ui_map.module +++ b/modules/ui/map/farm_ui_map.module @@ -9,17 +9,6 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Link; -/** - * Implements hook_theme(). - */ -function farm_ui_map_theme($existing, $type, $theme, $path) { - return [ - 'html__asset__map_popup' => [ - 'base hook' => 'html', - ], - ]; -} - /** * Implements hook_farm_dashboard_panes(). */ diff --git a/modules/ui/map/farm_ui_map.routing.yml b/modules/ui/map/farm_ui_map.routing.yml index 9ce3badf9..b9ff10739 100644 --- a/modules/ui/map/farm_ui_map.routing.yml +++ b/modules/ui/map/farm_ui_map.routing.yml @@ -1,6 +1,11 @@ farm_ui_map.asset.map_popup: - path: '/asset/{asset}/map_popup' + path: '/asset/{asset}/map-popup' defaults: - _entity_view: 'asset.map_popup' + _controller: '\Drupal\farm_ui_map\Controller\MapPopup::display' requirements: _entity_access: asset.view + asset: \d+ + options: + parameters: + asset: + type: entity:asset diff --git a/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js b/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js index dd71093e3..af8ec6ce9 100644 --- a/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js +++ b/modules/ui/map/js/farmOS.map.behaviors.asset_type_layers.js @@ -66,7 +66,7 @@ var assetLink = link.getAttribute('href') var description = event.target.element.querySelector('.ol-popup-description'); description.innerHTML = 'Loading asset details...'; - fetch(assetLink + '/map_popup') + fetch(assetLink + '/map-popup') .then((response) => { return response.text(); }) diff --git a/modules/ui/map/src/Controller/MapPopup.php b/modules/ui/map/src/Controller/MapPopup.php new file mode 100644 index 000000000..ab64aff3b --- /dev/null +++ b/modules/ui/map/src/Controller/MapPopup.php @@ -0,0 +1,40 @@ +entityTypeManager()->getViewBuilder($asset->getEntityTypeId()); + $build = $view_builder->view($asset, $this->displayMode); + // Render already exposes cache metadata, so no need to do it twice. + $response->setContent(render($build)); + return $response; + } + +} diff --git a/modules/ui/map/templates/html--asset--map-popup.html.twig b/modules/ui/map/templates/html--asset--map-popup.html.twig deleted file mode 100644 index c46528b2f..000000000 --- a/modules/ui/map/templates/html--asset--map-popup.html.twig +++ /dev/null @@ -1,29 +0,0 @@ -{# -/** - * @file - * Theme override for rendering the asset map_popup view mode. - * - * Only renders the page content. This includes the asset, local actions - * and any other blocks added to this route. - * - * Variables: - * - logged_in: A flag indicating if user is logged in. - * - root_path: The root path of the current page (e.g., node, admin, user). - * - node_type: The content type for the current node, if the page is a node. - * - head_title: List of text elements that make up the head_title variable. - * May contain one or more of the following: - * - title: The title of the page. - * - name: The name of the site. - * - slogan: The slogan of the site. - * - page_top: Initial rendered markup. This should be printed before 'page'. - * - page: The rendered page markup. - * - page_bottom: Closing rendered markup. This variable should be printed after - * 'page'. - * - db_offline: A flag indicating if the database is offline. - * - placeholder_token: The token for generating head, css, js and js-bottom - * placeholders. - * - * @see template_preprocess_html() - */ -#} -{{ page.content|without('farm_powered') }}