/** * 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(); }
/** * 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); }
/** * @return AttributeGroup */ protected function getDefaultGroup() { return $this->attributeGroupRepo->findDefaultAttributeGroup(); }