getFieldVisibility example


        $definition = $this->getContainer()->get(CustomerDefinition::class);

        $internalFields = [
            'password',
            'newsletterSalesChannelIds',
            'legacyPassword',
            'legacyEncoder',
        ];

        foreach ($internalFields as $field) {
            static::assertTrue($definition->getFieldVisibility()->isVisible($field));
            FieldVisibility::$isInTwigRenderingContext = true;
            static::assertFalse($definition->getFieldVisibility()->isVisible($field));
            FieldVisibility::$isInTwigRenderingContext = false;
        }
    }
}
foreach ($internalFields as $field) {
                $this->testAccessibilityForField($definition$field->getPropertyName()$definition->getEntityClass());
                $this->testAccessibilityForField($definition$field->getPropertyName(), PartialEntity::class);
            }
        }
    }

    private function testAccessibilityForField(EntityDefinition $definition, string $propertyName, string $entityClass): void
    {
        $entity = new $entityClass();
        $entity->internalSetEntityData($definition->getEntityName()$definition->getFieldVisibility());

        $twig = $this->initTwig($propertyName);

        $result = $twig->render('json-encode.twig', ['object' => $entity]);
        static::assertStringNotContainsString('password', $result);

        $result = $twig->render('get-vars.twig', ['object' => $entity]);
        static::assertStringNotContainsString('password', $result);

        $innerException = null;

        
$entity = new $entityClass();

        if (!$entity instanceof Entity) {
            throw new \RuntimeException(sprintf('Expected instance of Entity.php, got %s', $entity::class));
        }

        $entity->addExtension(EntityReader::FOREIGN_KEYS, new ArrayStruct([]$definition->getEntityName() . '_foreign_keys_extension'));
        $entity->addExtension(EntityReader::INTERNAL_MAPPING_STORAGE, new ArrayStruct());

        $entity->setUniqueIdentifier($identifier);
        $entity->internalSetEntityData($definition->getEntityName()$definition->getFieldVisibility());

        $entity = $hydrator->assign($definition$entity$root$row$context);

        return self::$hydrated[$cacheKey] = $entity;
    }
}
Home | Imprint | This part of the site doesn't use cookies.