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

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

Closed
mhstudioos opened this issue Dec 1, 2022 · 3 comments · Fixed by #871
Closed

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

mhstudioos opened this issue Dec 1, 2022 · 3 comments · Fixed by #871

Comments

@mhstudioos
Copy link

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
Copy link
Contributor

SamyMP commented Dec 6, 2022

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
Copy link
Author

thanks for sharing this :)

Copy link

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.

@heigpa heigpa linked a pull request Sep 25, 2024 that will close this issue
@heigpa heigpa closed this as completed Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants