This topic contains 4 replies, has 2 voices, and was last updated by adriwan_kenoby 5 years, 8 months ago.
- Topic
Hi Oro Team,
I am trying to add an Image Relation to a custom entity.
However I always have this exception
123Neither the property "picture" nor one of the methods "getPicture()", "picture()", "isPicture()", "hasPicture()", "__get()" exist and have public access in class "Sinabs\Bundle\NewsBundle\Entity\News"Is their something missing in the documentation ?
This is the entity
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262<?phpnamespace Sinabs\Bundle\NewsBundle\Entity;use Doctrine\ORM\Mapping as ORM;use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareInterface;use Oro\Bundle\EntityBundle\EntityProperty\DatesAwareTrait;use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;use Oro\Bundle\OrganizationBundle\Entity\OrganizationAwareInterface;use Oro\Bundle\OrganizationBundle\Entity\Ownership\AuditableBusinessUnitAwareTrait;use Sinabs\Bundle\NewsBundle\Model\ExtendNews;/*** News** @ORM\Table(name="sinabs_news_news")* @ORM\Entity(repositoryClass="Sinabs\Bundle\NewsBundle\Entity\Repository\NewsRepository")*/class News extends ExtendNews implements OrganizationAwareInterface, DatesAwareInterface{use DatesAwareTrait;use AuditableBusinessUnitAwareTrait;/*** @var int** @ORM\Column(name="id", type="integer")* @ORM\Id* @ORM\GeneratedValue(strategy="AUTO")*/private $id;/*** @var string** @ORM\Column(name="title", type="string", length=255)*/private $title;/*** @var string** @ORM\Column(name="author", type="string", length=255)*/private $author;/*** @var string** @ORM\Column(name="content", type="text")*/private $content;/*** @var \DateTime** @ORM\Column(name="begin", type="datetime", nullable=true)*/private $begin;/*** @var \DateTime** @ORM\Column(name="end", type="datetime", nullable=true)*/private $end;/*** @var bool** @ORM\Column(name="visible", type="boolean")*/private $visible;/*** @var bool** @ORM\Column(name="home_page", type="boolean")*/private $homePage;/*** Get id** @return int*/public function getId(){return $this->id;}/*** Set title** @param string $title** @return News*/public function setTitle($title){$this->title = $title;return $this;}/*** Get title** @return string*/public function getTitle(){return $this->title;}/*** Set author** @param string $author** @return News*/public function setAuthor($author){$this->author = $author;return $this;}/*** Get author** @return string*/public function getAuthor(){return $this->author;}/*** Set content** @param string $content** @return News*/public function setContent($content){$this->content = $content;return $this;}/*** Get content** @return string*/public function getContent(){return $this->content;}/*** Set begin** @param \DateTime $begin** @return News*/public function setBegin($begin){$this->begin = $begin;return $this;}/*** Get begin** @return \DateTime*/public function getBegin(){return $this->begin;}/*** Set end** @param \DateTime $end** @return News*/public function setEnd($end){$this->end = $end;return $this;}/*** Get end** @return \DateTime*/public function getEnd(){return $this->end;}/*** Set visible** @param boolean $visible** @return News*/public function setVisible($visible){$this->visible = $visible;return $this;}/*** Get visible** @return bool*/public function getVisible(){return $this->visible;}/*** Set homePage** @param boolean $homePage** @return News*/public function setHomePage($homePage){$this->homePage = $homePage;return $this;}/*** Get homePage** @return bool*/public function getHomePage(){return $this->homePage;}}Installer
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687<?php/*** Created by PhpStorm.* User: adrien* Date: 06/08/18* Time: 15:04*/namespace Sinabs\Bundle\NewsBundle\Migrations\Schema;use Doctrine\DBAL\Schema\Schema;use Oro\Bundle\MigrationBundle\Migration\Installation;use Oro\Bundle\MigrationBundle\Migration\QueryBag;class SinabsNewsBundleInstaller implements Installation{const NEWS_TABLE_NAME = 'sinabs_news_news';/*** Gets a number of the last migration version implemented by this installation script** @return string*/public function getMigrationVersion(){return 'v1_0';}/*** Modifies the given schema to apply necessary changes of a database* The given query bag can be used to apply additional SQL queries before and after schema changes** @param Schema $schema* @param QueryBag $queries* @return void*/public function up(Schema $schema, QueryBag $queries){$this->createSinabsNewsTable($schema);$this->addSinabsNewsForeignKeys($schema);}public function createSinabsNewsTable(Schema $schema){$table = $schema->createTable(self::NEWS_TABLE_NAME);$table->addColumn('id', 'integer', ['autoincrement' => true]);$table->addColumn('business_unit_owner_id', 'integer', ['notnull' => false]);$table->addColumn('organization_id', 'integer', ['notnull' => false]);$table->addColumn('title', 'string', ['length' => 255]);$table->addColumn('author', 'string', ['length' => 255]);$table->addColumn('content', 'text');$table->addColumn('begin', 'datetime', ['notnull' => false]);$table->addColumn('end', 'datetime', ['notnull' => false]);$table->addColumn('visible', 'boolean');$table->addColumn('home_page', 'boolean');$table->addColumn('created_at', 'datetime', []);$table->addColumn('updated_at', 'datetime', []);$table->setPrimaryKey(['id']);$table->addIndex(['business_unit_owner_id'], 'IDX_1DD3995059294170', []);$table->addIndex(['organization_id'], 'IDX_1DD3995032C8A3DE', []);}public function addSinabsNewsForeignKeys(Schema $schema){$table = $schema->getTable(self::NEWS_TABLE_NAME);$table->addForeignKeyConstraint($schema->getTable('oro_business_unit'),['business_unit_owner_id'],['id'],['onDelete' => 'SET NULL', 'onUpdate' => null]);$table->addForeignKeyConstraint($schema->getTable('oro_organization'),['organization_id'],['id'],['onDelete' => 'SET NULL', 'onUpdate' => null]);}}Migrations
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647<?php/*** Created by PhpStorm.* User: adrien* Date: 06/08/18* Time: 15:56*/namespace Sinabs\Bundle\NewsBundle\Migrations\Schema\v1_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;use Sinabs\Bundle\NewsBundle\Migrations\Schema\SinabsNewsBundleInstaller;class SinabsNewsBundle 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->addImageRelation($schema,SinabsNewsBundleInstaller::NEWS_TABLE_NAME, // entity table, e.g. oro_user, orocrm_contact etc.'picture', // field name[], //additional options for relation7, // max allowed file size in megabytes, can be omitted, by default 1 Mb100, // thumbnail width in pixels, can be omitted, by default 32100 // thumbnail height in pixels, can be omitted, by default 32);}}Type
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960<?phpnamespace Sinabs\Bundle\NewsBundle\Form\Type;use Sinabs\Bundle\NewsBundle\Entity\News;use Symfony\Component\Form\AbstractType;use Symfony\Component\Form\FormBuilderInterface;use Symfony\Component\OptionsResolver\OptionsResolver;use Oro\Bundle\AttachmentBundle\Form\Type\ImageType;class NewsType extends AbstractType{const NAME = 'sinabs_news_type';/*** {@inheritdoc}*/public function buildForm(FormBuilderInterface $builder, array $options){$builder->add('title')->add('author')->add('content')->add('picture',ImageType::class,['required' => false,'label' => 'label'])->add('begin')->add('end')->add('visible')->add('homePage');}/*** {@inheritdoc}*/public function configureOptions(OptionsResolver $resolver){$resolver->setDefaults(array('data_class' => News::class));}/*** {@inheritdoc}*/public function getBlockPrefix(){return self::NAME;}public function getName(){return $this->getBlockPrefix();}}And View
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106{% extends 'OroUIBundle:actions:update.html.twig' %}{% form_theme form with 'OroFormBundle:Form:fields.html.twig' %}{% set name = 'N/A' %}{% if entity.title %}{% set name = is_granted('VIEW', entity, 'title')? entity.title|default('N/A'): 'view %fieldName% not granted'|trans({'%fieldName%': 'sinabs.news.title.label'|trans})%}{% endif %}{% oro_title_set({params : {"%news.title%": name }}) %}{% set formAction = form.vars.value.id ? path('sinabs_news_update', { 'id': form.vars.value.id }) : path('sinabs_news_create') %}{% block head_script %}{{ parent() }}{% block stylesheets %}{{ form_stylesheet(form) }}{% endblock %}{% endblock %}{% block navButtons %}{% if form.vars.value.id and is_granted('DELETE', form.vars.value) %}{{ UI.deleteButton({'dataUrl': path('sinabs_api_delete_news', {'id': form.vars.value.id}),'dataRedirect': path('sinabs_news_index'),'aCss': 'no-hash remove-button','dataId': form.vars.value.id,'id': 'btn-remove-news','entity_label': 'sinabs.news.entity_label'|trans,}) }}{{ UI.buttonSeparator() }}{% endif %}{{ UI.cancelButton(path('sinabs_news_index')) }}{% set html = UI.saveAndCloseButton({'route': 'sinabs_news_view','params': {'id': '$id'}}) %}{% if is_granted('sinabs_news_create') %}{% set html = html ~ UI.saveAndNewButton({'route': 'sinabs_news_create'}) %}{% endif %}{% if form.vars.value.id or is_granted('sinabs_news_update') %}{% set html = html ~ UI.saveAndStayButton({'route': 'sinabs_news_update','params': {'id': '$id'}}) %}{% endif %}{{ UI.dropdownSaveButton({'html': html}) }}{% endblock %}{% block pageHeader %}{% if form.vars.value.id %}{% set name = 'N/A' %}{% if form.vars.value.title %}{% set name = is_granted('VIEW', form.vars.value, 'title')? form.vars.value.title|default('N/A'): UI.renderDisabledLabel('view %fieldName% not granted'|trans({'%fieldName%': 'sinabs.news.title.label'|trans}))%}{% endif %}{% set breadcrumbs = {'entity': form.vars.value,'indexPath': path('sinabs_news_index'),'indexLabel': 'sinabs.news.entity_plural_label'|trans,'entityTitle': name}%}{{ parent() }}{% else %}{% set title = 'oro.ui.create_entity'|trans({'%entityName%': 'sinabs.news.entity_label'|trans}) %}{% include 'OroUIBundle::page_title_block.html.twig' with { title: title } %}{% endif %}{% endblock pageHeader %}{% block content_data %}{% set id = 'news-edit' %}{% set dataBlocks = [{'title': 'General'|trans,'class': 'active','subblocks': [{'title': 'Basic Information'|trans,'data': [form_row(form.title),form_row(form.author),form_row(form.content),form_row(form.picture),form_row(form.begin),form_row(form.end),form_row(form.visible),form_row(form.homePage)]}]}] %}{% set data = {'formErrors': form_errors(form)? form_errors(form) : null,'dataBlocks': dataBlocks,} %}<div class="responsive-form-inner">{{ parent() }}</div>{% endblock content_data %}
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.