1
AppBundle\Entity\UserAccount:
    UserAccount_{1..5}:
        emailConfirmed: '80%? 1 : 0'
        enabled: ????

How to set enabled field to hold the same value as emailConfirmed field. In other words - how to reference other field value in the same entity?

1 Answers1

0

Create custom processor as described in documentation:

A alice processor can be used to manipulate a object before and after persisting. To register a own processor, create a service and tag it.

Create processor whenever you want (for ex. AppBundle\DataFixtures\MyProcessor:

<?php
namespace AppBundle\DataFixtures;
use Nelmio\Alice\ProcessorInterface;
class MyProcessor implements ProcessorInterface
{
    /**
     * @param object $object instance to process
     */
    public function preProcess($object)
    {
        if (!$object instanceof AppBundle\Entity\UserAccount) {
            return;
        }

        $object->setEnabled($object->getConfirmed());
    }

    /**
     * @param object $object instance to process
     */
    public function postProcess($object)
    {

    }
}

Add service:

services:
    my.alice.processor:
        class: AppBundle\DataFixtures\MyProcessor
        tags:
            -  { name: h4cc_alice_fixtures.processor }
malcolm
  • 5,486
  • 26
  • 45