Make a new UserField based on the given AttendeeExtraField

@param AttendeeExtraField $attendeeField
969603
private function findOrMakeUserFieldFor(AttendeeExtraField $attendeeField)
    {
        if (!$field = $this->getUserFields()->byID($attendeeField->ID)) {
            /** @var UserField $field */
            $class = self::mapFieldType($attendeeField->FieldType, $attendeeField->FieldName);
            $field = $class::create();
        }

        $field->ClassName = self::mapFieldType($attendeeField->FieldType, $attendeeField->FieldName);
        $field->ID = $attendeeField->ID;
        $field->Name = $attendeeField->FieldName;
        $field->Title = $attendeeField->Title;
        $field->Default = $attendeeField->DefaultValue;
        $field->ExtraClass = $attendeeField->ExtraClass;
        $field->Required = $attendeeField->Required;
        $field->Editable = $attendeeField->Editable;
        $field->EventID = $attendeeField->EventID;
        $field->Sort = $attendeeField->Sort;

        if ($attendeeField->Options()->exists() && $field->ClassName === 'UserOptionSetField') {
            /** @var \UserOptionSetField $field */
            /** @var AttendeeExtraFieldOption $attendeeOption */
            foreach ($attendeeField->Options() as $option) {
                $field->Options()->add($this->findOrMakeUserOptionFor($option));
                echo "[{$field->ID}] Added AttendeeExtraFieldOption as UserFieldOption\n";
            }
        }

        $field->write();
        echo "[{$field->ID}] Migrated AttendeeExtraField to $field->ClassName\n";
    }
100809
protected function initializeField($field)
    {
        $field->setParentContext($this);
        $this->getFieldManager()->pushField($field);
        return $field;
    }
708399
private function setupFields(News $owner, FieldList $fields)
    {
        // Remove all basic fields from parent, so we can setup as we wish.
        $fields->removeByName(array_keys($owner->db()));
        $fields->removeByName(array_keys($owner->has_one()));
        $fields->removeByName(array_keys($owner->has_many()));
        $fields->removeByName(array_keys($owner->many_many()));
        // For some reason, not all fields are removed from the has_one list. So I'll have to add "ID" to the strings.
        foreach ($owner->has_one() as $hasOne) {
            $fields->removeByName($hasOne . 'ID');
        }
        $fields->removeByName('Commenting');
        /** @var array $fieldset The array of fields that should be visible */
        $fieldset = $this->field_list;
        foreach ($fieldset as $key => $fieldlist) {
            ksort($fieldlist);
            $fields->addFieldsToTab($key, $fieldlist);
        }

        return $fields;
    }
512870
public function onBeforeWrite()
    {
        // Set the title of the attendee
        $this->Title = $this->getName();

        // Generate the ticket code
        if ($this->exists() && empty($this->TicketCode)) {
            $this->TicketCode = $this->generateTicketCode();
        }

        if (
            $this->getEmail()
            && $this->getName()
            && !$this->TicketFile()->exists()
            && !$this->TicketQRCode()->exists()
        ) {
            $this->createQRCode();
            $this->createTicketFile();
        }

        if ($fields = $this->Fields()) {
            foreach ($fields as $field) {
                if ($value = $this->{"$field->Name[$field->ID]"}) {
                    //$cache = self::getCacheFactory();
                    //$cache->save(serialize($value), $this->getFieldCacheKey($field));
                    $fields->add($field->ID, array('Value' => $value));
                }
            }
        }

        parent::onBeforeWrite();
    }
1006293
@Override
    public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
        fieldAlreadyExists |= name.equals(versionFieldName);

        return super.visitField(access, name, desc, signature, value);
    }
1291931
protected function createAttendee() {
		$attendee = EventAttendee::create();
		$attendee->RegistrationID = $this->registration->ID;
		return $attendee;
	}
210048
public function addField(Field $field)
    {
        $tmp               = $this->fields->getValue($this->entity);
        $tmp[$field->name] = $field;
        $this->fields->setValue($this->entity, $tmp);

        if ($field->role == 'id') {
            $key = new \ReflectionProperty(Entity::class, 'key');
            $key->setAccessible(true);
            $key->setValue($this->entity, $field->name);
        }
    }
698390
private function AddUserGroupField()
    {
        $name = 'UserGroup';
        $field = new Select($name, '');
        
        $parentGroup = $this->FindParentGroup();
        $inheritText = $parentGroup ? Trans('Core.PageForm.UserGroup.Inherit_{0}', $parentGroup->GetName()) :
                Trans('Core.PageForm.UserGroup.Inherit');
        
        $field->AddOption('', $inheritText);
        if ($this->page->Exists() && $this->page->GetUserGroup())
        {
            $field->SetValue($this->page->GetUserGroup()->GetID());
        }
        DBSelectUtil::AddUserGroupOptions($field);
        $this->AddField($field);
    }
703146
public function addField($name, $decorator = null, $field = null)
    {
        if (!is_string($name)) {
            throw new Exception(['Format for addField now require first argument to be name']);
        }

        if (!$this->form->model) {
            $this->form->model = new \atk4\ui\misc\ProxyModel();
        }

        if (is_string($field)) {
            $field = ['type' => $field];
        }

        if ($name) {
            $existingField = $this->form->model->hasElement($name);
        }

        try {
            if (!$existingField) {
                // Add missing field
                if ($field) {
                    $field = $this->form->model->addField($name, $field);
                } else {
                    $field = $this->form->model->addField($name);
                }
            } elseif (is_array($field)) {
                // Add properties to existing field
                $existingField->setDefaults($field);
                $field = $existingField;
            } elseif (is_object($field)) {
                throw new Exception(['Duplicate field', 'name' => $name]);
            } else {
                $field = $existingField;
            }

            if (is_string($decorator)) {
                $decorator = $this->form->decoratorFactory($field, ['caption' => $decorator]);
            } elseif (is_array($decorator)) {
                $decorator = $this->form->decoratorFactory($field, $decorator);
            } elseif (!$decorator) {
                $decorator = $this->form->decoratorFactory($field);
            } elseif (is_object($decorator)) {
                if (!$decorator instanceof \atk4\ui\FormField\Generic) {
                    throw new Exception(['Field decorator must descend from \atk4\ui\FormField\Generic', 'decorator' => $decorator]);
                }
                $decorator->field = $field;
                $decorator->form = $this->form;
            } else {
                throw new Exception(['Value of $decorator argument is incorrect', 'decorator' => $decorator]);
            }
        } catch (\Throwable $e) {
            throw new Exception(['Unable to add form field', 'name' => $name, 'decorator' => $decorator, 'field' => $field], null, $e);
        }

        return $this->_addField($decorator, $field);
    }
928899
protected function createRememberTokenIfDoesntExist(UserInterface $user)
    {
        $rememberToken = $user->getRememberToken();

        if (empty($rememberToken)) {
            $this->refreshRememberToken($user);
        }
    }
513289
public function preCreate(CreateEvent $event)
    {
        /** @var Group $role */
        $object = $event->getObject();
        $user = $this->tokenStorage->getToken()->getUser();

        if ($user instanceof User) {
            $object->setUser($user);
        } else {
            $object->setUser($this->userManager->getDefaultClarolineUser());
        }
    }
1062606
@Nonnull
    public BugInstance addVisitedField(PreorderVisitor visitor) {
        FieldAnnotation f = FieldAnnotation.fromVisitedField(visitor);
        addField(f);
        return this;
    }
224457
private function createLocalCField(AItem $owner, OwnField $ownMeta, & $result)
    {
        $field_name = $ownMeta->getName();
        $fieldType = $ownMeta->getFieldType();

        if(array_key_exists($field_name, $result))
        {
            $scalarItem = $this->cItemBuilder->create($fieldType, $result[$field_name]);
        }
        else
        {
            $scalarItem = $this->cItemBuilder->createCap($fieldType);
        }

        $newField = new ACOwnField($owner, $ownMeta);
        $newField->setItem($scalarItem);

        return $newField;
    }
72799
public function replaceEventInvitationUser(User $from, User $to)
    {
        $eventInvitations = $this->om->getRepository('ClarolineAgendaBundle:EventInvitation')->findByUser($from);

        if (count($eventInvitations) > 0) {
            foreach ($eventInvitations as $eventInvitation) {
                $eventInvitation->setUser($to);
            }

            $this->om->flush();
        }

        return count($eventInvitations);
    }
504187
public function preCreate(CreateEvent $event)
    {
        $subject = $event->getObject();
        $forum = $subject->getForum();

        //create user if not here
        $user = $this->om->getRepository('ClarolineForumBundle:Validation\User')->findOneBy([
          'user' => $subject->getCreator(),
          'forum' => $forum,
        ]);

        if (!$user) {
            $user = new User();
            $user->setForum($forum);
            $user->setUser($subject->getCreator());
        }

        $messages = $subject->getMessages();
        $first = $messages && isset($messages[0]) ? $messages[0] : null;

        if (!$this->checkPermission('EDIT', $forum->getResourceNode())) {
            if (Forum::VALIDATE_PRIOR_ALL === $forum->getValidationMode()) {
                $subject->setModerated(Forum::VALIDATE_PRIOR_ALL);
                if ($first) {
                    $first->setModerated(Forum::VALIDATE_PRIOR_ALL);
                }
            }

            if (Forum::VALIDATE_PRIOR_ONCE === $forum->getValidationMode()) {
                $subject->setModerated($user->getAccess() ? Forum::VALIDATE_NONE : Forum::VALIDATE_PRIOR_ONCE);
                if ($first) {
                    $first->setModerated(Forum::VALIDATE_PRIOR_ALL);
                }
            }
        } else {
            $subject->setModerated(Forum::VALIDATE_NONE);
            if ($first) {
                $first->setModerated(Forum::VALIDATE_PRIOR_ALL);
            }
        }

        if ($first) {
            $this->om->persist($first);
        }

        return $subject;
    }
1354638
def user_field_create(self, data, **kwargs):
        ""
        api_path = "/api/v2/user_fields.json"
        return self.call(api_path, method="POST", data=data, **kwargs)
1023359
public function attach(ObserverInterface $observer): void
    {
        $key = spl_object_hash($observer);

        if ( array_key_exists($key, $this->observers) ) {
            throw new ObservatoryException(
                'Provided observer already known, hash: '.$key
            );
        }

        $this->observers[$key] = $observer;
    }