@param \Protobuf\Compiler\Entity             $entity
@param \google\protobuf\FieldDescriptorProto $field

@return string[]
490079
protected function generateReadCallback(Entity $entity, FieldDescriptorProto $field)
    {
        $body  = [];
        $sttm  = $this->generateFieldReadStatement($entity, $field);
        $lines = $this->addIndentation($sttm, 1);

        $body[] = '$readCallback = function (\Protobuf\ReadContext $context, $wire) {';
        $body[] = '    $reader = $context->getReader();';
        $body[] = '    $length = $context->getLength();';
        $body[] = '    $stream = $context->getStream();';
        $body[] = null;
        $body   = array_merge($body, $lines);
        $body[] = '};';

        return $body;
    }
756705
protected function generateAddValue(Entity $entity, FieldDescriptorProto $field)
    {
        $lines      = [];
        $fieldName  = $field->getName();
        $methodName = 'add' . $this->getClassifiedName($field);

        $lines[] = 'foreach ($values[\'' . $fieldName . '\'] as $item) {';
        $lines[] = '    $message->' . $methodName . '($item);';
        $lines[] = '}';

        return $lines;
    }
1086243
public function getFilterFieldDescriptors()
    {
        $fieldDescriptors = [];

        $fieldDescriptors['type_id'] = new DoctrineFieldDescriptor(
            'id',
            'type_id',
            self::$productTypeEntityName,
            null,
            [
                self::$productTypeEntityName => new DoctrineJoinDescriptor(
                    self::$productTypeEntityName,
                    static::$productEntityName . '.type'
                ),
            ]
        );

        $fieldDescriptors['status_id'] = new DoctrineFieldDescriptor(
            'id',
            'status_id',
            self::$productStatusEntityName,
            null,
            [
                self::$productStatusEntityName => new DoctrineJoinDescriptor(
                    self::$productStatusEntityName,
                    static::$productEntityName . '.status'
                ),
            ]
        );

        $fieldDescriptors['accounts_supplier_id'] = new DoctrineFieldDescriptor(
            'id',
            'supplier_id',
            self::$accountsSupplierEntityName,
            null,
            [
                self::$accountsSupplierEntityName => new DoctrineJoinDescriptor(
                    self::$accountsSupplierEntityName,
                    static::$productEntityName . '.supplier'
                ),
            ]
        );

        $fieldDescriptors['is_deprecated'] = new DoctrineFieldDescriptor(
            'isDeprecated',
            'is_deprecated',
            static::$productEntityName,
            null,
            []
        );

        $fieldDescriptors['parent'] = new DoctrineFieldDescriptor(
            'id',
            'parent',
            static::$productEntityName . 'Parent',
            'product.parent',
            [
                static::$productEntityName . 'Parent' => new DoctrineJoinDescriptor(
                    static::$productEntityName,
                    static::$productEntityName . '.parent'
                ),
            ],
            true
        );

        $fieldDescriptors['categories'] = new DoctrineFieldDescriptor(
            'id',
            'categories',
            static::$productEntityName . 'Categories',
            'products.categories',
            [
                static::$productEntityName . 'Categories' => new DoctrineJoinDescriptor(
                    static::$productEntityName,
                    static::$productEntityName . '.categories'
                ),
            ],
            true
        );

        $fieldDescriptors['attributes'] = new DoctrineFieldDescriptor(
            'id',
            'attributes',
            static::$productEntityName . 'ProductAttributes',
            'products.product-attributes',
            [
                static::$productEntityName . 'ProductAttributes' => new DoctrineJoinDescriptor(
                    static::$productEntityName,
                    static::$productEntityName . '.productAttributes'
                ),
            ],
            true
        );

        return $fieldDescriptors;
    }
498162
protected function generateExtensionField(Entity $entity, FieldDescriptorProto $field)
    {
        $name     = $field->getName();
        $number   = $field->getNumber();
        $docBlock = $this->getDocBlockType($field);
        $type     = $this->getFieldTypeName($field);
        $label    = $this->getFieldLabelName($field);
        $property = PropertyGenerator::fromArray([
            'static'       => true,
            'name'         => $name,
            'visibility'   => PropertyGenerator::VISIBILITY_PROTECTED,
            'docblock'     => [
                'shortDescription' => "Extension field : $name $label $type = $number",
                'tags'             => [
                    [
                        'name'        => 'var',
                        'description' => '\Protobuf\Extension',
                    ]
                ]
            ]
        ]);

        $property->getDocblock()->setWordWrap(false);

        return $property;
    }
152222
public function addField(\google\protobuf\FieldDescriptorProto $value)
    {
        if ($this->field === null) {
            $this->field = new \Protobuf\MessageCollection();
        }

        $this->field->add($value);
    }
1232736
protected function generateExtensionMethod(Entity $entity, FieldDescriptorProto $field)
    {
        $fieldName  = $field->getName();
        $descriptor = $entity->getDescriptor();
        $methodName = $this->getCamelizedName($field);
        $bodyGen    = new ExtensionsGenerator($this->context);
        $body       = implode(PHP_EOL, $bodyGen->generateBody($entity, $field));
        $method     = MethodGenerator::fromArray([
            'static'     => true,
            'body'       => $body,
            'name'       => $methodName,
            'docblock'   => [
                'shortDescription' => "Extension field : $fieldName",
                'tags'             => [
                    [
                        'name'        => 'return',
                        'description' => '\Protobuf\Extension',
                    ]
                ]
            ]
        ]);

        $method->getDocblock()->setWordWrap(false);

        return $method;
    }
1043335
public function getEntityAccessFields($entity, $bundle) {
    $fields = [];
    $field_definitions = $this->entityManager->getFieldDefinitions($entity, $bundle->id());
    foreach ($field_definitions as $field_name => $field_definition) {
      if (!empty($field_definition->getTargetBundle())) {
        if ($field_definition->getType() === 'entity_access_field') {
          $fields[$field_name] = $field_definition;
        }
      }
    }
    return $fields;
  }
1260304
protected function getFieldLabelName(FieldDescriptorProto $field)
    {
        $label = $field->getLabel()->value();
        $name  = Field::getLabelName($label);

        return $name ?: 'unknown';
    }
649744
protected function generateAccessorsMethods(Entity $entity)
    {
        $methods    = [];
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];

        foreach ($fields as $field) {
            $methods[] = $this->generateHasMethod($entity, $field);
            $methods[] = $this->generateGetterMethod($entity, $field);
            $methods[] = $this->generateSetterMethod($entity, $field);

            if ($field->getLabel() === Label::LABEL_REPEATED()) {
                $methods[] = $this->generateAddMethod($entity, $field);
            }
        }

        $methods[] = $this->generateGetExtensionsMethod($entity);
        $methods[] = $this->generateGetUnknownFieldSetMethod($entity);

        return $methods;
    }
420674
protected function getFieldDescriptors($locale, $isForOutput = false)
    {
        $fieldDescriptors = [];

        $fieldDescriptors['id'] = new DoctrineFieldDescriptor(
            'id',
            'id',
            'SuluProductBundle:Addon',
            'public.id',
            [],
            true,
            false,
            'integer'
        );

        $fieldDescriptors['addonName'] = new DoctrineFieldDescriptor(
            'name',
            'addonName',
            'SuluProductBundle:ProductTranslation',
            'products.product-addon',
            [
                'SuluProductBundle:ProductAddon' => new DoctrineJoinDescriptor(
                    'SuluProductBundle:Product',
                    'SuluProductBundle:Addon.addon'
                ),
                'SuluProductBundle:ProductTranslation' => new DoctrineJoinDescriptor(
                    'SuluProductBundle:ProductTranslation',
                    'SuluProductBundle:ProductAddon.translations',
                    'SuluProductBundle:ProductTranslation.locale = \'' . $locale . '\''
                ),
            ],
            false,
            true,
            'string'
        );

        $fieldDescriptors['number'] = new DoctrineFieldDescriptor(
            'number',
            'number',
            'SuluProductBundle:ProductAddon',
            'product.number',
            [],
            false,
            true,
            'string'
        );

        // We dont want to have the productId in the fields action.
        if (!$isForOutput) {
            $fieldDescriptors['productId'] = new DoctrineFieldDescriptor(
                'id',
                'productId',
                'SuluProductBundle:Product',
                'addon.product',
                [
                    'SuluProductBundle:Product' => new DoctrineJoinDescriptor(
                        'SuluProductBundle:Product',
                        'SuluProductBundle:Addon.product'
                    ),
                ],
                false,
                false,
                'integer'
            );
        }

        return $fieldDescriptors;
    }
361710
public function getEntityArrayValues($entity)
    {
        $values = [];
        $properties = $this->getEntityProperties($entity);
        $metadata = $this->em->getClassMetadata(get_class($entity));
        foreach ($properties as $property) {
            $values[$property] = $metadata->getFieldValue($entity, $property);
        }
        return $values;
    }
830684
public function getEntityProperties($entity)
    {
        $metadata = $this->em->getClassMetadata(get_class($entity));
        return array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
    }
418026
protected function getListBuilder($entityName, $fieldDescriptors)
    {
        /** @var RestHelperInterface $restHelper */
        $restHelper = $this->get('sulu_core.doctrine_rest_helper');

        /** @var DoctrineListBuilderFactory $factory */
        $factory = $this->get('sulu_core.doctrine_list_builder_factory');

        $listBuilder = $factory->create($entityName);

        $restHelper->initializeListBuilder(
            $listBuilder,
            $fieldDescriptors
        );

        return $listBuilder;
    }
692067
public function getIndexData(Field $field, FieldDefinition $fieldDefinition)
    {
        $tagKeywords = [];
        $parentTagIds = [];
        $tagIds = [];

        if (!empty($field->value->externalData)) {
            foreach ($field->value->externalData as $tag) {
                if (isset($tag['keywords'][$field->languageCode])) {
                    $tagKeywords[] = $tag['keywords'][$field->languageCode];
                    $parentTagIds[] = $tag['parent_id'];
                    $tagIds[] = $tag['id'];
                } elseif (isset($tag['keywords'][$tag['main_language_code']])) {
                    $tagKeywords[] = $tag['keywords'][$tag['main_language_code']];
                    $parentTagIds[] = $tag['parent_id'];
                    $tagIds[] = $tag['id'];
                } else {
                    // Something went wrong with the tag, we will not index it
                    continue;
                }
            }
        }

        return [
            new Search\Field(
                'tag_keywords',
                $tagKeywords,
                new Search\FieldType\MultipleStringField()
            ),
            new Search\Field(
                'parent_tag_ids',
                $parentTagIds,
                new Search\FieldType\MultipleIntegerField()
            ),
            new Search\Field(
                'tag_ids',
                $tagIds,
                new Search\FieldType\MultipleIntegerField()
            ),
            new Search\Field(
                'tag_text',
                implode(' ', $tagKeywords),
                new Search\FieldType\TextField()
            ),
            new Search\Field(
                'fulltext',
                implode(' ', $tagKeywords),
                new Search\FieldType\FullTextField()
            ),
        ];
    }
646268
protected function generateFieldSizeStatement(Entity $entity, FieldDescriptorProto $field)
    {
        $generator = new SerializedSizeFieldStatementGenerator($this->context);
        $statement = $generator->generateFieldSizeStatement($entity, $field);

        return $statement;
    }
1349989
protected function generateHasMethod(Entity $entity, FieldDescriptorProto $field)
    {
        $fieldName  = $field->getName();
        $methodName = $this->getAccessorName('has', $field);
        $method     = MethodGenerator::fromArray([
            'name'       => $methodName,
            'body'       => 'return $this->' . $fieldName . ' !== null;',
            'docblock'   => [
                'shortDescription' => "Check if '$fieldName' has a value",
                'tags'             => [
                    [
                        'name'        => 'return',
                        'description' => 'bool',
                    ]
                ]
            ]
        ]);

        return $method;
    }
1000371
protected function generateGetterMethod(Entity $entity, FieldDescriptorProto $field)
    {
        $fieldName  = $field->getName();
        $methodName = $this->getAccessorName('get', $field);
        $method     = MethodGenerator::fromArray([
            'name'       => $methodName,
            'body'       => 'return $this->' . $fieldName . ';',
            'docblock'   => [
                'shortDescription' => "Get '$fieldName' value",
                'tags'             => [
                    [
                        'name'        => 'return',
                        'description' => $this->getDocBlockType($field),
                    ]
                ]
            ]
        ]);

        $method->getDocblock()->setWordWrap(false);

        return $method;
    }