Untitled

 avatar
unknown
php
2 months ago
2.1 kB
7
Indexable
<?php

namespace DT\Bundle\MigrationBundle\Migration\Schema;

use Oro\Bundle\EntityBundle\EntityConfig\DatagridScope;
use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;
use Oro\Bundle\EntityExtendBundle\Migration\OroOptions;

trait DefaultOroOptionsTrait
{
    protected const string ORO_OPTIONS = OroOptions::KEY;

    public function getDefaultOroOptions(string $entityName, string $fieldName, array $options = []): array
    {
        $defaultOptions = [
            'extend' => [
                'owner' => ExtendScope::OWNER_CUSTOM,
                'is_extend' => true,
                'without_default' => true,
            ],
            'entity' => [
                'label' =>
                    sprintf('dt.%s.%s.label', \strtolower($entityName), \strtolower($fieldName)),
                'description' =>
                    sprintf('dt.%s.%s.description', \strtolower($entityName), \strtolower($fieldName))
            ],
            'dataaudit' => ['auditable' => true],
            'datagrid' => ['is_visible' => DatagridScope::IS_VISIBLE_TRUE],
            'form' => ['is_enabled' => true],
            'view' => ['is_displayable' => true],
        ];

        return array_replace_recursive($defaultOptions, $options);
    }

    public function getHiddenOroOptions(string $entityName, string $fieldName, array $options = []): array
    {
        $hiddenOptions = $this->getDefaultOroOptions(
            $entityName,
            $fieldName,
            [
                'dataaudit' => ['auditable' => false],
                'datagrid' => ['is_visible' => DatagridScope::IS_VISIBLE_FALSE],
                'form' => ['is_enabled' => false],
                'importexport' => ['excluded' => true],
                'view' => ['is_displayable' => false],
                'frontend' => [
                    'is_displayable' => false,
                    'is_editable' => false
                ],
                'email' => ['available_in_template' => false]
            ]
        );

        return array_replace_recursive($hiddenOptions, $options);
    }
}
Editor is loading...
Leave a Comment