Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,84 @@ overridden as with any other bundle, by creating translation files in the
To get started, check the bundle's main language file in:
[Resources/translations/messages.en.yml](Resources/translations/messages.en.yml)

## Extends our entities

To add fields to an entity, you must create your own entity that extends ours.
Here is an example to add «closing days» to translated values of a location :
```
<?php
// src/AppBundle/Entity/MyLocationTranslation.php

namespace AppBundle\Entity;

use Webburza\Sylius\LocationBundle\Model\LocationTranslation as BaseLocationTranslation;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="app_location")
*/
class MyLocationTranslation extends BaseLocationTranslation
{
/** @ORM\Column(type="string", length=2048) */
private $closingDays;

public function setClosingDays($closingDays)
{
$this->closingDays = $closingDays;

return $this;
}

public function getClosingDays()
{
return $this->closingDays;
}
}

```

Then add your own fields to edit form, extending our form type :
```
<?php
// src/AppBundle/Type/MyLocationTranslationType.php

namespace AppBundle\Type;

use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Webburza\Sylius\LocationBundle\Form\Type\LocationTranslationType as BaseLocationTranslationType;
use Symfony\Component\Form\FormBuilderInterface;

class MyLocationTranslationType extends BaseLocationTranslationType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);

$builder->add('closingDays', TextareaType::class, [
'label' => 'webburza_location.form.location.closingDays'
]);
}
}
```
By the way, you can change also widget here, instead of «TextareaType». You can use CkeditorType for example.

Finaly, you must configure symfony to use this. Add this to ``app/config/config.yml`` (or another config file) :
```
parameters:
webburza_location.model.location_translation.class: AppBundle\Entity\MyLocationTranslation
webburza_location.form.type.location_translation.class: AppBundle\Type\MyLocationTranslationType

```

And do not forget to add translation string for ```webburza_location.form.location.closingDays```

You’re done !


## License

This bundle is available under the [MIT license](LICENSE).
Expand Down