Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @ORMEntity(repositoryClass="AppRepositoryMenuRepository")
- */
- class Menu
- {
- /**
- * @Groups({"menu"})
- * @ORMId
- * @ORMColumn(type="integer")
- * @ORMGeneratedValue(strategy="AUTO")
- */
- private $id;
- // ...
- /**
- * References translated menus.
- * @Groups({"localized_menus"})
- *
- * @ORMOneToMany(
- * targetEntity="LocalizedMenu"
- * ,mappedBy="parentMenu"
- * ,indexBy="locale"
- * ,cascade={"persist", "remove"}
- * )
- * @ORMOrderBy({"locale" = "ASC"})
- */
- private $localizedMenus;
- // ...
- public function getLocalizedMenu($locale) {
- if (!isset($this->localizedMenus[$locale])) {
- return new LocalizedMenu($locale, $this);
- }
- return $this->localizedMenus[$locale];
- }
- public function addLocalizedMenu($localizedMenu): self
- {
- $this->localizedMenus[$localizedMenu->getLocale()] = $localizedMenu;
- return $this;
- }
- }
- /**
- * @ORMEntity(repositoryClass="AppRepositoryLocalizedMenuRepository")
- */
- class LocalizedMenu
- {
- public function __construct($locale, $menu) {
- $this->locale = $locale;
- $this->parentMenu = $menu;
- $this->parentMenu->addLocalizedMenu($this);
- }
- // region FIELDS
- /**
- * @Groups({"localized_menu", "localized_menus"})
- * @ORMId
- * @ORMColumn(type="integer")
- * @ORMGeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @Groups({"localized_menu", "localized_menus"})
- * @var $locale string
- * @ORMColumn(
- * type = "string"
- * ,unique = true
- * )
- */
- private $locale = "";
- /**
- * @Groups({"localized_menu", "localized_menus"})
- * @ORMColumn(
- * type = "string",
- * length = 75
- * )
- */
- private $title = "";
- /**
- * @Groups({"localized_menu", "localized_menus"})
- * @var $description string Extra description for this menu item
- * @ORMColumn(
- * type = "text",
- * name = "description"
- * )
- */
- private $description = "";
- /**
- * @Groups({"localized_menu", "localized_menus"})
- * @ORMColumn(
- * type = "datetime",
- * name = "creation_date"
- * )
- * @AssertDateTime()
- */
- private $creationDate;
- /**
- * @Groups({"localized_menu", "localized_menus"})
- * @ORMColumn(
- * type = "datetime",
- * name = "edit_date"
- * )
- * @AssertDateTime()
- */
- private $editDate;
- /**
- * @Groups({"localized_menu", "localized_menus"})
- * @ORMColumn(type="text")
- * @AssertNotBlank(
- * message = "Een menu item is een pagina die inhoud nodig heeft, vergeet dit niet"
- * )
- */
- private $content = "";
- /**
- * @var $parentMenu Menu Parent menu for this localized menu
- *
- * @Groups({"localized_menu", "localized_parent_menu"})
- * @ORMManyToOne(
- * targetEntity="Menu",
- * inversedBy="localizedMenus"
- * )
- */
- private $parentMenu;
- }
- $builder
- ->add('localizedMenus', CollectionType::class, array(
- 'entry_type' => LocalizedMenuType::class,
- "entry_options" => [
- "choice_locale" => $options["choice_locale"]
- ],
- 'allow_add' => true,
- 'allow_delete' => true,
- 'required' => false
- ))
- $builder
- ->add('title', TextType::class, array(
- 'label' => 'Titel',
- 'trim' => true
- ))
- ->add('description', TextareaType::class, array(
- 'label' => 'Omschrijving',
- 'trim' => true
- ))
- ->add('content', TextareaType::class, array(
- 'label' => 'Inhoud',
- 'trim' => true,
- 'attr' => array('class' => 'tinymce'),
- 'data' => " "
- ))
- ->add('locale', LocaleType::class, array(
- "choice_translation_locale" => $options["choice_locale"]
- ))
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement