Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.6' into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kingjia90 committed Nov 23, 2023
2 parents 9c708be + 2530a31 commit 6c097cb
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 43 deletions.
8 changes: 3 additions & 5 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct($type, $path, $name = null, $configuration = null)
$this->setType($type);
$this->setPath($path);
$this->setName($name);
$this->setConfiguration($configuration ?? []);
$this->setConfiguration($configuration);
}

public function getObjectVars(): array
Expand Down Expand Up @@ -148,12 +148,10 @@ public function setType(string $type): void
*/
public function setConfiguration($configuration): void
{
if (is_array($configuration)) {
$configuration = json_decode(json_encode($configuration), true);
}
if (empty($this->getName())) {
if ($configuration && empty($this->getName())) {
$this->setName($configuration['configuration']['general']['name'] ?? null);
}

$this->configuration = $configuration;
}

Expand Down
26 changes: 26 additions & 0 deletions src/Event/GraphQL/AssetMetadataEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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\DataHubBundle\Event\GraphQL;

final class AssetMetadataEvents
{
/**
* @Event("Pimcore\Bundle\DataHubBundle\Event\GraphQL\Model\AssetEvent")
*
* @var string
*/
const PRE_RESOLVE = 'pimcore.datahub.graphql.asset.metadata.preResolve';
}
64 changes: 38 additions & 26 deletions src/GraphQL/Resolver/AssetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@

use Exception;
use GraphQL\Type\Definition\ResolveInfo;
use Pimcore\Bundle\DataHubBundle\Event\GraphQL\AssetMetadataEvents;
use Pimcore\Bundle\DataHubBundle\GraphQL\ElementDescriptor;
use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ElementTagTrait;
use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ServiceTrait;
use Pimcore\Bundle\DataHubBundle\WorkspaceHelper;
use Pimcore\Event\Model\AssetEvent;
use Pimcore\Model\Asset;
use Symfony\Component\EventDispatcher\EventDispatcher;

class AssetType
{
Expand Down Expand Up @@ -64,39 +67,48 @@ public function resolveTag($value = null, $args = [], $context = [], ResolveInfo
public function resolveMetadata($value = null, $args = [], $context = [], ResolveInfo $resolveInfo = null)
{
$asset = $this->getAssetFromValue($value, $context);
$metadata = $asset?->getMetadata(raw: true);
if (!$metadata) {
return null;
}

if ($asset) {
$metadata = $asset->getObjectVar('metadata');
if ($metadata) {
if (isset($args['ignore_language']) && $args['ignore_language']) {
return $metadata;
}
//Relational data would return as a comma separated list. each element type and id by `_`, eg. "object_154,asset_489"
$event = new AssetEvent($asset, [
'metadata' => $metadata,
'context' => $context
]);
/** @var EventDispatcher $eventDispatcher */
$eventDispatcher = \Pimcore::getContainer()->get('event_dispatcher');
$eventDispatcher->dispatch($event, AssetMetadataEvents::PRE_RESOLVE);
$metadata = $event->getArgument('metadata');

if (isset($args['ignore_language']) && $args['ignore_language']) {
return $metadata;
}

$map = [];
$keys = [];
$language = isset($args['language']) ? $args['language'] : $this->getGraphQlService()->getLocaleService()->findLocale();
$map = [];
$keys = [];
$language = $args['language'] ?? $this->getGraphQlService()->getLocaleService()->findLocale();

foreach ($metadata as $item) {
$keys[$item['name']] = 1;
$l = $item['language'] ? $item['language'] : 'default';
$map[$l][$item['name']] = $item;
}
$result = [];

foreach ($keys as $key => $found) {
if (isset($map[$language][$key])) {
$result[] = $map[$language][$key];
} elseif (isset($map['default'][$key])) {
$result[] = $map['default'][$key];
}
}
foreach ($metadata as $item) {
$keys[$item['name']] = 1;
$l = $item['language'] ?: 'default';
$map[$l][$item['name']] = $item;
}
$result = [];

if ($result) {
return $result;
}
foreach ($keys as $key => $found) {
if (isset($map[$language][$key])) {
$result[] = $map[$language][$key];
} elseif (isset($map['default'][$key])) {
$result[] = $map['default'][$key];
}
}

if ($result) {
return $result;
}

return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.ca.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.cs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.es.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.hu.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.it.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.nl.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.pl.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.pt_br.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down
99 changes: 99 additions & 0 deletions src/Resources/translations/admin.ro.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
plugin_pimcore_datahub_configpanel_error_adding_config: Error adding configuration
plugin_pimcore_datahub_configpanel: Configuration
plugin_pimcore_datahub_configpanel_invalid_name: Invalid name
plugin_pimcore_datahub_configpanel_invalid_length: Exceeded maximum configuration
name length 80 of characters
plugin_pimcore_datahub_configpanel_error_cloning_config: Error cloning configuration
plugin_pimcore_datahub_configpanel_enterclonekey_title: Clone
plugin_pimcore_datahub_configpanel_enterclonekey_enterclonekey_prompt: Name of clone
plugin_pimcore_datahub_configpanel_item_save_success: Configuration saved
plugin_pimcore_datahub_configpanel_item_saveerror: Configuration could not be saved
plugin_pimcore_datahub_configpanel_item_saveerror_permissions: Configuration cannot
be saved because it would deprive your update permissions. Please check the permissions
tab.
plugin_pimcore_datahub_configpanel_item_general: General
plugin_pimcore_datahub_configpanel_sqlObjectCondition: SQL Condition
plugin_pimcore_datahub_configpanel_schema: Schema Definition
plugin_pimcore_datahub_configpanel_schema_fields: Schema Fields
plugin_pimcore_datahub_configpanel_security: Security Definition
plugin_pimcore_datahub_configpanel_security_method: Method
plugin_pimcore_datahub_configpanel_security_method_apikey: API Key
plugin_pimcore_datahub_configpanel_fields: Fields
plugin_pimcore_datahub_configpanel_entity: Entity
plugin_pimcore_datahub_configpanel_root: Root Node
plugin_pimcore_datahub_fieldName: Field Name
plugin_pimcore_datahub_configpanel_condition_hint: This is a global SQL condition
in addition to the workspace settings that will be added to all queries
plugin_pimcore_datahub_configpanel_available_fields: Available Fields
plugin_pimcore_datahub_operator_thumbnail_config: Configuration
plugin_pimcore_datahub_operator_select_entity: Select Entity
plugin_pimcore_datahub_security_datahub_apikey: Datahub API Keys
plugin_pimcore_datahub_security_definition: Security Definition
plugin_pimcore_datahub_security_apikey_description: API key required for web service
access. One API key per line allowed. At least one key with minimum 16 characters
needs to be provided.
plugin_pimcore_datahub_config: Datahub Config
plugin_datahub_config: Datahub Config
plugin_datahub_adapter_graphql: Datahub Adapter - GraphQL
plugin_datahub_admin: Datahub Admin
plugin_pimcore_datahub_type_graphql: GraphQL
plugin_pimcore_datahub_workspace_permission_create: Create
plugin_pimcore_datahub_workspace_permission_read: Read
plugin_pimcore_datahub_workspace_permission_update: Update
plugin_pimcore_datahub_workspace_permission_delete: Delete
plugin_pimcore_datahub_graphql_open_explorer_in_iframe: Open in Iframe
plugin_pimcore_datahub_graphql_open_explorer_in_tab: Open in Tab
plugin_pimcore_datahub_graphql_query_schema: Query Schema
plugin_pimcore_datahub_graphql_mutation_schema: Mutation Schema
plugin_pimcore_datahub_graphql_iexplorer: iExplorer
plugin_pimcore_datahub_datatype_not_supported_yet: datatype '%s' not supported yet
operator_alias: Alias
operator_concatenator: Operator Concatenator
operator_dateformatter: Date Formatter
operator_element_counter: Element Counter
operator_text: Operator Text
operator_merge: Merge (deprecated)
operator_substring: Substring
operator_thumbnail: Thumbnail
operator_thumbnail_html: Thumbnail HTML
operator_translate_value: Operator Translate Value
operator_trimmer: Trimmer
mutationoperator_locale_switcher: Locale Switcher
mutationoperator_ifempty: IfEmpty
mutationoperator_locale_collector: Locale Collector
mutationoperator_locale_switcher_description: Switches to different language other
than the default language.
mutationoperator_ifempty_description: Only sets the value if current one is empty.
mutationoperator_locale_collector_description: Allows editing all languages for a
single field.
plugin_pimcore_datahub_query: Query
plugin_pimcore_datahub_mutation: Mutation
plugin_pimcore_datahub_graphql_special_schema: Generic Types
plugin_pimcore_datahub_graphql_special_document: Document
plugin_pimcore_datahub_graphql_special_document_folder: Document Folder
plugin_pimcore_datahub_graphql_special_asset: Asset
plugin_pimcore_datahub_graphql_special_asset_folder: Asset Folder
plugin_pimcore_datahub_graphql_special_object_folder: Object Folder
plugin_pimcore_datahub_graphql_special_asset_listing: Asset Listing
plugin_pimcore_datahub_graphql_special_translation_listing: Translation Listing
plugin_pimcore_datahub_graphql_special_translation: Translation
read: Read
plugin_pimcore_datahub_skip_permission_check: Skip Permission Check
plugin_pimcore_datahub_configpanel_permissions: Permissions
plugin_pimcore_datahub_graphql_permissions_roles: Role Permissions
plugin_pimcore_datahub_graphql_permissions_users: User Permissions
plugin_pimcore_datahub_operator_select_user: Select User
plugin_pimcore_datahub_operator_select_role: Select Role
plugin_pimcore_datahub_configpanel_user: User
plugin_pimcore_datahub_configpanel_role: Role
plugin_pimcore_datahub_disable_introspection: Disable Introspection
plugin_pimcore_datahub_security_introspection_description: 'Please note: When introspection
is disabled, the autocomplete feature will not work.'
plugin_pimcore_datahub_import: Import
plugin_pimcore_datahub_export: Export
...
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.sk.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.sv.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.th.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/translations/admin.zh_Hans.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
plugin_pimcore_datahub_toolbar: Datahub
plugin_pimcore_datahub_toolbar: Datahub Config
plugin_pimcore_datahub_configpanel_add: Add Configuration
plugin_pimcore_datahub_configpanel_enterkey_title: Add a new configuration
plugin_pimcore_datahub_configpanel_enterkey_prompt: Unique Identifier
Expand Down

0 comments on commit 6c097cb

Please sign in to comment.