/** * @param FormEvent $event */ public function preSetData(FormEvent $event) { $data = $event->getData(); if (null === $data || null !== $data->getId()) { return; } $data->setSortOrder($this->repository->getMaxSortOrder() + 1); }
/** * Remove an attribute from a group and link it to the default group * * @param AttributeGroupInterface $group * @param AttributeInterface $attribute * * @throws \LogicException */ public function removeAttribute(AttributeGroupInterface $group, AttributeInterface $attribute) { if (null === ($default = $this->repository->findDefaultAttributeGroup())) { throw new \LogicException('The default attribute group should exist.'); } $group->removeAttribute($attribute); $attribute->setGroup($default); $this->attributeSaver->saveAll([$attribute]); $this->groupSaver->save($group); }
/** * Remove an attribute from a group and link it to the default group * * @param AttributeGroupInterface $group * @param AttributeInterface $attribute * * @throws \LogicException */ public function removeAttribute(AttributeGroupInterface $group, AttributeInterface $attribute) { if (null === ($default = $this->repository->findDefaultAttributeGroup())) { throw new \LogicException('The default attribute group should exist.'); } $group->removeAttribute($attribute); $attribute->setGroup($default); $this->objectManager->persist($group); $this->objectManager->persist($attribute); $this->objectManager->flush(); }
/** * @param int $id * * @return AttributeGroupInterface */ protected function findAttributeGroupOr404($id) { $result = $this->attributeGroupRepo->find($id); if (!$result) { throw $this->createNotFoundException(sprintf('Attribute group not found')); } return $result; }
/** * @param int $id * * @return AttributeGroupInterface */ protected function findAttributeGroupOr404($id) { $result = $this->attributeGroupRepo->find($id); if (null === $result) { throw new NotFoundHttpException('Attribute group not found'); } return $result; }
/** * Hide the group field with a default value = "Other" * * @param FormInterface $form Form * @param AttributeInterface $data */ protected function hideGroupElement(FormInterface $form, AttributeInterface $data) { if (null !== $data->getId()) { $group = $data->getGroup(); } else { $group = $this->groupRepository->findDefaultAttributeGroup(); } $formField = $form->get('group'); $options = $formField->getConfig()->getOptions(); $newOptions = ['data' => $group, 'class' => $options['class'], 'choices' => [$group], 'required' => true, 'multiple' => false, 'read_only' => true, 'attr' => ['class' => 'hide']]; $form->add('group', 'entity', $newOptions); }
/** * @param string $code * * @return AttributeGroupInterface|null */ protected function findAttributeGroup($code) { $attributeGroup = $this->attrGroupRepo->findOneByIdentifier($code); return $attributeGroup; }