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

#4040 Map Enterprise Attributes during Trellis Events import #4053

Open
wants to merge 16 commits into
base: issue/4039-add-enterprise-attributes-to-events
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
langcode: en
status: true
dependencies:
enforced:
module:
- az_core
id: az_enterprise_attributes_import
label: Enterprise Attributes
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags:
- Enterprise Attributes
- 'Enterprise Attributes'
- Taxonomy
migration_group: null
label: 'Enterprise Attributes'
source:
plugin: url
data_fetcher_plugin: http
data_parser_plugin: az_enterprise_attributes_import_json
urls: []
urls: { }
item_selector: attributes
ids:
key:
type: string

fields:
-
name: value
Expand All @@ -26,7 +35,6 @@ source:
-
name: parent
selector: parent

process:
name: value
field_az_attribute_key: key
Expand All @@ -45,12 +53,7 @@ process:
-
plugin: default_value
default_value: 0

destination:
plugin: entity:taxonomy_term
plugin: 'entity:taxonomy_term'
default_bundle: az_enterprise_attributes

dependencies:
enforced:
module:
- az_core
migration_dependencies: null
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
langcode: en
status: true
dependencies: { }
dependencies:
module:
- az_enterprise_attributes_import
id: az_enterprise_attributes_import
label: 'AZ Enterprise Attributes'
description: 'Import Enterprise Attributes'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Drupal\az_core\Plugin\migrate\process;

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

/**
* Flattens a multi-dimensional array.
*
* @code
* process:
* field_of_array_values:
* - plugin: az_enterprise_attributes_flatten
* source: enterprise_attributes_array
* - plugin: flatten
* @endcode
*/
#[MigrateProcess('az_enterprise_attributes_flatten')]
class AZEnterpriseAttributesArrayFlatten extends ProcessPluginBase {

/**
* {@inheritdoc}
*/
public function transform($input, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!is_array($input)) {
return $input;
}

// Include all first-level keys.
$result = array_keys($input);

foreach ($input as $value) {
if (is_array($value) && isset($value[0]) && is_string($value[0])) {
$result = array_merge($result, array_map('trim', explode(',', $value[0])));
}
}

return array_values(array_unique($result));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,56 @@ source:
name: publish
label: Publish
selector: Publish_Formula
-
name: az_enterprise_attributes
label: 'Enterprise Attributes'
selector: Attributes
trackleft marked this conversation as resolved.
Show resolved Hide resolved
-
name: format
label: 'Format'
selector: Format
ids:
id:
type: string
process:
pseudo_az_enterprise_attributes_format:
-
plugin: default_value
default_value: ['Event Format']
pseudo_az_enterprise_attributes_format_value:
-
plugin: explode
delimiter: ','
source: format
pseudo_az_enterprise_attributes_format_merged:
-
plugin: merge
source:
- '@pseudo_az_enterprise_attributes_format'
- '@pseudo_az_enterprise_attributes_format_value'
-
plugin: default_value
default_value: []
pseudo_az_enterprise_attributes:
-
plugin: skip_on_empty
method: process
source: az_enterprise_attributes
- plugin: az_enterprise_attributes_flatten
- plugin: flatten
trackleft marked this conversation as resolved.
Show resolved Hide resolved

field_az_enterprise_attributes:
- plugin: merge
source:
- '@pseudo_az_enterprise_attributes_format_merged'
- '@pseudo_az_enterprise_attributes'
-
plugin: entity_lookup
entity_type: taxonomy_term
bundle_key: vid
bundle: az_enterprise_attributes
value_key: name
ignore_case: true
title: name
field_az_trellis_id: id
field_az_link/uri: url
Expand Down
Loading