2

Context

I'm currently trying to add file relation to an entity of my OroPlatform project. The goal is to give the opportunity to the user to upload files on the create/update view of a specific entity.

I have read in the OroPlatform documentation that I have to create a new migration : https://doc.oroinc.com/master/backend/bundles/platform/AttachmentBundle/attachment-bundle-config/#attachment-bundle-file-types

Here is the migration I have created :

<?php

namespace Baltimore\Bundle\AppBundle\Migrations\Schema\v1_1_1;

use Doctrine\DBAL\Schema\Schema;

use Oro\Bundle\AttachmentBundle\Migration\Extension\AttachmentExtension;
use Oro\Bundle\AttachmentBundle\Migration\Extension\AttachmentExtensionAwareInterface;
use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

class AddAttachmentToBusinessUnit implements Migration, AttachmentExtensionAwareInterface
{
    /** @var AttachmentExtension */
    protected $attachmentExtension;

    /**
     * {@inheritdoc}
     */
    public function setAttachmentExtension(AttachmentExtension $attachmentExtension)
    {
        $this->attachmentExtension = $attachmentExtension;
    }

    /**
     * {@inheritdoc}
     */
    public function up(Schema $schema, QueryBag $queries)
    {
        $this->attachmentExtension->addFileRelation(
            $schema,
            'oro_business_unit',
            'document',
            [],
            15
        );
    }
}

And I have added this line to the update.html.twig of my entity: form_row(form.document)

Issue

When I try to access the update page, I have the following error :

"Neither the property "document" nor one of the methods "document()", "getdocument()"/"isdocument()"/"hasdocument()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView"."

I have warmup the cache in order to generate the accessors for my class and the method getDocument() exist in the generated file EX_OroOrganizationBundle_BusinessUnit.php

Also, it seems that the property has been successfully added to my entity :

enter image description here

Louis Bertin
  • 552
  • 2
  • 12

2 Answers2

1

To add a new form field, first, you have to define it in a form type extension, then you'll be able to access it from the template.

See How to Create a Form Type Extension.

Andrey Yatsenko
  • 1,936
  • 1
  • 11
  • 13
  • Thanks Andrey. Is it possible to use the 'oro_option' param in the migration file and use these lines ? 'form' => [ 'form_type' => FileType::class, ], I have already did that to add column with an existing table and it worked. – Louis Bertin Jul 14 '21 at 07:42
  • 1
    It's a fourth argument of addFileRelation method. e.g. https://github.com/oroinc/resource-library/blob/4.1/src/Oro/Bundle/ResourceLibraryBundle/Migrations/Schema/OroResourceLibraryBundleInstaller.php#L210-L225 – Andrey Yatsenko Jul 14 '21 at 14:25
  • Thanks for the link. Is there a place where I can read up on each item in the `oro_options` element? This could be very interesting. – Louis Bertin Jul 15 '21 at 08:51
  • 1
    Yes, you can use there the same options as in the ConfigField annotation: https://doc.oroinc.com/backend/configuration/annotation/config-field/ – Andrey Yatsenko Jul 16 '21 at 12:21
0

Finally my needs has changed, but I think I have the answer to solve this problem.
Here is what I will do:

/**
* {@inheritdoc}
*/
public function up(Schema $schema, QueryBag $queries)
{
   $this->attachmentExtension->addFileRelation(
      $schema,
      'oro_business_unit',
      'document',
      [
         'extend' => [
             'owner' => ExtendScope::OWNER_CUSTOM,
             'is_extend' => true
          ],
          'entity' => ['label'=>'oro.organization.businessunit.entity_label'],
      ],
      15
   );
}
Louis Bertin
  • 552
  • 2
  • 12