pimcore / data-hub

Data delivery & consumption platform for Pimcore.
Other
125 stars 106 forks source link

[Improvement]: Allow all columns of an entity #642

Open mhstudioos opened 1 year ago

mhstudioos commented 1 year ago

Improvement description

Hi

Not sure if this is already possible but couldn't find proper docs about it. Is it possible to allow all collumns/properties of an entity in the datahub without selecting them all via the interface?

config:

` schema: queryEntities: Car: id: Car name: Car columnConfig: columns:

                                attributes:
                                    attribute: sku
                                    label: Sku
                                    dataType: input
                                isOperator: false
                            -
                                attributes:
                                    attribute: workingTitle
                                    label: 'Working Title'
                                    dataType: input
                                isOperator: false
                            -
                                attributes:
                                    attribute: description
                                    label: Description
                                    dataType: wysiwyg
                                isOperator: false`
SamyMP commented 1 year ago

It would be great to have this feature. In the meantime, I created a command that generates the file config to expose every attributes of every dataobjects of the database. You could arrange it to pass the list of desired classes to expose. Here is the command :

<?php

namespace App\Command;

use Pimcore\Bundle\DataHubBundle\Configuration;
use Pimcore\Console\AbstractCommand;
use Pimcore\Model\DataObject\ClassDefinition;
use Pimcore\Model\DataObject\Localizedfield;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class GenerateGraphQLExport extends AbstractCommand
{
    protected function configure()
    {
        $this
                  ->setName('generate-graphql-export');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $classList = new \Pimcore\Model\DataObject\ClassDefinition\Listing();
        $classes = $classList->load();

        $config = Configuration::getByName('YourConfig');
        if (!$config) {
            $output->writeln('YourConfig was not found...');
            return 1;
        }
        $configuration = $config->getConfiguration();

        /**
         * @var ClassDefinition $class
         */
        foreach ($classes as $class) {
            $output->writeln($class->getName());
            $classDefinition = $class->getFieldDefinitions();
            $configuration['schema']['queryEntities'][$class->getName()]['id'] = $class->getName();
            $configuration['schema']['queryEntities'][$class->getName()]['name'] = $class->getName();
            $configuration['schema']['queryEntities'][$class->getName()]['columnConfig']['columns'] = [];

            foreach ($classDefinition as $definition) {
                if ($definition->getName() === 'localizedfields') {
                    /**
                     * @var Localizedfield $definition
                     */
                    $definition = $definition->getChildren()[0];

                    $configuration['schema']['queryEntities'][$class->getName()]['columnConfig']['columns'][] =
                    [
                        'attributes' => [
                            'attribute' => $definition->getName(),
                            'label' => $definition->getTitle(),
                            'dataType' => $definition->getFieldtype(),
                        ],
                        'isOperator' => false,
                    ];
                } else {
                    $configuration['schema']['queryEntities'][$class->getName()]['columnConfig']['columns'][] =
                    [
                        'attributes' => [
                            'attribute' => $definition->getName(),
                            'label' => $definition->getTitle(),
                            'dataType' => $definition->getFieldtype(),
                        ],
                        'isOperator' => false,
                    ];
                }
            }

            foreach (['id', 'fullpath', 'key', 'published', 'creationDate', 'modificationDate', 'filename', 'classname'] as $systemKey) {
                $configuration['schema']['queryEntities'][$class->getName()]['columnConfig']['columns'][] =
                [
                    'attributes' => [
                        'attribute' => $systemKey,
                        'label' => $systemKey,
                        'dataType' => 'system',
                    ],
                    'isOperator' => false,
                ];
            }
        }

        $configuration['general']['modificationDate'] = time();

        $config->setConfiguration($configuration);
        $config->save();

        return 0;
    }
}

Note that the config "YourConfig" has to exist (even empty), the command doesn't create the config from scratch but modifies an existing one as it was easier to handle in my case

mhstudioos commented 1 year ago

thanks for sharing this :)

github-actions[bot] commented 8 months ago

Thanks a lot for reporting the issue. We did not consider the issue as "Pimcore:Priority", "Pimcore:ToDo" or "Pimcore:Backlog", so we're not going to work on that anytime soon. Please create a pull request to fix the issue if this is a bug report. We'll then review it as quickly as possible. If you're interested in contributing a feature, please contact us first here before creating a pull request. We'll then decide whether we'd accept it or not. Thanks for your understanding.