dev-master
9999999-dev...
The Requires
- php ^5.3.3 || ^7.0
- doctrine/doctrine-fixtures-bundle ^2.3
- stof/doctrine-extensions-bundle ^1.2
- doctrine/doctrine-cache-bundle ^1.3
Wallogit.com
2017 © Pedro PelĂĄez
...
``` json //composer.json du nouveau Projet "require": { "...," "tgc/edit-content": "dev-master", "..." },, (*1)
"repositories": [ "...", { "type": "vcs", "url": "git@os1119.octey.me:Alexis/EditBundle.git" }, "..." ],, (*2)
"config": { "...", "secure-http": false, "..." },, (*3)
composer update, (*4)
## Add route of the bundle ``` yml //app/config/routing.yml edit-content: resource: '@TgcEditContentBundle/Controller' type: annotation
``` yml //app/config/services.yml services: Tgc\EditContentBundle\EventSubscriber\LocaleSubscriber: arguments: ['%kernel.default_locale%'], (*5)
## Activate the bundle: ``` php <?php // app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Tgc\EditContentBundle\TgcEditContentBundle(), new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), new Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(), ); if (//...) { //.... if (//...) { //... $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(); } } } }
``` yml // app/config/config.yml doctrine: orm: mappings: translatable: type: annotation is_bundle: false prefix: Gedmo\Translatable\Entity dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity" alias: GedmoTranslatable, (*6)
## Enable translatable extension ``` yml // app/config/config.yml stof_doctrine_extensions: default_locale: fr persist_default_translation: true orm: default: translatable: true
``` php <?php //src/AppBundle/DataFixtures/ORM/, (*7)
namespace AppBundle\DataFixtures\ORM;, (*8)
use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\Persistence\ObjectManager; use Tgc\EditContentBundle\Entity\TextEditable;, (*9)
class TextData implements FixtureInterface {, (*10)
public function load(ObjectManager $manager) {
$contents = [
[
'slug' => 'presentationTitre',
'text-fr' => 'Présentation fr',
'text-en' => 'Presentation en'
]
];
foreach ($contents as $content) {
$repo = $manager->getRepository('Gedmo\\Translatable\\Entity\\Translation');
$textEditable = new TextEditable();
$textEditable->setSlug($content['slug']);
$repo
->translate($textEditable,'text', 'en', $content['text-en'])
->translate($textEditable, 'text', 'fr', $content['text-fr'])
;
$manager->persist($textEditable);
}
$manager->flush();
}
}, (*11)
## Update database
php bin/console doctrine:schema:update, (*12)
## Add data in fixtures in $contents ``` php <?php class TextData implements FixtureInterface { public function load(ObjectManager $manager) { $contents = [ [ 'slug' => 'presentationChambres', 'text-fr' => 'chambres fr', 'text-en' => 'rooms en' ] ]; ``` ## Load fixtures ``` php bin/console doctrine:fixtures:load ``` ## Add code in your method Controller ``` php <?php //src/AppBundle/Controller/DefaultController /** * @Route("/{edit}", name="homepage", requirements={"edit": "|edit|preview"}) */ public function indexAction($edit = "", Request $request) { $editContentService = $this->get('edit_content'); $result = $editContentService->getEditContent(['presentationTitre'], 'homepage', $edit, $request->getLocale()); return $this->render('default/index.html.twig', $result); }
``` php <?php $editContentService->getEditContent(['presentationTitre','SlugToInsert'], 'homepage', '', $request->getLocale()); }, (*13)
## in your view add :
``` twig
{{ include('TgcEditContentBundle:Default:validateTextEdit.html.twig') }}
{{ include('TgcEditContentBundle:Default:textEditable.html.twig', { 'content': presentationTitre }) }}
yml
// app/config/config.yml
doctrine_cache:
aliases:
tgc_cache: tgc_cache
providers:
tgc_cache:
## See http://symfony.com/doc/master/bundles/DoctrineCacheBundle/reference.html
## For more configuration options
type: file_system
file_system:
umask: 0113
extension: 'cache', (*14)
...