Pim-community-dev: Fatal error: Class 'Pim\Bundle\EnrichBundle\Form\Type\ImageType' not found

Created on 12 Apr 2017  路  6Comments  路  Source: akeneo/pim-community-dev

When trying to use a pim_enrich_image form type, a fatal error occurs.

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildForm($builder, $options);
        $builder
            ->add(
                'image',
                'pim_enrich_image'
            );
    }

It seems the class Pim\Bundle\EnrichBundle\Form\Type\ImageType has been removed (see #5048) and form type configuration and mentions should also be removed

Occurrences of pim_enrich_image are :

  • src/Pim/Bundle/EnrichBundle/Resources/config/form_types.yml
  • src/Pim/Bundle/CatalogBundle/Resources/config/attribute_types.yml
  • src/Pim/Bundle/CatalogBundle/spec/AttributeType/ImageTypeSpec.php
Waiting for feedback bug wanna-contribute

All 6 comments

Hi @gplanchat !
In what cases you are using pim_enrich_images ? We now try to avoid this using and replace it by JS forms :)

Hi @gplanchat,

can you elaborate what is your need please?

Micka毛l

It is in the context of building reference data (with PimCustomEntityBundle), I discussed about this with @fitn and @MarieMinasyan a few weeks ago.

They pointed me the field type has been removed from Akeneo, but we need those field types either in the core or in an additional bundle or component. The fatal error is unexpected and adds doubt on the valid implementation of our own feature(s).

There is no field to help uploading the image. Marie pointed me the class Oro\Bundle\UserBundle\Entity\EventListener\UploadedImageSubscriber was providing what was needed to upload those sort of files with a akeneo_file_storage_file_info field type. Romain told me the case of translatable images was not integrated to the requirements.

I also discussed on the Magento Slack channel with developer who wanted to add a WYSIWYG field to a category entity and he faced the exact same missing feature as I did with images.

Use Case : add an image field to a custom entity

<?php

class MyEntityWithPictogram extends AbstractCustomEntity
{
    /**
     * @var FileInfoInterface
     */
    private function $image;

    /**
     * @return string
     */
    public function getCustomEntityName()
    {
        return 'my_entity_with_pictogram';
    }

    /**
     * @return FileInfoInterface
     */
    public function getImage()
    {
        return $this->image;
    }

    /**
     * @param FileInfoInterface $image
     */
    public function setImage(FileInfoInterface $image)
    {
        $this->image = $image;
    }
}

Use Case : add an image field to a translatable custom entity

<?php

class MyTranslatableEntityWithPictogram extends AbstractTranslatableCustomEntity
{
    /**
     * @return string
     */
    public function getCustomEntityName()
    {
        return 'my_entity_with_pictogram';
    }

    /**
     * @return string
     */
    public function getTranslationFQCN()
    {
        return MyTranslatableEntityWithPictogramTranslation::class;
    }
}

class MyTranslatableEntityWithPictogramTranslation extends AbstractTranslation
{
    /**
     * @var FileInfoInterface
     */
    private function $image;

    /**
     * @return FileInfoInterface
     */
    public function getImage()
    {
        return $this->image;
    }

    /**
     * @param FileInfoInterface $image
     */
    public function setImage(FileInfoInterface $image)
    {
        $this->image = $image;
    }
}

Same needs about the upload field, but this time on a translation entity.

Use Case : add an image field to a translatable custom entity, with a fallback

<?php

class MyTranslatableEntityWithPictogramFallback extends AbstractTranslatableCustomEntity
{
    /**
     * @var FileInfoInterface
     */
    private function $image;

    /**
     * @return string
     */
    public function getCustomEntityName()
    {
        return 'my_entity_with_pictogram';
    }

    /**
     * @return string
     */
    public function getTranslationFQCN()
    {
        return MyTranslatableEntityWithPictogramTranslation::class;
    }

    /**
     * @param string $locale
     *
     * @return FileInfoInterface
     */
    public function getImage($locale = null)
    {
        if (null === ($translation = $this->getTranslation($locale))) {
            return $this->image;
        }

        if (null === ($image = $translation->getImage())) {
            return $this->image;
        }

        return $image;
    }

    /**
     * @param FileInfoInterface $image
     */
    public function setImage(FileInfoInterface $image)
    {
        $this->image = $image;
    }
}

class MyTranslatableEntityWithPictogramFallbackTranslation extends AbstractTranslation
{
    /**
     * @var FileInfoInterface
     */
    private function $image;

    /**
     * @return FileInfoInterface
     */
    public function getImage()
    {
        return $this->image;
    }

    /**
     * @param FileInfoInterface $image
     */
    public function setImage(FileInfoInterface $image)
    {
        $this->image = $image;
    }
}

Hello Gregory.

Indeed, as of today, there is nothing on the front part to ease the creation of an image upload form.

I really do not recommend using the subscriber you are referring to, as it is Oro stuff, so it does not use our storage stack.

Sadly, you have no choice but to create your own form from scratch. The current upload form used on the product is very coupled with the rest of the product forms https://github.com/akeneo/pim-community-dev/blob/1.7/src/Pim/Bundle/EnrichBundle/Resources/public/js/product/field/media-field.js.

However, I think you can look at it to create your own form. You can see here https://github.com/akeneo/pim-community-dev/blob/1.7/src/Pim/Bundle/EnrichBundle/Resources/public/js/product/field/media-field.js#L83 that we use a REST Media controller https://github.com/akeneo/pim-community-dev/blob/1.7/src/Pim/Bundle/EnrichBundle/Controller/Rest/MediaController.php#L48 to upload product media.
This controller is completely independent from the product or the custom entities. So you can totally use it in your form through AJAX call. It returns the path where your file was uploaded.

You can then use our FileStorageBundle to manage this file as an Akeneo FileInfo entity. This bundle contains everything to create, update, fetch and delete files.

In your case, for instance, the akeneo_file_storage.file_storage.file.file_storer service (https://github.com/akeneo/pim-community-dev/blob/1.7/src/Akeneo/Bundle/FileStorageBundle/Resources/config/file_storage.yml#L11) will copy the uploaded file in the real Akeneo Storage directory, create (or update) the corresponding FileInfo entity, and finally delete the temporary uploaded file.

Regards,
Damien

Thanks @damien-carcel, I'll probably write a dedicated bundle for this.

@gplanchat feel free to close the issue if you consider your questions answered, and thanks for your great feedback!

Micka毛l

Was this page helpful?
0 / 5 - 0 ratings

Related issues

henryktews picture henryktews  路  4Comments

jjanvier picture jjanvier  路  4Comments

ronthedrummer picture ronthedrummer  路  3Comments

ewallteam picture ewallteam  路  6Comments

oliverde8 picture oliverde8  路  3Comments