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

How to create custom entity with wysiwyg text field? #83

Closed
msieracki opened this issue Mar 23, 2017 · 6 comments
Closed

How to create custom entity with wysiwyg text field? #83

msieracki opened this issue Mar 23, 2017 · 6 comments
Assignees

Comments

@msieracki
Copy link

msieracki commented Mar 23, 2017

Hello

I'm trying to create entity with WYSIWYG field. In Akeneo 1.5 I used pim_wysiwyg field type during form creation, but in Akeneo 1.7 it don't work.

$builder ->add( 'fieldName', 'pim_wysiwyg', array( 'label'=> 'Field Label', 'required'=> false ) );

Does anyone knows how to create form with WYSIWYG field for custom entity?

@jmleroux jmleroux self-assigned this Apr 5, 2017
@igormukhingmailcom
Copy link

Hi, @jmleroux
Any update here?
Thanks

@jjdiaz
Copy link

jjdiaz commented Dec 17, 2017

Same problem for me in 1.7 version. I can create a TextArea fields using the 'widget' modificator. But I can not use the wysiwyg editor.

Thanks and regards

@igormukhingmailcom
Copy link

Editor actually already at codebase and all you need to make it work is to add wysiwyg css class to some textareas. This is how to do this until pim_wysiwyg will be returned back officially:

<?php

namespace AppBundle\Form\Type;

use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;

class WysiwygType extends TextareaType
{
    /**
     * {@inheritdoc}
     */
    public function buildView(FormView $view, FormInterface $form, array $options)
    {

    }

    /**
     * {@inheritdoc}
     */
    public function getParent()
    {
        return 'textarea';
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'wysiwyg';
    }
}
# app/config/config.yml
twig:
    form:
        resources:
            - 'AppBundle:Form:pim-fields.html.twig'
# src/AppBundle/Resources/services.yml

services:

    form.type.wysiwyg:
        class: AppBundle\Form\Type\WysiwygType
        tags:
            - { name: form.type, alias: wysiwyg }
{# src/AppBundle/Resources/views/Form/pim-fields.html.twig #}
{% extends 'PimUIBundle:Form:pim-fields.html.twig' %}

{%- block wysiwyg_widget -%}
    {% set attr = attr|merge({'class': attr.class is defined ? attr.class ~ ' wysiwyg' : 'wysiwyg'}) %}
    <textarea {{ block('widget_attributes') }}>{{ value }}</textarea>
{%- endblock wysiwyg_widget -%}

Usage

Translatable custom WYSIWYG field for Category:

<?php

namespace AppBundle\Form\Type;

use AppBundle\Entity\Brand;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;

use Pim\Bundle\EnrichBundle\Form\Type\CategoryType as BaseCategoryType;

/**
 * Type for category properties
 */
class CategoryType extends BaseCategoryType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add(
            'longDescriptionTop',
            'pim_translatable_field',
            [
                'field'             => 'longDescriptionTop',
                'translation_class' => $this->translationDataClass,
                'entity_class'      => $this->dataClass,
                'property_path'     => 'translations',
                'widget'            => 'wysiwyg',
                'required'          => false,
            ]
        );
    }
}

@jmleroux
Copy link
Contributor

Thank you very much @igormukhingmailcom ,

I love when people share their knowledge with each other. That's the way open source should work!

@jmleroux
Copy link
Contributor

I added this explaination in the newly created WIKI: https://github.com/akeneo-labs/CustomEntityBundle/wiki/Frequently-Asked-Questions

If you think it should be part of the main doc, PR are welcome ;)

@jjdiaz
Copy link

jjdiaz commented Dec 19, 2017

Thank you very much Igor and Jean Marie. Very good job guys. I will try asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants