@param string      $entity
@param string|null $field

@return string
350920
protected function guessPluralField($entity, $field = null)
    {
        return $field ?: Inflector::pluralize($this->guessSingularField($entity));
    }
968539
public function getBlockVariables($field, $entity)
    {
        $defaults = parent::getBlockVariables($field, $entity);

        return [
            'value' => $defaults['value'],
            'label_link' => $field->getOption('label_link', 'Link'),
            'mailto' => $field->getOption('mailto', false),
        ] + $defaults;
    }
726217
public function returnId($entity = null)
	{
	    if (substr ($entity, 0, 1) == "/") {
	        $entityID = $this->pathId($entity);
	    } else {
	        $entityID = $this->titleId($entity);
	    }

	    return $entityID;
	}
427174
private function getFieldValue($entity, \ReflectionProperty $reflectionProperty)
    {
        $value = null;
        if ($reflectionProperty) {
            $reflectionProperty->setAccessible(true);
            $value = $reflectionProperty->getValue($entity);
        }

        return $value;
    }
1181246
protected function embedsOne(string $entity, string $field)
    {
        if (is_subclass_of($entity, Schema::class)) {
            $entity = (new $entity())->entityClass;
        }

        $items = (array) $this->$field;
        if (false === empty($items) && false === array_key_exists(0, $items)) {
            $items = [$items];
        }

        return Ioc::make(CursorFactory::class)
            ->createEmbeddedCursor($entity, $items)->first();
    }
562226
protected function getField($field)
    {
        if ($this->isFieldSupported($field) && isset($this->fields[ $field ])) {
            return $this->fields[ $field ];
        }

        return null;
    }
188212
public function getFieldsChoices($entity = null)
    {
        $entityChoices = $this->getEntityChoices();

        $fieldsChoices = [];

        $translator = $this->getContainer()->get('translator');

        $adminPool = $this->getContainer()->get('sonata.admin.pool');

        $em = $this->getContainer()->get('doctrine')->getManager();

        foreach ($entityChoices as $entityChoiceKey => $entityChoice) {
            if ($entity && $entityChoice !== $entity) {
                continue;
            }

            $admin = $adminPool->getAdminByClass($entityChoice);

            if (!$admin) {
                throw new \RuntimeException('Not found admin by class: ' . $entityChoice);
            }

            $translation_domain = $admin->getTranslationDomain();

            $classMetadata = $em->getClassMetadata($entityChoice);

            /** @var array $associationMappings */
            $associationMappings = $classMetadata->associationMappings;

            /** @var array $fieldsMappings */
            $fieldsMappings = $classMetadata->fieldMappings;

            foreach ($fieldsMappings as $fieldsMapping) {
                $fieldsChoices[$fieldsMapping['fieldName']] =
                    $entityChoiceKey . ' / ' . $translator->trans('form.label_' . $fieldsMapping['columnName'], [], $translation_domain);
            }

            foreach ($associationMappings as $associationMapping) {
                $mappingFieldName = $associationMapping['fieldName'];
                $mappingAdmin = $adminPool->getAdminByClass($associationMapping['targetEntity']);

                if (!$mappingAdmin) {
                    continue;
                }

                $mappingTranslationDomain = $mappingAdmin->getTranslationDomain();

                $classMetadataMapping = $em->getClassMetadata($associationMapping['targetEntity']);

                /** @var array $fieldsMappingsMapping */
                $fieldsMappingsMapping = $classMetadataMapping->fieldMappings;

                foreach ($fieldsMappingsMapping as $fieldsMappingAssoc) {
                    $fieldsChoices[$mappingFieldName . '.' . $fieldsMappingAssoc['fieldName']] =
                        $entityChoiceKey . ' / '
                        . $translator->trans('form.label_' . $this->camelCaseToUnderscore($mappingFieldName), [], $translation_domain) . ' / '
                        . $translator->trans('form.label_' . $this->camelCaseToUnderscore($fieldsMappingAssoc['fieldName']), [], $mappingTranslationDomain);
                }
            }
        }

        return $fieldsChoices;
    }
174558
protected function getEditionResponse(Entity $entity = null)
    {
        // Create a new HTML response.
        $response = $this->getHtmlResponse();
        // Indicate where is the template.
        $response->setTemplateId(sprintf(
            '%s/edit',
            $this->getCollectionName()
        ));
        // If there is an entity ID, load that entity in the response as well.
        if ($entity) {
            $response->setData(
                $this->getItemName(),
                $entity->getFieldsData()
            );
        }

        return $response;
    }
901533
public function getBlockVariables($field, $entity)
    {
        $defaults = parent::getBlockVariables($field, $entity);

        // Date_format should be any format supported by http://php.net/manual/en/function.date.php
        $date_format = $field->getOption('date_format', 'c');

        $date = $defaults['value'];

        if (!$date instanceof \DateTime) {
            $variables = [
                'value' => null,
                'datetime' => null,
            ];
        }
        else {
            $variables = [
                'value' => $date->format($date_format),
                'datetime' => $date->format(\DateTime::RFC3339),
            ];
        }

        return $variables + $defaults;
    }
445240
public function getBlockVariables($field, $entity)
    {
        if ($field->getOption('callback')) {
            $value = call_user_func($field->getOption('callback'), $entity);
        }
        else {
            $value = $field->getData($entity);
        }

        return [
            'field_name' => $field->getName(),
            'value' => $value,
            'default_value' => $field->getOption('default_value', 'null'),
        ];
    }
906063
public function forTemplate($field = null)
    {
        // debugging info for a specific field
        $class = get_class($this->object);
        if ($field) {
            return "<b>Debugging Information for {$class}->{$field}</b><br/>" . ($this->object->hasMethod($field) ? "Has method '$field'<br/>" : null) . ($this->object->hasField($field) ? "Has field '$field'<br/>" : null);
        }

        // debugging information for the entire class
        $reflector = new ReflectionObject($this->object);
        $debug = "<b>Debugging Information: all methods available in '{$class}'</b><br/><ul>";

        foreach ($this->object->allMethodNames() as $method) {
            // check that the method is public
            if ($method[0] === strtoupper($method[0]) && $method[0] != '_') {
                if ($reflector->hasMethod($method) && $method = $reflector->getMethod($method)) {
                    if ($method->isPublic()) {
                        $debug .= "<li>\${$method->getName()}";

                        if (count($method->getParameters())) {
                            $debug .= ' <small>(' . implode(', ', $method->getParameters()) . ')</small>';
                        }

                        $debug .= '</li>';
                    }
                } else {
                    $debug .= "<li>\$$method</li>";
                }
            }
        }

        $debug .= '</ul>';

        if ($this->object->hasMethod('toMap')) {
            $debug .= "<b>Debugging Information: all fields available in '{$class}'</b><br/><ul>";

            foreach ($this->object->toMap() as $field => $value) {
                $debug .= "<li>\$$field</li>";
            }

            $debug .= "</ul>";
        }

        // check for an extra attached data
        if ($this->object->hasMethod('data') && $this->object->data() != $this->object) {
            $debug .= ViewableData_Debugger::create($this->object->data())->forTemplate();
        }

        return $debug;
    }
1239132
private function entityToString(EntityInterface $entity)
    {
        $template = "Values: %s";
        $entityValues = null;
        
        foreach ($entity->toArray() as $propertyName => $propertyValue) {
            $entityValues = sprintf("%s\n\t%s = '%s'", $entityValues, $propertyName, $this->stringifyValue($propertyValue));
        }
        
        return sprintf($template, $entityValues);
    }
1312742
protected function updateField(Entity $entity, $field) {
		if ($entity->dirty($field)) {
			return;
		}

		$entity->set($field, $this->getUserId());
	}
850880
public function getHeader($field)
    {
       if (!isset($this->headers[$field])) {
           return null;
       }
       
       return is_array($this->headers[$field]) ? implode(',', $this->headers[$field]) : $this->headers[$field];
    }
198485
public function map($field, $context = null)
    {
        if ($context instanceof JsonDefinition &&
            $context->getField($field['fieldName']) instanceof DefinitionElementInterface
        ) {
            $fieldInformation = $context->getField($field['fieldName'])
                ->getDefAsArray();

            // in this context, the default type is the doctrine type..
            if (isset($fieldInformation['doctrineType'])) {
                $fieldInformation['type'] = $fieldInformation['doctrineType'];
            }

            $field = array_merge($field, $fieldInformation);
        }

        return $field;
    }
1086244
public function getSelfSubUrl($entity = null)
    {
        if ($entity === null) {
            return null;
        }

        return Router::url($this->_getRepositoryRoutingParameters($this->_repository) + [
            '_method' => 'GET',
            'action' => 'view',
            $entity->get($this->_repository->getPrimaryKey()),
        ], $this->_view->viewVars['_absoluteLinks']);
    }
1137905
public function generateBody(Entity $entity)
    {
        $lines      = [];
        $addLine    = false;
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];
        $defaults   = $this->generateDefaultValues($entity);

        foreach ($fields as $field) {
            if ($field->getLabel() !== Label::LABEL_REQUIRED()) {
                continue;
            }

            if ($field->hasDefaultValue()) {
                continue;
            }

            $item  = $this->generateRequiredFieldException($entity, $field);
            $lines = array_merge($lines, $item, [null]);
        }

        $lines[] = '$message = new self();';
        $lines[] = '$values  = array_merge([';
        $lines   = array_merge($lines, $this->addIndentation($defaults, 1));
        $lines[] = '], $values);';
        $lines[] = null;

        foreach ($fields as $field) {
            if ($field->getLabel() === Label::LABEL_REPEATED()) {
                continue;
            }

            $item  = $this->generateSetValue($entity, $field);
            $lines = array_merge($lines, $item);

            $addLine = true;
        }

        if ($addLine) {
            $lines[] = null;
        }

        foreach ($fields as $field) {
            if ($field->getLabel() !== Label::LABEL_REPEATED()) {
                continue;
            }

            $item  = $this->generateAddValue($entity, $field);
            $lines = array_merge($lines, $item, [null]);
        }

        $lines[] = 'return $message;';

        return $lines;
    }