magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.39k stars 9.29k forks source link

Override TinyMCE5 to add a custom font on "style_formats" key on magento 2.4.5-p1 #37771

Open cemag44300 opened 1 year ago

cemag44300 commented 1 year ago

Summary

Preconditions and environment

Steps to reproduce

Expected result Custom style format is present in the formats list

Additional information Works on Magento before 2.4.5-p1.

Actual result

Release note No response

Issue closed This issue was closed but @engcom-Bravo don't override style_formats

Capture https://i.imgur.com/dFPP5vo.png

Examples

app/code/Custom/PageBuilder/registration.php

<?php
/**
 * Custom PageBuilder module
 */
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Custom_PageBuilder',
    __DIR__
);

app/code/Custom/PageBuilder/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Custom_PageBuilder" setup_version="1.0.0">
        <sequence>
            <module name="Magento_PageBuilder"/>
        </sequence>
    </module>
</config>

app/code/Custom/PageBuilder/etc/adminhtml/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Custom\PageBuilder\Plugin\Wysiwyg\ConfigPlugin">
        <arguments>
            <argument name="additionalSettings" xsi:type="array">
                <item name="style_formats" xsi:type="array">
                    <item name="setfiretotherain" xsi:type="array">
                        <item name="title" xsi:type="string">Set Fire to the Rain</item>
                        <item name="block" xsi:type="string">div</item>
                        <item name="classes" xsi:type="string">u-text-setfiretotherain</item>
                    </item>
                </item>
            </argument>
        </arguments>
    </type>
    <type name="Magento\PageBuilder\Model\Wysiwyg\DefaultConfigProvider">
        <plugin name="custom_pagebuilder_wysiwyg_plugin" type="Custom\PageBuilder\Plugin\Wysiwyg\ConfigPlugin" disabled="false"/>
    </type>
</config>

app/code/Custom/PageBuilder/Plugin/Wysiwyg/ConfigPlugin.php

<?php
namespace Custom\PageBuilder\Plugin\Wysiwyg;

use Magento\Framework\DataObject;
use Magento\Framework\View\Asset\Repository;
use Magento\PageBuilder\Model\Wysiwyg\DefaultConfigProvider;

/**
 * Class Config Plugin
 */
class ConfigPlugin
{
    /**
     * @var Repository
     */
    private $assetRepo;

    /**
     * @var array
     */
    private $additionalSettings;

    public function __construct(
        Repository $assetRepo,
        array $additionalSettings
    ) {
        $this->assetRepo = $assetRepo;
        $this->additionalSettings = $additionalSettings;
    }

    public function afterGetConfig(
        DefaultConfigProvider $subject,
        DataObject $result
    ) {
        $result->addData(['settings' => $this->additionalSettings ]);
        return $result;
    }
}

Proposed solution

No response

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @cemag44300. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

cemag44300 commented 12 months ago

@magento give me 2.4-develop instance - upcoming 2.4.5-p1 release

magento-deployment-service[bot] commented 12 months ago

Hi @cemag44300. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 12 months ago

Hi @cemag44300, here is your Magento Instance: https://88b358b2e02e00f5db390974b55da3fe.instances-prod.magento-community.engineering Admin access: https://88b358b2e02e00f5db390974b55da3fe.instances-prod.magento-community.engineering/admin_b4f7 Login: 0206e735 Password: 73df128385bd

m2-assistant[bot] commented 12 months ago

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-November commented 12 months ago

Hello @cemag44300,

Thank you for report and collaboration!

We tried to reproduce the issue on 2.4-develop. The issue is reproducible, please refer the below screencast.

https://github.com/magento/magento2/assets/60198231/9635f5a1-7791-48bc-8005-63ded52a63ac

As we can see in the screencast, We are not getting the custom "style formats" in TinyMCE editor.

Hence confirming the issue.

Below is the module. PbVendor.zip

Thanks.

github-jira-sync-bot commented 12 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-9200 is successfully created for this GitHub issue.

m2-assistant[bot] commented 12 months ago

:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

aasim110 commented 11 months ago

@magento I'm working on this

cemag44300 commented 9 months ago

@aasim110 Have you any feedback to patch this issue ?

m1kash commented 8 months ago

@cemag44300

For fix that issue: you have to use array instead associative array with keys.

for example:

<item name="style_formats" xsi:type="array">
                    <item name="0" xsi:type="array">
                        <item name="title" xsi:type="string">Heading 1</item>
                        <item name="block" xsi:type="string">h1</item>
                    </item>
                    <item name="1" xsi:type="array">
                        <item name="title" xsi:type="string">Heading 2</item>
                        <item name="block" xsi:type="string">h2</item>
                    </item>
                    <item name="2" xsi:type="array">
                        <item name="title" xsi:type="string">Heading 3</item>
                        <item name="block" xsi:type="string">h3</item>
                    </item>
</item>

or convert associative array with keys to simple array. Look into lib/tiny_mce_5/web/tinymce.d.ts:1499.

digiltd commented 8 months ago

@m1kash thank you so much for this, perfect timing :)