public function newItem(Menu $menu, $i, Item $parentItem = null)
 {
     $item = new Item();
     $item->setMenu($menu);
     $item->setName('Item ' . $i);
     $item->setPosition($i);
     $item->setUri('http://alpixel.fr');
     if ($parentItem !== null) {
         $item->setParent($parentItem);
     }
     return $item;
 }
Esempio n. 2
0
 public function checkUri($object = null)
 {
     if ($object === null) {
         return;
     }
     $form = $this->getForm();
     $request = $this->getRequest();
     $uriType = $request->request->get('uri_type');
     if (!Item::uriTypeExists($uriType)) {
         $form->get('uri')->addError(new FormError('Le type d\'url est invalide !'));
         return;
     }
     if ($uriType === Item::URI_TYPE_ANCHOR) {
         return;
     }
     if ($uriType === Item::URI_TYPE_EXTERNAL) {
         $uri = $form->get('uri')->getData();
         if (preg_match('/^https?:\\/\\//', $uri) === 0) {
             $form->get('uri')->addError(new FormError('Votre lien doit débuter par "http://" ou "https://"'));
         }
     }
 }