/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['object'] = $form->getParent()->getData(); if ($options['download_link'] && $view->vars['object']) { $view->vars['download_uri'] = $this->storage->resolveUri($form->getParent()->getData(), $form->getName()); } }
/** * Returns first label for field with error * * @param FormInterface $form * @return array */ protected function getErrorFormLabel(FormInterface $form) { $vars = $form->createView()->vars; $label = $vars['label']; $translationDomain = $vars['translation_domain']; $result = array('label' => $label, 'domain' => $translationDomain); if (empty($label)) { if ($form->getParent() !== null) { $result = $this->getErrorFormLabel($form->getParent()); } } return $result; }
/** * {@inheritdoc} */ public function chooseGroups(FormInterface $form) { $dayPhoneData = $form->get('dayPhone')->getData(); $eveningPhoneData = $form->get('eveningPhone')->getData(); $emailData = $form->get('email')->getData(); // All other fields are validated through the Default validation group $validation_groups = array('Default'); // todo: is there an apprpoach that does not require the sdk models? /** @var ReferencingApplication $application */ $application = $form->getParent()->getData(); if ($application instanceof ReferencingApplication) { // If Optimum product, require at least one contact detail must be given if (19 == $application->getProductId()) { if (empty($dayPhoneData) && empty($eveningPhoneData) && empty($emailData)) { $validation_groups[] = 'dayphone'; $validation_groups[] = 'eveningphone'; $validation_groups[] = 'email'; } } // If no day phone, enforce evening if (empty($dayPhoneData)) { $validation_groups[] = 'eveningphone'; } // If no evening phone, enforce day if (empty($eveningPhoneData)) { if ($k = array_search('eveningphone', $validation_groups)) { unset($validation_groups[$k]); } $validation_groups[] = 'dayphone'; } return $validation_groups; } return array('Default'); }
/** * {@inheritdoc} */ public function finishView(FormView $view, FormInterface $form, array $options) { $permissionForm = $form->getParent(); if (!$permissionForm) { return; } $permissionsForm = $permissionForm->getParent(); if (!$permissionsForm) { return; } $privilegeForm = $permissionsForm->getParent(); if (!$privilegeForm) { return; } $privilegesForm = $privilegeForm->getParent(); if (!$privilegesForm) { return; } $roleForm = $privilegesForm->getParent(); if (!$roleForm) { return; } if (in_array($roleForm->getConfig()->getType()->getName(), [AccountUserRoleType::NAME, FrontendAccountUserRoleType::NAME])) { //uses on edit page for rendering preloaded string (role permission name) $view->vars['translation_prefix'] = $this->roleTranslationPrefixResolver->getPrefix(); } }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $vars = ['configs' => $options['configs']]; if ($form->getData()) { $data = $form->getParent()->getData(); $fieldConfig = $this->cm->getProvider('extend')->getConfig($data, $form->getName()); if ($form->getData()) { /** @var ConverterInterface|EntitySelectHandler $converter */ $converter = $options['converter']; $result = []; if ($converter instanceof EntitySelectHandler) { $converter->initForEntity($fieldConfig->getId()->getClassName(), $fieldConfig->get('target_field')); } if (isset($options['configs']['multiple']) && $options['configs']['multiple']) { foreach ($form->getData() as $item) { $result[] = $converter->convertItem($item); } } else { $result[] = $converter->convertItem($form->getData()); } $vars['attr'] = ['data-selected-data' => json_encode($result)]; } } $view->vars = array_replace_recursive($view->vars, $vars); }
/** * {@inheritDoc} */ public function finishView(FormView $view, FormInterface $form, array $options) { $formParent = $form->getParent(); if (!$formParent) { return; } /* @var $productUnitHolder ProductUnitHolderInterface */ $productUnitHolder = $formParent->getData(); if (!$productUnitHolder) { return; } $product = $productUnitHolder->getProductHolder()->getProduct(); $choices = $this->getProductUnits($product); $productUnit = $productUnitHolder->getProductUnit(); if (!$productUnit || $product && !in_array($productUnit, $choices, true)) { $emptyValueTitle = $this->translator->trans($this->options['empty_label'], ['{title}' => $productUnitHolder->getProductUnitCode()]); $view->vars['empty_value'] = $emptyValueTitle; } $choices = $this->productUnitFormatter->formatChoices($choices, $options['compact']); $choicesViews = []; foreach ($choices as $key => $value) { $choicesViews[] = new ChoiceView($value, $key, $value); } $view->vars['choices'] = $choicesViews; }
/** * Navigates to the Root form to define if cascading should be done. * * @param FormInterface $form * @return boolean */ public function getRootFormCascadeOption(FormInterface $form) { if (!$form->isRoot()) { return $this->getRootFormCascadeOption($form->getParent()); } return $form->getConfig()->getOption('cascade_filter', false); }
/** * Pass the image URL to the view. * * @param FormView $view * @param FormInterface $form * @param array $options */ public function buildView(FormView $view, FormInterface $form, array $options) { $data = $form->getParent()->getData(); if ($data instanceof ContentSpec) { $tmpName = explode('_', $form->getName()); if (count($tmpName) === 3) { $currentFile = null; foreach ($data->getTranslations() as $tr) { if ($tr->getLocale() == $tmpName[1] && ($tr->getField() == 'content' || $tr->getField() == 'data')) { $contents = json_decode($tr->getContent(), true); if (isset($contents[$tmpName[2]])) { $currentFile = $contents[$tmpName[2]]; } } } } else { $currentFile = $data->getInContent($form->getName()); if (!$currentFile) { $currentFile = $data->getInData($form->getName()); } } if ($currentFile) { $currentFileWeb = $this->nyrocms->getHandler($data->getContentHandler())->getUploadDir() . '/' . $currentFile; $view->vars['currentFile'] = $currentFileWeb; $view->vars['showDelete'] = $options['showDelete'] && is_string($options['showDelete']) ? $options['showDelete'] : false; } } }
/** * Disable a field after the form has been created * * @param FormInterface $field */ protected function disableField(FormInterface $field) { $config = $field->getConfig(); $options = $config->getOptions(); $options['disabled'] = true; $field->getParent()->add($field->getName(), $config->getType()->getInnerType(), $options); }
public function buildView(FormView $view, FormInterface $form, array $options) { //parent::buildView($view, $form, $options); $entity = $form->getParent()->getData(); $property_name = $view->vars['name']; $this->defaults = array_merge($this->defaults, $options); // entity info $entity_info = $this->container->get('itf.admin_helper')->getEntityInfo(get_class($entity)); $fk_entity_info = $this->container->get('itf.admin_helper')->getEntityInfo($this->defaults['data_class']); $this->defaults['fn_entity'] = $entity_info['entity_short']; $this->defaults['fn_bundle'] = $entity_info['bundle_short']; $this->defaults['fn_property'] = $property_name; $this->defaults['fn_fk_entity'] = $fk_entity_info['entity_short']; $this->defaults['fn_fk_bundle'] = $fk_entity_info['bundle_short']; // extract constraints $validator = $this->container->get('validator'); $metadata = $validator->getMetadataFor($fk_entity_info['entity_fq']); if (isset($metadata->properties[$this->defaults['fn_entity_property']])) { $this->extractConstraints($metadata->properties[$this->defaults['fn_entity_property']]); } // set id if (method_exists($entity, 'getId')) { $this->defaults['fn_entity_id'] = (int) $entity->getId(); } $view->vars = array_merge($view->vars, $this->defaults); }
/** * {@inheritdoc} */ public function finishView(FormView $view, FormInterface $form, array $options) { $permissionForm = $form->getParent(); if (!$permissionForm) { return; } $permissionsForm = $permissionForm->getParent(); if (!$permissionsForm) { return; } $privilegeForm = $permissionsForm->getParent(); if (!$privilegeForm) { return; } $privilegesForm = $privilegeForm->getParent(); if (!$privilegesForm) { return; } $roleForm = $privilegesForm->getParent(); if (!$roleForm) { return; } if ($roleForm->getConfig()->getType()->getName() === AccountUserRoleType::NAME) { $view->vars['translation_prefix'] = 'orob2b.customer.security.access-level.'; } }
public function buildView(FormView $view, FormInterface $form, array $options) { $options['expanded'] = false; // only select can be dynamic if ($options['source_field']) { $value = $form->getParent()[$options['source_field']]->getData(); if (is_object($value)) { $value = $value->getId(); } $view->vars['source_field'] = $options['source_field']; $completeChoices = array(); foreach ($options['choices'] as $key => $val) { $completeChoices[$key] = array(); foreach ($val as $k => $v) { $completeChoices[$key][] = array('id' => $k, 'text' => $v); } } $view->vars['complete_choices'] = $completeChoices; $choices = array(); if (isset($options['choices'][$value])) { $choices = $options['choices'][$value]; } $options['choice_list'] = new SimpleChoiceList($choices); } parent::buildView($view, $form, $options); }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $parentData = $form->getParent()->getData(); $accountId = null; if ($parentData instanceof Account) { $accountId = $parentData->getId(); } $view->vars['configs']['accountId'] = $accountId; }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $parentData = $form->getParent()->getData(); $parentId = null; if ($parentData instanceof Customer) { $parentId = $parentData->getId(); } $view->vars['parent_id'] = $parentId; }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $parent = $form->getParent()->getParent()->getParent(); $parentData = $parent->getData(); if ($parentData instanceof AclPrivilege) { $view->vars['identity'] = $parentData->getIdentity()->getId(); $view->vars['level_label'] = AccessLevel::getAccessLevelName($form->getData()); } }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { if ($options['controller_body']) { $view->vars['controller_body'] = $this->templating->render($options['controller_body'], ['form' => $form->getParent()]); } $view->vars['angular_modules'] = json_encode($options['angular_modules']); $view->vars['angular_services'] = json_encode($options['angular_services']); $view->vars['angular_services_array'] = $options['angular_services']; }
/** * Gets constraints for form view based on metadata * * @param FormInterface $form * @return array */ protected function getMetadataConstraints(FormInterface $form) { $isMapped = $form->getConfig()->getOption('mapped', true); if (!$form->getParent() || !$isMapped) { return []; } $name = $form->getName(); $parent = $form->getParent(); $parentKey = spl_object_hash($parent); if (!isset($this->metadataConstraintsCache[$parentKey])) { $this->metadataConstraintsCache[$parentKey] = $this->extractMetadataPropertiesConstraints($parent); } $result = []; if (isset($this->metadataConstraintsCache[$parentKey][$name])) { $result = $this->metadataConstraintsCache[$parentKey][$name]->constraints; } return $result; }
public function buildView(FormView $view, FormInterface $form, array $options) { $hasId = $form->getParent()->getData()->getId(); if ($hasId) { return; } // This is a new connection, so make the 'type' field available for setting. $view->vars['disabled'] = false; }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { if (isset($options['admin_code'])) { $code = $options['admin_code']; } elseif (isset($options['class'])) { $class = $options['class']; } elseif (($data = $form->getData()) instanceof PersistentCollection) { $class = $data->getTypeClass()->getName(); } if (isset($code)) { $childAdmin = $this->adminPool->getAdminByAdminCode($code); } elseif (isset($class)) { $childAdmin = $this->adminPool->getAdminByClass($class); } else { throw new \InvalidArgumentException('Configure "class" or "admin_code" options for obtains the admin instance.'); } if (!$childAdmin) { $message = isset($class) ? sprintf('Create a Admin class for "%s"', $class) : sprintf('Admin code "%s" not found.', $options['admin_code']); throw new \LogicException($message); } $parentClass = $form->getParent()->getConfig()->getOption('data_class'); if (isset($options['parent_admin_code'])) { $parentAdmin = $this->adminPool->getAdminByAdminCode($options['parent_admin_code']); } else { $parentAdmin = $this->adminPool->getAdminByClass($parentClass); } if (!$parentAdmin->hasChild($childAdmin->getCode())) { throw new \LogicException(sprintf('Add the admin "%s" as child of "%s"', get_class($childAdmin), get_class($parentAdmin))); } $parentAdmin->setSubject($form->getParent()->getData()); $childAdmin = $parentAdmin->getChild($childAdmin->getCode()); /** @var AbstractAdmin $childAdmin */ if (!$childAdmin->isEmbedded()) { throw new \LogicException('The child Admin should be marked as embedded to embed into a parent.'); } $id = $parentAdmin->getUrlsafeIdentifier($parentAdmin->getSubject()); if (null === $id) { throw new \LogicException(sprintf('You cannot create embedded admin from new parent instances. Check the form configuration for "%s" admin class.', get_class($parentAdmin))); } $view->vars['parentId'] = $id; $view->vars['admin'] = $childAdmin; $view->vars['label'] = $options['title']; }
function it_does_nothing_if_form_has_no_translatable_parent(FormView $view, FormInterface $form, FormConfigInterface $formConfig, FormInterface $parentForm, FormConfigInterface $parentFormConfig) { $form->getPropertyPath()->willReturn('translatable_property'); $form->getConfig()->willReturn($formConfig); $form->getParent()->willReturn($parentForm); $parentForm->getConfig()->willReturn($parentFormConfig); $parentFormConfig->getInheritData()->willReturn(true); $parentForm->getParent()->willReturn(null); $this->finishView($view, $form, array()); }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $vars = array('configs' => $options['configs']); if ($form->getData()) { $fieldConfig = $this->entityManager->getExtendManager()->getConfigProvider()->getConfig($form->getParent()->getData(), $form->getName()); $fieldName = $fieldConfig->get('target_field'); $vars['attr'] = array('data-entities' => json_encode(array(array($fieldName => $form->getData()->{'get' . ucfirst($fieldName)}())))); } $view->vars = array_replace_recursive($view->vars, $vars); }
/** * @param FormView $view * @param FormInterface $form * @param array $options */ public function buildView(FormView $view, FormInterface $form, array $options) { $entity = $form->getParent()->getData(); if (is_callable($options['image_url_callback'])) { $options['image_url'] = call_user_func($options['image_url_callback'], $entity); } elseif ($entity instanceof ImageInterface) { $options['image_url'] = $entity->getImageWebPath(); } $view->vars['image_url'] = $options['image_url']; $view->vars['attr']['class'] .= ($view->vars['attr']['class'] ? ' ' : '') . 'form-image-upload-__input'; }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { $parent = $form->getParent()->getParent()->getParent(); $parentData = $parent->getData(); if ($parentData instanceof AclPrivilege) { $view->vars['identity'] = $parentData->getIdentity()->getId(); $view->vars['level_label'] = AccessLevel::getAccessLevelName($form->getData()); } //uses on view page for rendering preloaded string (role permission name) $view->vars['translation_prefix'] = $this->roleTranslationPrefixResolver->getPrefix(); }
/** * @param FormInterface $field * @param FormView $view */ protected function updateTooltip(FormInterface $field, FormView $view) { $parentOptions = $field->getParent()->getConfig()->getOptions(); $parentClassName = isset($parentOptions['data_class']) ? $parentOptions['data_class'] : null; if (!isset($view->vars['tooltip']) && $parentClassName && $this->entityConfigProvider->hasConfig($parentClassName, $field->getName())) { $tooltip = $this->entityConfigProvider->getConfig($parentClassName, $field->getName())->get('description'); //@deprecated 1.9.0:1.11.0 tooltips.*.yml will be removed. Use Resources/translations/messages.*.yml instead if ($this->translator->hasTrans($tooltip, self::DEFAULT_TRANSLATE_DOMAIN) || $this->translator->hasTrans($tooltip, self::TOOLTIPS_TRANSLATE_DOMAIN)) { $view->vars['tooltip'] = $tooltip; } } }
/** * @param FormView $view * @param FormInterface $form * @param array $options */ public function buildView(FormView $view, FormInterface $form, array $options) { $imageUrl = null; if (array_key_exists('image_path', $options)) { $parentData = $form->getParent()->getData(); if (null !== $parentData) { $accessor = PropertyAccess::createPropertyAccessor(); $imageUrl = $accessor->getValue($parentData, $options['image_path']); } } $view->vars['image_url'] = $imageUrl; }
/** * Pass the image URL to the view * * @param FormView $view * @param FormInterface $form * @param array $options */ public function buildView(FormView $view, FormInterface $form, array $options) { $parentData = $form->getParent()->getData(); if (null !== $parentData) { $accessor = PropertyAccess::createPropertyAccessor(); $imageUrl = $accessor->getValue($parentData, 'avatar.webPath'); } else { $imageUrl = null; } // set an "image_url" variable that will be available when rendering this field $view->vars['avatar'] = $imageUrl; }
public function finishView(FormView $view, FormInterface $form, array $options) { $isForm = false; if (!$view->parent && $options['compound'] && $view->vars['horizontal']) { $class = isset($view->vars['attr']['class']) ? $view->vars['attr']['class'] . ' ' : ''; $view->vars['attr']['class'] = $class . 'form-horizontal'; $isForm = true; } if ($isForm || $form->getParent() === null && $options['compound']) { $this->setChildrenHorizontal($view); } }
/** * Validate attachment field * * @param FormInterface $form * @param File|Attachment $entity */ protected function validate(FormInterface $form, $entity) { $fieldName = $form->getName(); if ($form->getParent()->getConfig()->getOption('parentEntityClass', null)) { $dataClass = $form->getParent()->getConfig()->getOption('parentEntityClass', null); $fieldName = ''; } else { $dataClass = $form->getParent() ? $form->getParent()->getConfig()->getDataClass() : $form->getConfig()->getDataClass(); if (!$dataClass) { $dataClass = $form->getParent()->getParent()->getConfig()->getDataClass(); } } $violations = $this->validator->validate($dataClass, $entity, $fieldName); if (!empty($violations)) { $fileField = $form->get('file'); /** @var $violation ConstraintViolation */ foreach ($violations as $violation) { $error = new FormError($violation->getMessage(), $violation->getMessageTemplate(), $violation->getMessageParameters()); $fileField->addError($error); } } }
/** * {@inheritdoc} */ public function buildView(FormView $view, FormInterface $form, array $options) { // Test to see if the address history constraint has been violated to let the view know $addressHistoryConstraintViolation = false; // Look through form errors for violation $formErrors = $form->getParent()->getErrors(); foreach ($formErrors as $key => $formError) { if (method_exists($formError->getCause(), 'getCode') && 'ADDRESSHISTORYVIOLATION' == $formError->getCause()->getCode()) { $addressHistoryConstraintViolation = true; } } $view->vars['addressHistoryConstraintViolation'] = $addressHistoryConstraintViolation; }
/** * Passe l'url de l'image � la vue * * @param \Symfony\Component\Form\FormView $view * @param \Symfony\Component\Form\FormInterface $form * @param array $options */ public function buildView(FormView $view, FormInterface $form, array $options) { $publish = null; if (array_key_exists('isPublishOption', $options)) { $parentData = $form->getParent()->getData(); if (null !== $parentData) { $accessor = PropertyAccess::createPropertyAccessor(); $publish = $accessor->getValue($parentData, $options['isPublishOption']); } } // d�finit une variable "isPublishOption" qui sera disponible � l'affichage du champ $view->vars['isPublishOption'] = $publish; }