Magento 2.1 새로운 컴포넌트 타입 문제 추가


15

제품 양식 관리 페이지 의 사용자 정의 탭 (재정 의하여 추가됨)에서이 요소를 사용할 Company\Module\Data\Form\Element\PdfButton때라 는 새 양식 요소 유형을 version EE 2.0.7추가했습니다 Magento\Catalog\Block\Adminhtml\Product\Edit\Tabs.

Magento EE 2.1로 업그레이드 한 후 사용자 정의 탭이 사라졌습니다. 제품 페이지에 새 탭을 만들기 위해 수정자를 추가했습니다. 공급 업체 파일의 수정자를 복사하여 모듈에 새 탭을 추가하여 새 탭을 추가했습니다.

그러나 사용자 정의 요소를 사용하고 싶을 때. 그래서 메타 배열의 children 필드에 다음 코드를 추가했습니다.

$children[$website['id']] = [
                'arguments' => [
                    'data' => [
                        'config' => [
                            'dataType' => Form\Element\DataType\Number::NAME,
                            'componentType' => Form\Field::NAME,
                            'formElement' => Form\Element\Wysiwyg2::NAME,
                            'description' => __($website['name']),
                            'tooltip' => $tooltip,
                            'sortOrder' => $sortOrder,
                            'dataScope' => 'website_ids.' . $website['id'],
                            'label' => "Pdf Upload",
                            'valueMap' => [
                                'true' => (string)$website['id'],
                                'false' => '0',
                            ],
                            'value' => $isChecked ? (string)$website['id'] : '0',
                        ],
                    ],
                ],
            ];

이 후,를 복사하여 Form\Element\Wysiwyg붙여 넣습니다 Form\Element\Wysiwyg2. 에서 Wysiwyg2 클래스 :

<?php

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Ui\Component\Form\Element;

use Magento\Framework\Data\Form\Element\Editor;
use Magento\Framework\Data\Form;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\DataObject;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Ui\Component\Wysiwyg\ConfigInterface;

/**
 * Class Input
 */
class Wysiwyg2 extends AbstractElement
{
    const NAME = 'wysiwyg2';

    /**
     * @var Form
     */
    protected $form;

    /**
     * @var Editor
     */
    protected $editor;

    /**
     * @param ContextInterface $context
     * @param FormFactory $formFactory
     * @param ConfigInterface $wysiwygConfig
     * @param array $components
     * @param array $data
     * @param array $config
     */
    public function __construct(
        ContextInterface $context,
        FormFactory $formFactory,
        ConfigInterface $wysiwygConfig,
        array $components = [],
        array $data = [],
        array $config = []
    ) {
        $wysiwygConfigData = isset($config['wysiwygConfigData']) ? $config['wysiwygConfigData'] : [];
        $this->form = $formFactory->create();
        $this->editor = $this->form->addField(
            $context->getNamespace() . '_' . $data['name'],
            'Magento\Framework\Data\Form\Element\Editor',
            [
                'force_load' => true,
                'rows' => 20,
                'name' => $data['name'],
                'config' => $wysiwygConfig->getConfig($wysiwygConfigData),
                'wysiwyg' => isset($config['wysiwyg']) ? $config['wysiwyg'] : null,
            ]
        );
        $data['config']['content'] = $this->editor->getElementHtml();

        parent::__construct($context, $components, $data);
    }

    /**
     * Get component name
     *
     * @return string
     */
    public function getComponentName()
    {
        return static::NAME;
    }}

그러나 오류가 있으며 이름을 어디에 추가해야하는지 모르겠습니다.

1 exception(s):
Exception #0 (Magento\Framework\Exception\LocalizedException): The requested component ("wysiwyg2") is not found. Before using, you must add the implementation.

Exception #0 (Magento\Framework\Exception\LocalizedException): The requested component ("wysiwyg2") is not found. Before using, you must add the implementation.
#0 /var/www/vhosts/plchk/vendor/magento/module-ui/Model/Manager.php(207): Magento\Framework\View\Element\UiComponent\Config\Provider\Component\Definition->getComponentData('wysiwyg2')
#1 /var/www/vhosts/plchk/vendor/magento/framework/View/Element/UiComponentFactory.php(187): Magento\Ui\Model\Manager->createRawComponentData('wysiwyg2')
#2 /var/www/vhosts/plchk/vendor/magento/module-ui/Component/Form/Field.php(82): Magento\Framework\View\Element\UiComponentFactory->create(1, 'wysiwyg2', Array)
#3 /var/www/vhosts/plchk/vendor/magento/framework/View/Layout/Generator/UiComponent.php(148): Magento\Ui\Component\Form\Field->prepare()
#4 /var/www/vhosts/plchk/vendor/magento/framework/View/Layout/Generator/UiComponent.php(145): Magento\Framework\View\Layout\Generator\UiComponent->prepareComponent(Object(Magento\Ui\Component\Form\Field))

답변:


0

내가 이해하는 한, 호출하는 완전히 새로운 Ui 구성 요소 유형을 추가하려고합니다 wysiwyg2.

그러나 불행히도 새로운 Ui 구성 요소 유형을 추가하는 방법에 대한 알려진 문제가 있습니다 (예, 다른 유형). 원래 문제 확인할 수 있습니다 overhere을 .

Magento 2가 Ui 구성 요소를 제품 형태로 처리하는 방법을 자세히 살펴 보겠습니다.

공급 업체 / 마 젠토 / 모듈-카탈로그 /Ui/DataProvider/Product/Form/Modifier/Eav.php

/**
 * Add wysiwyg properties
 *
 * @param ProductAttributeInterface $attribute
 * @param array $meta
 * @return array
 */
private function customizeWysiwyg(ProductAttributeInterface $attribute, array $meta)
{
    if (!$attribute->getIsWysiwygEnabled()) {
        return $meta;
    }

    $meta['arguments']['data']['config']['formElement'] = WysiwygElement::NAME;
    $meta['arguments']['data']['config']['wysiwyg'] = true;
    $meta['arguments']['data']['config']['wysiwygConfigData'] = [
        'add_variables' => false,
        'add_widgets' => false,
        'add_directives' => true,
        'use_container' => true,
        'container_class' => 'hor-scroll',
    ];

    return $meta;
}

그리고 내부 public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupCode, $sortOrder)

633 행 (버전마다 다를 수 있음)

        case 'textarea':
            $meta = $this->customizeWysiwyg($attribute, $meta);
            break;

보시다시피에 customizeWysiwyg()하드 코딩 formElement되었습니다 wysiwyg.

wysiwyg2일하고 싶다면 setupAttributeMeta()다음과 같은 것을 추가 하기 위해 플러그인을 작성해야합니다.$meta = $this->customizeWysiwyg2($attribute, $meta);

그러나 나는 이것을 권장하지 않습니다.에 대한 환경 설정을 만들면 \Magento\Ui\Component\Form\Element\Wysiwyg생성자 내에서 다음과 같은 작업을 수행 할 수 있습니다

/**
 * Wysiwyg constructor.
 *
 * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context
 * @param \Magento\Framework\Data\FormFactory                          $formFactory
 * @param \Magento\Ui\Component\Wysiwyg\ConfigInterface                $wysiwygConfig
 * @param array                                                        $components
 * @param array                                                        $data
 * @param array                                                        $config
 */
public function __construct(
    ContextInterface $context,
    FormFactory $formFactory,
    ConfigInterface $wysiwygConfig,
    array $components = [],
    array $data = [],
    array $config = []
) {
    // Override the component for the WYSIWYG
    // This is not done using definition.xml due to https://github.com/magento/magento2/issues/5647
    $data['config']['component'] = 'Stackoverflow_Toan/js/form/element/wysiwyg';

    // Override the templates to include our KnockoutJS code
    $data['config']['template'] = 'Stackoverflow_Toan/wysiwyg';
    $data['config']['elementTmpl'] = 'Stackoverflow_Toan/wysiwyg';

    parent::__construct($context, $formFactory, $wysiwygConfig, $components, $data, $config);
}

이런 식으로, 당신은 당신의 자신의 jsComponent, 녹아웃 템플릿 등을 가질 수 있으며 원하는대로 커스터마이징 할 수 있습니다.

도움이 되었기를 바랍니다 :)

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.