/**
  * @param \Twig_Environment $environment
  * @param FieldableEntity $entity
  * @param string $field
  *
  * @return string
  * @internal param \Twig_Environment $environment
  */
 public function renderFieldDisplay(\Twig_Environment $environment, FieldableEntity $entity, $field)
 {
     $class = get_class($entity);
     $displayMapping = $this->displayManager->getEntityConfig($class);
     $fieldSettings = $this->fieldManager->getEntityFieldMapping($class);
     $html = '';
     if ($displayMapping['options']['fields'][$field]) {
         $displayFieldSettings = $displayMapping['options']['fields'][$field] + ['type' => null, 'label' => true, 'label_inline' => false, 'options' => []];
         $display = $this->displayManager->getDisplayDefinition($displayFieldSettings['type']);
         $fieldEntity = call_user_func([$entity, 'get' . $field]);
         $fieldDisplayOptions = $displayFieldSettings['options'] ?: [];
         $templateOptions = ['entity' => $fieldEntity, 'field_settings' => $fieldSettings, 'field_name' => $field, 'label' => is_string($displayFieldSettings['label']) ?: ($displayFieldSettings['label'] ? $field : false), 'label_inline' => $displayFieldSettings['label_inline']];
         if ($fieldSettings[$field]['options']['limit'] > 1) {
             $subHtml = '';
             $subTemplateOptions = $templateOptions;
             $subTemplateOptions['label'] = false;
             foreach ($fieldEntity as $fieldEntityItem) {
                 $subHtml .= $environment->render($display->getTemplate(), $subTemplateOptions + $display->getTemplateOptions($fieldEntityItem, $fieldDisplayOptions));
             }
             $templateOptions['rows'] = $subHtml;
             $html = $environment->render($display->getListTemplate(), $templateOptions + $display->getListTemplateOptions($fieldEntity, $fieldDisplayOptions));
         } else {
             $html = $environment->render($display->getTemplate(), $templateOptions + $display->getTemplateOptions($fieldEntity, $fieldDisplayOptions));
         }
     }
     return $html;
 }
 /**
  * {@inheritDoc}
  */
 public function getOptions($term, array $options)
 {
     $fieldSearch = ['vocab' => [], 'terms' => ['name' => $term]];
     $fieldDefinitions = $this->fieldManager->getEntityFieldMapping($options['class']);
     foreach ($fieldDefinitions as $fieldName => $fieldDefinition) {
         if ($fieldDefinition['searchable']) {
             $fieldSearch['terms'][$fieldName] = $term;
         }
     }
     /** @var Tag[] $taxonomies */
     $taxonomies = $this->searchAdaptor->search($options['class'], $fieldSearch, $options['page_size'], $options['page_offset']);
     $tagOptions = [];
     foreach ($taxonomies as $taxonomy) {
         $tagOptions[] = ['text' => (string) $taxonomy, 'id' => $taxonomy->getId()];
     }
     if ($options['allow_new']) {
         $tagOptions[] = ['text' => $term, 'id' => $term];
     }
     return $tagOptions;
 }
 /**
  * @param FormMapper $formMapper
  */
 protected function configureFormFields(FormMapper $formMapper)
 {
     $formMapper->with('Content', ['class' => 'col-md-9'])->end()->with('Publishing', ['class' => 'col-md-3'])->end()->with('Routing', ['class' => 'col-md-3'])->add('path', 'text', ['required' => false])->end();
     $fieldMappings = $this->fieldManager->getEntityFieldMapping($this->getClass());
     $formMapper->with('Content');
     foreach ($fieldMappings as $field => $settings) {
         $fieldDefinition = $this->fieldManager->getFieldDefinition($settings['type']);
         $fieldWidgetDefinition = $this->fieldManager->getFieldWidgetDefinition($settings['widget']['type']);
         $constraints = $fieldDefinition->getConstraints($field, $settings['options']);
         // TODO: deprecate dynamic
         if ($settings['dynamic']) {
             $fieldWidgetDefinition->configureForm($formMapper, $fieldDefinition, $field, $settings['options'], $settings['widget']['type'], $settings['widget']['options']);
             $formMapper->getFormBuilder()->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $formEvent) use($fieldDefinition, $field, $settings) {
                 $data = $formEvent->getData();
                 if ($data instanceof Node) {
                     $value = $data->{"get{$field}"}();
                     if (!$value || !count($value) && $settings['options']['limit'] == 1) {
                         $fieldClass = $fieldDefinition->getEntityClass();
                         if ($fieldClass) {
                             $data->{"set{$field}"}(new $fieldClass());
                         }
                     }
                 }
             });
         } else {
             $fieldWidgetDefinition->configureForm($formMapper, $fieldDefinition, $field, $settings['options'], $settings['widget']['type'], $settings['widget']['options']);
             /** @var ClassMetadata $metadata */
             $metadata = $this->validator->getMetadataFactory()->getMetadataFor($this->getClass());
             foreach ($constraints as $constraintField => $constraint) {
                 $metadata->addPropertyConstraints($constraintField, $constraint);
             }
         }
     }
     $formMapper->end();
     $formMapper->end();
 }