Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geometry/location fields to CSV importers #815

Draft
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions modules/core/import/modules/csv/migrations/csv_asset.yml
Expand Up @@ -23,6 +23,17 @@ process:
source: parents
- plugin: asset_lookup

# Is location/fixed booleans.
is_location:
plugin: boolean
source: is_location
is_fixed:
plugin: boolean
source: is_fixed

# Intrinsic geometry.
intrinsic_geometry: intrinsic_geometry

# Asset status.
status:
- plugin: get
Expand All @@ -36,10 +47,18 @@ third_party_settings:
columns:
- name: name
description: Name of the asset. Required.
- name: intrinsic_geometry
description: The intrinsic geometry of the asset in WKT format (typically used for fixed locations).
- name: parents
description: Parents of the asset. Accepts asset names, ID tags, UUIDs, and IDs. Multiple assets can be separated by commas with the whole cell wrapped in quotes.
- name: notes
description: Notes about the asset.
- name: is_location
description: Whether this asset is a location. Accepts most boolean values. Leave this blank to use the default for this asset type.
- name: is_fixed
description: Whether this asset has a fixed location. Accepts most boolean values. Leave this blank to use the default for this asset type.
- name: intrinsic_geometry
description: The intrinsic geometry of the asset in WKT format. This is only used if the asset has a fixed location.
- name: status
description: 'Status of the asset. Allowed values: active, archived. Defaults to active.'

Expand Down
14 changes: 14 additions & 0 deletions modules/core/import/modules/csv/migrations/csv_log.yml
Expand Up @@ -78,6 +78,14 @@ process:
- plugin: term_lookup
bundle: log_category

# Geometry.
geometry: geometry

# Is movement boolean.
is_movement:
plugin: boolean
source: is_movement

# Log status.
status:
- plugin: get
Expand All @@ -97,6 +105,8 @@ third_party_settings:
description: Assets referenced by the log. Accepts asset names, ID tags, UUIDs, and IDs. Multiple assets can be separated by commas with the whole cell wrapped in quotes.
- name: locations
description: Location assets where the log took place. Accepts asset names, ID tags, UUIDs, and IDs. Multiple assets can be separated by commas with the whole cell wrapped in quotes.
- name: geometry
description: The geometry of the log in WKT format.
- name: quantity
description: Numeric quantity value. Accepts integers or decimals.
- name: quantity measure
Expand All @@ -109,6 +119,10 @@ third_party_settings:
description: Notes about the log.
- name: categories
description: Log category taxonomy terms. Multiple terms can be separated by commas with the whole cell wrapped in quotes.
- name: geometry
description: The geometry of the log in WKT format.
- name: is_movement
description: Whether this log represents an asset movement. Accepts most boolean values. Leave this blank to use the default for this log type.
- name: status
description: 'Status of the log. Allowed values: pending, done. Defaults to done.'

Expand Down
47 changes: 47 additions & 0 deletions modules/core/migrate/src/Plugin/migrate/process/Boolean.php
@@ -0,0 +1,47 @@
<?php

namespace Drupal\farm_migrate\Plugin\migrate\process;

use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
* This plugin converts values to a boolean.
*
* @codingStandardsIgnoreStart
*
* Example usage:
* @code
* destination:
* plugin: 'entity:log'
* process:
* is_movement:
* plugin: boolean
* source: is_movement
* @endcode

* @codingStandardsIgnoreEnd
*
* @MigrateProcessPlugin(
* id = "boolean"
* )
*/
class Boolean extends ProcessPluginBase {

/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {

// If the trimmed value is an empty string, return NULL so that the field's
// default value will be used.
if (trim($value) === '') {
return NULL;
}

// Use PHP's filter_var() with FILTER_VALIDATE_BOOLEAN constant.
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}

}