public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data)
 {
     $fieldDefinition = $data->fieldDefinition;
     $formConfig = $fieldForm->getConfig();
     $names = $fieldDefinition->getNames();
     $label = $fieldDefinition->getName($formConfig->getOption('languageCode')) ?: reset($names);
     $fieldForm->add($formConfig->getFormFactory()->createBuilder()->create('value', CheckboxType::class, ['required' => $fieldDefinition->isRequired, 'label' => $label])->addModelTransformer(new FieldValueTransformer($this->fieldTypeService->getFieldType($fieldDefinition->fieldTypeIdentifier)))->setAutoInitialize(false)->getForm());
 }
 /**
  * Maps Repository Field to the Site Field.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Field $field
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
  *
  * @return mixed|\Netgen\EzPlatformSiteApi\API\Values\Field
  */
 private function mapFieldData(APIField $field, ContentType $contentType)
 {
     $fieldDefinition = $contentType->getFieldDefinition($field->fieldDefIdentifier);
     $fieldTypeIdentifier = $fieldDefinition->fieldTypeIdentifier;
     $isEmpty = $this->fieldTypeService->getFieldType($fieldTypeIdentifier)->isEmptyValue($field->value);
     return ['isEmpty' => $isEmpty, 'innerField' => $field];
 }
 /**
  * Parses the given $configurationHash using the FieldType identified by
  * $fieldTypeIdentifier.
  *
  * @param string $fieldTypeIdentifier
  * @param mixed $configurationHash
  *
  * @return mixed
  */
 public function parseValidatorConfiguration($fieldTypeIdentifier, $configurationHash)
 {
     if ($this->fieldTypeProcessorRegistry->hasProcessor($fieldTypeIdentifier)) {
         $fieldTypeProcessor = $this->fieldTypeProcessorRegistry->getProcessor($fieldTypeIdentifier);
         $configurationHash = $fieldTypeProcessor->preProcessValidatorConfigurationHash($configurationHash);
     }
     $fieldType = $this->fieldTypeService->getFieldType($fieldTypeIdentifier);
     return $fieldType->validatorConfigurationFromHash($configurationHash);
 }
 public function testIsFieldNotEmpty()
 {
     $contentTypeId = 123;
     $contentInfo = new ContentInfo(array('contentTypeId' => $contentTypeId));
     $content = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\Content');
     $content->expects($this->any())->method('__get')->with('contentInfo')->will($this->returnValue($contentInfo));
     $fieldDefIdentifier = 'my_field_definition';
     $textLineFT = new TextLineType();
     $nonEmptyValue = new Value('Vive le sucre !!!');
     $emptyField = new Field(array('fieldDefIdentifier' => 'ezstring', 'value' => $nonEmptyValue));
     $contentType = $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType');
     $fieldDefinition = $this->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\ContentType\\FieldDefinition')->setConstructorArgs(array(array('fieldTypeIdentifier' => 'ezstring')))->getMockForAbstractClass();
     $contentType->expects($this->once())->method('getFieldDefinition')->with($fieldDefIdentifier)->will($this->returnValue($fieldDefinition));
     $this->contentTypeServiceMock->expects($this->once())->method('loadContentType')->with($contentTypeId)->will($this->returnValue($contentType));
     $this->translationHelper->expects($this->once())->method('getTranslatedField')->with($content, $fieldDefIdentifier)->will($this->returnValue($emptyField));
     $this->fieldTypeServiceMock->expects($this->any())->method('getFieldType')->with('ezstring')->will($this->returnValue($textLineFT));
     $this->assertFalse($this->fieldHelper->isFieldEmpty($content, $fieldDefIdentifier));
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $translatablePropertyTransformer = new TranslatablePropertyTransformer($options['languageCode']);
     $builder->add($builder->create('name', 'text', ['property_path' => 'names', 'label' => 'field_definition.name'])->addModelTransformer($translatablePropertyTransformer))->add('identifier', 'text', ['label' => 'field_definition.identifier'])->add($builder->create('description', 'text', ['property_path' => 'descriptions', 'required' => false, 'label' => 'field_definition.description'])->addModelTransformer($translatablePropertyTransformer))->add('isRequired', 'checkbox', ['required' => false, 'label' => 'field_definition.is_required'])->add('isTranslatable', 'checkbox', ['required' => false, 'label' => 'field_definition.is_translatable'])->add('fieldGroup', 'choice', ['choices' => []], ['required' => false, 'label' => 'field_definition.field_group'])->add('position', 'integer', ['label' => 'field_definition.position'])->add('selected', 'checkbox', ['required' => false, 'mapped' => false]);
     // Hook on form generation for specific FieldType needs
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         /** @var \EzSystems\RepositoryForms\Data\FieldDefinitionData $data */
         $data = $event->getData();
         $form = $event->getForm();
         $fieldTypeIdentifier = $data->getFieldTypeIdentifier();
         $fieldType = $this->fieldTypeService->getFieldType($fieldTypeIdentifier);
         // isSearchable field should be present only if the FieldType allows it.
         $form->add('isSearchable', 'checkbox', ['required' => false, 'disabled' => !$fieldType->isSearchable(), 'label' => 'field_definition.is_searchable']);
         // Let fieldType mappers do their jobs to complete the form.
         if ($this->fieldTypeMapperRegistry->hasMapper($fieldTypeIdentifier)) {
             $mapper = $this->fieldTypeMapperRegistry->getMapper($fieldTypeIdentifier);
             $mapper->mapFieldDefinitionForm($form, $data);
         }
     });
 }
 /**
  * Checks if provided field can be considered empty.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Content $content
  * @param string $fieldDefIdentifier
  * @param null $forcedLanguage
  *
  * @return bool
  */
 public function isFieldEmpty(Content $content, $fieldDefIdentifier, $forcedLanguage = null)
 {
     $field = $this->translationHelper->getTranslatedField($content, $fieldDefIdentifier, $forcedLanguage);
     $fieldDefinition = $this->getFieldDefinition($content->contentInfo, $fieldDefIdentifier);
     return $this->fieldTypeService->getFieldType($fieldDefinition->fieldTypeIdentifier)->isEmptyValue($field->value);
 }
 /**
  * Returns the field type with $fieldTypeIdentifier.
  *
  * @param string $fieldTypeIdentifier
  *
  * @return \eZ\Publish\API\Repository\FieldType
  */
 protected function getFieldType($fieldTypeIdentifier)
 {
     return $this->fieldTypeService->getFieldType($fieldTypeIdentifier);
 }
 /**
  * Instantiates a FieldType\Type object
  *
  * @todo Move this to a internal service provided to services that needs this (including this)
  *
  * @access private This function is for internal use only.
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If $type not properly setup
  *         with settings injected to service
  *
  * @param string $identifier
  *
  * @return \eZ\Publish\SPI\FieldType\FieldType
  */
 public function buildFieldType($identifier)
 {
     return $this->service->buildFieldType($identifier);
 }
 /**
  * Returns if there is a FieldType registered under $identifier.
  *
  * @param string $identifier
  *
  * @return bool
  */
 public function hasFieldType($identifier)
 {
     return $this->service->hasFieldType($identifier);
 }