getField example


    public function generateSorting(
        SortingInterface $sorting,
        QueryBuilder $query,
        ShopContextInterface $context
    ) {
        $this->addSorting($sorting$query);
    }

    private function addSorting(ProductAttributeSorting $sorting, QueryBuilder $query): void
    {
        $query->addOrderBy('productAttribute.' . $sorting->getField()$sorting->getDirection());
    }
}
$entity->colorHexCode = $row[$root . '.colorHexCode'];
        }
        if (isset($row[$root . '.mediaId'])) {
            $entity->mediaId = Uuid::fromBytesToHex($row[$root . '.mediaId']);
        }
        if (isset($row[$root . '.createdAt'])) {
            $entity->createdAt = new \DateTimeImmutable($row[$root . '.createdAt']);
        }
        if (isset($row[$root . '.updatedAt'])) {
            $entity->updatedAt = new \DateTimeImmutable($row[$root . '.updatedAt']);
        }
        $entity->media = $this->manyToOne($row$root$definition->getField('media')$context);
        $entity->group = $this->manyToOne($row$root$definition->getField('group')$context);

        $this->translate($definition$entity$row$root$context$definition->getTranslatedFields());
        $this->hydrateFields($definition$entity$root$row$context$definition->getExtensionFields());
        $this->customFields($definition$row$root$entity$definition->getField('customFields')$context);
        $this->manyToMany($row$root$entity$definition->getField('productProperties'));
        $this->manyToMany($row$root$entity$definition->getField('productOptions'));

        return $entity;
    }
}

    private function collect(string $entity, array &$payload): array
    {
        $definition = $this->registry->getByEntityName($entity);

        $map = [];
        foreach ($payload as &$row) {
            foreach ($row as $key => &$value) {
                if (\is_array($value) && isset($value['resolver']) && isset($value['value'])) {
                    $definition = $this->registry->getByEntityName($entity);

                    $field = $definition->getField($key);

                    $ref = match (true) {
                        $field instanceof FkField => $field->getReferenceDefinition()->getEntityName(),
                        $field instanceof IdField => $entity,
                        default => null
                    };

                    if ($ref === null) {
                        continue;
                    }

                    
static::assertCount(1, $criteriaCollection->all());
        /** @var Criteria $criteria */
        $criteria = $criteriaCollection->all()[SalesChannelProductDefinition::class]['product_id'];

        static::assertInstanceOf(Criteria::class$criteria);
        static::assertCount(1, $criteria->getFilters());
        /** @var OrFilter $orFilter */
        static::assertInstanceOf(OrFilter::class$orFilter = $criteria->getFilters()[0]);
        static::assertCount(2, $queries = $orFilter->getQueries());

        static::assertInstanceOf(EqualsFilter::class$firstQuery = $queries[0]);
        static::assertEquals('product.parentId', $firstQuery->getField());
        static::assertEquals('product123', $firstQuery->getValue());
        static::assertInstanceOf(EqualsFilter::class$secondQuery = $queries[1]);
        static::assertEquals('id', $secondQuery->getField());
        static::assertEquals('product123', $secondQuery->getValue());
    }

    public function testEnrichWithEmptyConfig(): void
    {
        $resolverContext = new ResolverContext($this->createMock(SalesChannelContext::class)new Request());
        $result = new ElementDataCollection();

        
$entity->mediaId = Uuid::fromBytesToHex($row[$root . '.mediaId']);
        }
        if (isset($row[$root . '.link'])) {
            $entity->link = $row[$root . '.link'];
        }
        if (isset($row[$root . '.createdAt'])) {
            $entity->createdAt = new \DateTimeImmutable($row[$root . '.createdAt']);
        }
        if (isset($row[$root . '.updatedAt'])) {
            $entity->updatedAt = new \DateTimeImmutable($row[$root . '.updatedAt']);
        }
        $entity->media = $this->manyToOne($row$root$definition->getField('media')$context);

        $this->translate($definition$entity$row$root$context$definition->getTranslatedFields());
        $this->hydrateFields($definition$entity$root$row$context$definition->getExtensionFields());
        $this->customFields($definition$row$root$entity$definition->getField('customFields')$context);

        return $entity;
    }
}
$entity->keyword = $row[$root . '.keyword'];
        }
        if (isset($row[$root . '.ranking'])) {
            $entity->ranking = (float) $row[$root . '.ranking'];
        }
        if (isset($row[$root . '.createdAt'])) {
            $entity->createdAt = new \DateTimeImmutable($row[$root . '.createdAt']);
        }
        if (isset($row[$root . '.updatedAt'])) {
            $entity->updatedAt = new \DateTimeImmutable($row[$root . '.updatedAt']);
        }
        $entity->product = $this->manyToOne($row$root$definition->getField('product')$context);
        $entity->language = $this->manyToOne($row$root$definition->getField('language')$context);

        $this->translate($definition$entity$row$root$context$definition->getTranslatedFields());
        $this->hydrateFields($definition$entity$root$row$context$definition->getExtensionFields());

        return $entity;
    }
}
if ($detail === null) {
            throw DataAbstractionLayerException::cannotCreateNewVersion($definition->getEntityName()$id);
        }

        $data = json_decode($this->serializer->serialize($detail, 'json'), true, 512, \JSON_THROW_ON_ERROR);

        $keepIds = $newId === $id;

        $data = $this->filterPropertiesForClone($definition$data$keepIds$id$definition$context->getContext());
        $data['id'] = $newId;

        $createdAtField = $definition->getField('createdAt');
        $updatedAtField = $definition->getField('updatedAt');

        if ($createdAtField instanceof DateTimeField) {
            $data['createdAt'] = new \DateTime();
        }

        if ($updatedAtField instanceof DateTimeField) {
            if ($updatedAtField->getFlag(Required::class)) {
                $data['updatedAt'] = new \DateTime();
            } else {
                $data['updatedAt'] = null;
            }
/** * @param FieldGrouping[] $groupings * * @return array{field: string, inner_hits?: array{name: string}} */
    private function parseGrouping(array $groupings, EntityDefinition $definition, Context $context): array
    {
        /** @var FieldGrouping $grouping */
        $grouping = array_shift($groupings);

        $accessor = $this->criteriaParser->buildAccessor($definition$grouping->getField()$context);
        if (empty($groupings)) {
            return ['field' => $accessor];
        }

        return [
            'field' => $accessor,
            'inner_hits' => [
                'name' => 'inner',
                'collapse' => $this->parseGrouping($groupings$definition$context),
            ],
        ];
    }
'id' => 'id', 'field_test' => 'field_test', 'user_id' => 'user_id']
    );
  }

  /** * Tests the output of a view with base fields and configurable fields. */
  public function testSimpleRender() {
    $executable = Views::getView('test_field_field_test');
    $executable->execute();

    $this->assertEquals('1', $executable->getStyle()->getField(0, 'id'));
    $this->assertEquals('3', $executable->getStyle()->getField(0, 'field_test'));
    $this->assertEquals('2', $executable->getStyle()->getField(1, 'id'));
    // @todo Switch this assertion to assertSame('', ...) when     // https://www.drupal.org/node/2488006 gets fixed.     $this->assertEquals('0', $executable->getStyle()->getField(1, 'field_test'));
    $this->assertEquals('3', $executable->getStyle()->getField(2, 'id'));
    $this->assertEquals('8', $executable->getStyle()->getField(2, 'field_test'));
    $this->assertEquals('4', $executable->getStyle()->getField(3, 'id'));
    $this->assertEquals('5', $executable->getStyle()->getField(3, 'field_test'));
    $this->assertEquals('5', $executable->getStyle()->getField(4, 'id'));
    $this->assertEquals('6', $executable->getStyle()->getField(4, 'field_test'));
  }

            ],
        ]);

        static::assertEquals('multi', $filter->getType());

        static::assertInstanceOf(MultiFilterStruct::class$filter);
        static::assertCount(2, $filter->getQueries());

        $ratings = $filter->getQueries()[0];
        static::assertInstanceOf(EqualsFilterStruct::class$ratings);
        static::assertEquals('ratings', $ratings->getField());
        static::assertEquals('2', $ratings->getValue());

        $category = $filter->getQueries()[1];
        static::assertInstanceOf(EqualsFilterStruct::class$category);
        static::assertEquals('category', $category->getField());
        static::assertEquals('5', $category->getValue());
    }

    public function testGetQueryParametersFromMultiFilter(): void
    {
        $filter = FilterStruct::fromArray([
            
'extensions' => $query->getExtensions(),
                ];
                $arrayQuery['query'] = QueryStringParser::toArray($query->getQuery());
                $array['query'][] = $arrayQuery;
            }
        }

        if (\count($criteria->getGroupFields())) {
            $array['grouping'] = [];

            foreach ($criteria->getGroupFields() as $groupField) {
                $array['grouping'][] = $groupField->getField();
            }
        }

        if (\count($criteria->getAggregations())) {
            $array['aggregations'] = $this->aggregationParser->toArray($criteria->getAggregations());
        }

        return $array;
    }
}
$entity->invalid = (bool) $row[$root . '.invalid'];
        }
        if (isset($row[$root . '.createdAt'])) {
            $entity->createdAt = new \DateTimeImmutable($row[$root . '.createdAt']);
        }
        if (isset($row[$root . '.updatedAt'])) {
            $entity->updatedAt = new \DateTimeImmutable($row[$root . '.updatedAt']);
        }

        $this->translate($definition$entity$row$root$context$definition->getTranslatedFields());
        $this->hydrateFields($definition$entity$root$row$context$definition->getExtensionFields());
        $this->customFields($definition$row$root$entity$definition->getField('customFields')$context);

        return $entity;
    }
}
ShopContextInterface $context
    ) {
        $this->addCondition($condition$query);
    }

    private function addCondition(ProductAttributeCondition $condition, QueryBuilder $query): void
    {
        $this->parse(
            $query,
            's_articles_attributes',
            'productAttribute',
            $condition->getField(),
            $condition->getValue(),
            $condition->getOperator()
        );
    }
}

        $parent = new ArrayNodeDefinition('root');
        $child = new ScalarNodeDefinition('child');

        $parent
            ->children()
                ->scalarNode('foo')->end()
                ->scalarNode('bar')->end()
            ->end()
            ->append($child);

        $this->assertCount(3, $this->getField($parent, 'children'));
        $this->assertContains($child$this->getField($parent, 'children'));
    }

    /** * @dataProvider providePrototypeNodeSpecificCalls */
    public function testPrototypeNodeSpecificOption(string $method, array $args)
    {
        $this->expectException(InvalidDefinitionException::class);
        $node = new ArrayNodeDefinition('root');

        
public function getType(): string
    {
        return 'date_histogram';
    }

    /** * {@inheritdoc} */
    protected function getArray(): array
    {
        $out = [
            'field' => $this->getField(),
            'calendar_interval' => $this->getInterval(),
        ];

        if (!empty($this->format)) {
            $out['format'] = $this->format;
        }

        return $out;
    }
}
Home | Imprint | This part of the site doesn't use cookies.