public function updatePost(FormInterface $form) { $post = $form->getObject(); $this->assertGranted('blog.post.update', $post); $this->bind($post, $form); $this->objectManager->persist($post); $this->getEventManager()->trigger('update', $this, ['post' => $post]); }
/** * Callback for file count validation. * * @internal * This function gets the value passed in as variable, * but we do not need it. * @return bool */ public function fileCountValidationCallback() { if ($this->form && ($object = $this->form->getObject())) { if ($this->getMaxFileCount() - 1 < count($object)) { return false; } } return true; }
public function editPageRepository(FormInterface $form) { $page = $form->getObject(); if (!$form->isValid()) { throw new RuntimeException(print_r($form->getMessages(), true)); } $data = $form->getData(FormInterface::VALUES_AS_ARRAY); $formClone = clone $form; $formClone->bind($page); $formClone->setData($data); $formClone->isValid(); $this->assertGranted('page.update', $page); $this->getObjectManager()->persist($page); return $page; }
/** * @param FormInterface $form * @return void * @throws RuntimeException */ public function updateParameter(FormInterface $form) { $object = $form->getObject(); $this->assertGranted('navigation.manage', $object); if (!$form->isValid()) { throw new RuntimeException(print_r($form->getMessages())); } $this->objectManager->persist($object); $this->getEventManager()->trigger('parameter.update', $this); }
/** * {@inheritDoc} */ public function openTag(FormInterface $form = null) { if ($form) { $class = $form->getAttribute('class'); if (strpos($class, $this->defaultClass) === false) { $class = trim("{$class} {$this->defaultClass}"); } if ($object = $form->getObject()) { $className = str_replace(array_keys($this->classNameReplacements), array_values($this->classNameReplacements), get_class($object)); } else { $className = get_class($form); } $parts = explode('\\', $className); foreach ($parts as $part) { $classes[] = strtolower($part); if (count($classes) > 1) { $class .= ' ' . implode('-', $classes); } } $form->setAttribute('class', $class); $formAttributes = $form->getAttributes(); if (!array_key_exists('id', $formAttributes) && $classes) { $form->setAttribute('id', implode('-', $classes)); } } return parent::openTag($form); }