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

Added Structured Table Type #353

Open
wants to merge 3 commits into
base: 1.x
Choose a base branch
from
Open
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
66 changes: 66 additions & 0 deletions src/Mapping/Operator/Factory/AsStructuredTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\DataImporterBundle\Mapping\Operator\Factory;

use Pimcore\Bundle\DataImporterBundle\Mapping\Operator\AbstractOperator;
use Pimcore\Bundle\DataImporterBundle\Mapping\Type\TransformationDataTypeService;
use Pimcore\Model\DataObject\Data\StructuredTable;

class AsStructuredTable extends AbstractOperator
{
/**
* @param mixed $inputData
* @param bool $dryRun
*
* @return StructuredTable|string
*/
public function process($inputData, bool $dryRun = false)
{
if (!is_array($inputData)) {
$inputData = [$inputData];
}
if ($dryRun) {
if (empty($inputData)) {
return "";
}
return (new StructuredTable($inputData))->getHtmlTable(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return a html table here?
Shouldn't be that in generateResultPreview, as for example here

array_map(function ($value, $label) {
return [
'key' => $value,
'label' => $label,
];
}, array_keys($inputData), array_keys(array_values($inputData)[0])),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$inputData might be empty/null ... will result in errors at this place.

array_map(function ($value) {
return [
'label' => $value,
];
}, array_keys($inputData)),
);
}
return new StructuredTable($inputData);
}

/**
* @param string $inputType
* @param int|null $index
*
* @return string
*/
public function evaluateReturnType(string $inputType, int $index = null): string
{
return TransformationDataTypeService::DEFAULT_ARRAY;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we would need to introduce there an extra type which just allows assignment to structured table fields, like we have it for quantity value, gallery etc.

}
}
4 changes: 3 additions & 1 deletion src/Mapping/Type/TransformationDataTypeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class TransformationDataTypeService
self::DEFAULT_ARRAY => [
'multiselect',
'countrymultiselect',
'languages'
'languages',
'table',
'structuredTable'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be moved to an extra type...

],
self::QUANTITY_VALUE => [
'quantityValue'
Expand Down
1 change: 1 addition & 0 deletions src/PimcoreDataImporterBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function getJsPaths(): array
'/bundles/pimcoredataimporter/js/pimcore/configuration/components/mapping/operator/trim.js',
'/bundles/pimcoredataimporter/js/pimcore/configuration/components/mapping/operator/numeric.js',
'/bundles/pimcoredataimporter/js/pimcore/configuration/components/mapping/operator/asArray.js',
'/bundles/pimcoredataimporter/js/pimcore/configuration/components/mapping/operator/asStructuredTable.js',
'/bundles/pimcoredataimporter/js/pimcore/configuration/components/mapping/operator/asCountries.js',
'/bundles/pimcoredataimporter/js/pimcore/configuration/components/mapping/operator/asGeopoint.js',
'/bundles/pimcoredataimporter/js/pimcore/configuration/components/mapping/operator/asGeobounds.js',
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/config/services/mapping.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ services:
tags:
- { name: "pimcore.datahub.data_importer.operator", type: "asCountries" }

Pimcore\Bundle\DataImporterBundle\Mapping\Operator\Factory\AsStructuredTable:
tags:
- { name: "pimcore.datahub.data_importer.operator", type: "asStructuredTable" }


# ---------------------
# data target services
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

pimcore.registerNS('pimcore.plugin.pimcoreDataImporterBundle.configuration.components.mapping.operator.asStructuredTable');
pimcore.plugin.pimcoreDataImporterBundle.configuration.components.mapping.operator.asStructuredTable = Class.create(pimcore.plugin.pimcoreDataImporterBundle.configuration.components.mapping.abstractOperator, {

type: 'asStructuredTable',

getMenuGroup: function () {
return this.menuGroups.dataTypes;
},

getIconClass: function () {
return "pimcore_icon_structuredTable";
},
});
1 change: 1 addition & 0 deletions src/Resources/translations/admin.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_numeric
plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_reduceArrayKeyValuePairs: Reduce Array KeyValue Pairs
plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_flattenArray: Flatten Array
plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_asArray: As Array
plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_asStructuredTable: As Structured Table
plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_asCountries: As Countries
plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_asGeopoint: As Geopoint
plugin_pimcore_datahub_data_importer_configpanel_transformation_pipeline_asGeobounds: As Geobounds
Expand Down