Set custom composite discriminator key based on multiple parameter fields
before deserialization to ensure proper discrimination mapping

@param PreDeserializeEvent $event
765914
public function onParameterPreDeserialize(PreDeserializeEvent $event)
    {
        $data = $event->getData();

        if (array_key_exists('$ref', $data)) {
            $event->setType(RefParameter::class);
            return;
        }

        $data['class'] = $data['in'];

        if (array_key_exists('type', $data)) {
            $data['class'] = sprintf('%s.%s', $data['in'], $data['type']);
        }

        $event->setData($data);
    }
892607
protected function preLoadEmbeddedWithDiscriminator(PreLoadEventArgs $eventArgs, $field, $mapping)
    {
        $unhydratedDoc = $eventArgs->getData();

        if (isset($unhydratedDoc[$field])) {
            $documentManager = $eventArgs->getDocumentManager();
            $eventManager = $documentManager->getEventManager();

            if ($mapping['type'] === 'one') {
                $discriminatorFieldValue = $unhydratedDoc[$field][$mapping['discriminatorField']];
                $embeddedClassName = $mapping['discriminatorMap'][$discriminatorFieldValue];
                $targetMetadata = $documentManager->getClassMetadata($embeddedClassName);
                $readEventArgs = $this->getReadEventArgs($targetMetadata, $eventManager);

                if ($readEventArgs->getReject()) {
                    $eventArgs->getData()[$field] = null;
                }
            } else {
                $unhydratedEmbeddedDoc = $unhydratedDoc[$field];
                foreach ($unhydratedEmbeddedDoc as $i => $embeddedDoc) {
                    $discriminatorFieldValue = $embeddedDoc[$mapping['discriminatorField']];
                    $embeddedClassName = $mapping['discriminatorMap'][$discriminatorFieldValue];
                    $targetMetadata = $documentManager->getClassMetadata($embeddedClassName);

                    $readEventArgs = $this->getReadEventArgs($targetMetadata, $eventManager);

                    if ($readEventArgs->getReject()) {
                        $eventArgs->getData()[$field][$i] = null;
                    }
                }
            }
        }
    }
793205
public function canTrigger(Event $event)
    {
        $class = get_class($event->getSubject());
        if (!isset($this->_options['allowedSubject'])) {
            throw new RuntimeException(self::class . ' Missing subject filter options!');
        }
        if (is_string($this->_options['allowedSubject'])) {
            $this->_options['allowedSubject'] = [$this->_options['allowedSubject']];
        }

        return in_array($class, $this->_options['allowedSubject']);
    }
1041752
public function handlePreIndex(PreIndexEvent $event)
    {
        $metadata = $event->getMetadata();
        $reflection = $metadata->getClassMetadata()->reflection;

        if (
            false === $reflection->isSubclassOf(FileVersionMeta::class)
            && FileVersionMeta::class !== $metadata->getName()) {
            return;
        }

        $document = $event->getDocument();
        $subject = $event->getSubject();
        $locale = $subject->getLocale();

        $fileVersion = $subject->getFileVersion();
        $file = $fileVersion->getFile();
        $media = $file->getMedia();

        // Do not try and get the image URL if the mime type is not in the
        // list of mime types for which thumbnails are generated.
        foreach ($this->thumbnailMimeTypes as $type) {
            if (fnmatch($type, $fileVersion->getMimeType())) {
                $document->setImageUrl($this->getImageUrl($media, $locale));
                break;
            }
        }

        $document->addField($this->factory->createField(
            'media_id',
            $media->getId()
        ));

        $document->addField($this->factory->createField(
            'media_mime',
            $fileVersion->getMimeType()
        ));

        if ($collection = $media->getCollection()) {
            $document->addField($this->factory->createField(
                'collection_id',
                $collection->getId()
            ));
        }
    }
886760
public function onObjectTag(GenericDatasEvent $event)
    {
        $taggedObject = null;
        $datas = $event->getDatas();

        if (is_array($datas) && isset($datas['tag']) && isset($datas['object'])) {
            $user = isset($datas['user']) ? $datas['user'] : null;
            $taggedObject = $this->tagManager->tagObject($datas['tag'], $datas['object'], $user);
        }
        $event->setResponse($taggedObject);
    }
509002
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options) {
		$formField = $this->_config['formField'];
		$field = $this->_config['field'];

		$PasswordHasher = $this->_getPasswordHasher($this->_config['passwordHasher']);

		if ($entity->get($formField) !== null) {
			$entity->set($field, $PasswordHasher->hash($entity->get($formField)));

			if (!$entity->get($field)) {
				throw new RuntimeException('Empty field');
			}

			$entity->unsetProperty($formField);
			//$entity->set($formField, null);

			if ($this->_config['confirm']) {
				$formFieldRepeat = $this->_config['formFieldRepeat'];
				$entity->unsetProperty($formFieldRepeat);
			}
			if ($this->_config['current']) {
				$formFieldCurrent = $this->_config['formFieldCurrent'];
				$entity->unsetProperty($formFieldCurrent);
			}
		} else {
			// To help mitigate timing-based user enumeration attacks.
			$PasswordHasher->hash('');
		}
	}
458927
public function keyChanged(PersistenceEvent $event) {
    $object = $event->getObject();
    if ($object->getType() == $this->entityType) {
      $cache = ObjectFactory::getInstance('dynamicCache');
      $cache->clear($this->getId());
    }
  }
231281
public function handleUuid(AbstractMappingEvent $event)
    {
        $document = $event->getDocument();

        if (!$document instanceof UuidBehavior) {
            return;
        }

        $node = $event->getNode();

        $accessor = $event->getAccessor();
        $accessor->set(
            'uuid',
            $node->getIdentifier()
        );
    }
1280368
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options)
    {
        if (isset($data['id'])) {
            // Unset password and password confirmation if password is empty when editing a user.
            if (isset($data['password']) && empty($data['password'])) {
                unset($data['password']);

                if (isset($data['password_confirmation'])) {
                    unset($data['password_confirmation']);
                }
            }
        }
    }
286927
public function onGroupsDelete(GenericDatasEvent $event)
    {
        $groups = $event->getDatas();
        $ids = array();

        foreach ($groups as $group) {
            $ids[] = $group->getId();
        }
        $this->tagManager->removeTaggedObjectsByClassAndIds(
            'Claroline\CoreBundle\Entity\Group',
            $ids
        );
    }
1100164
private function setNodeName(AbstractMappingEvent $event)
    {
        $document = $event->getDocument();

        if (!$document instanceof NodeNameBehavior) {
            return;
        }

        $node = $event->getNode();
        $accessor = $event->getAccessor();
        $accessor->set(
            'nodeName',
            $node->getName()
        );
    }
667180
public function onPostDeserialize(ObjectEvent $event)
    {
        /** @var TargetGroupRuleInterface $targetGroupRule */
        $targetGroupRule = $event->getObject();

        if (!$targetGroupRule instanceof TargetGroupRuleInterface) {
            return;
        }

        if ($targetGroupRule->getConditions()) {
            foreach ($targetGroupRule->getConditions() as $condition) {
                $condition->setRule($targetGroupRule);
            }
        }
    }
675612
public function setDiscriminatorDefaultValue($discriminatorDefaultValue)
    {
        if ($discriminatorDefaultValue !== null && !array_key_exists($discriminatorDefaultValue, $this->discriminatorMap)) {
            throw MappingException::invalidDiscriminatorValue($discriminatorDefaultValue, $this->name);
        }

        $this->discriminatorDefaultValue = $discriminatorDefaultValue;
    }
632599
protected function _identifierFilter(Event $event) {
		if (is_array($this->_config['identifiers'])) {
			$identifier = $event->getData('entity.model');
			if (!in_array($identifier, $this->_config['identifiers'])) {
				return false;
			}
		}

		return true;
	}
1240346
public function beforeFind(Event $event)
    {
        $related = $this->_getRelatedModels();
        if ($related === []) {
            $this->associations = [];
        } else {
            $this->associations = $this->_associations(array_keys($related));
        }

        if (!$event->getSubject()->query->getContain()) {
            $event->getSubject()->query->contain($related);
        }
    }
138822
public function onSchemaPreDeserialize(PreDeserializeEvent $event)
    {
        $data = $event->getData();

        if (array_key_exists('type', $data) && is_array($data['type'])) {
            $event->setType(MultiSchema::class);
        }

        if (array_key_exists('$ref', $data)) {
            $event->setType(RefSchema::class);
        }
    }
322380
public function handleDecodePropertyValueForWidgetEvent(DecodePropertyValueForWidgetEvent $event)
    {
        $attribute = $this->getSupportedAttribute($event);
        if (!$attribute) {
            return;
        }

        $dispatcher = $event->getEnvironment()->getEventDispatcher();
        $value      = $event->getValue();

        if (\is_numeric($value)) {
            $dateEvent = new ParseDateEvent($value, $attribute->getDateTimeFormatString());
            $dispatcher->dispatch(ContaoEvents::DATE_PARSE, $dateEvent);

            $event->setValue($dateEvent->getResult());
        }
    }