Open alexander-schranz opened 3 years ago
A little bit offtopic. @alexander-schranz , what do you think about an example for Extending Entities with the MediaBundle. (SuluMedia Attribute). And a Example for view Images in a ListView. Is the SuluMedia Bundle the right place ? Im interested in do that
We dont have a lot of documentation about custom entities at the moment, so not sure what would be the best place for this. Would be okay for me to add a Use media in custom entity
section - i think its better than having no documentation at all 🙂
We had something similar one a project documentation there was a section Override Entities
and then for every entity was a new sub section e.g.: Override Media Entity
.
Docs did there look like this:
## Override Entities
### Override Media Entity
Create your new product entity class:
```php
<?php
// src/Entity/Product.php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use .......\Media as SuluMedia;
/**
* @ORM\Table(name="me_media")
* @ORM\Entity
*/
class Media extends SuluMedia
{
}
```
Configure your new model class:
```yaml
# config/packages/sulu_product.yaml
sulu_media:
objects:
media:
model: 'App\Entity\Media'
```
To add new fields to your entity have a look at the [Doctrine Mapping Documentation](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/basic-mapping.html);
@alexander-schranz I meant more the direction of bring the Media Bundle into your own Entity. As an example "event" has a property "image" which has a doctrine relationship to "media".
And the doc should contain how about doctrine config (yml or xml) establishes this relationship. Like here in Contact. https://github.com/sulu/sulu/blob/2.x/src/Sulu/Bundle/ContactBundle/Resources/config/doctrine/Contact.orm.xml#L44
Another part should be how you can show the media in your ListView. Like here: https://github.com/sulu/sulu/blob/2.x/src/Sulu/Bundle/ContactBundle/Resources/config/lists/contacts.xml#L45
Oh yeah then Usage media with custom entity
or something similar would make sense.
In https://github.com/sulu/sulu-docs/pull/623 we added some configuration to the doc. We should also add the other available options to the configuration docs.