/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var RelationConfigContext $context */ $config = $context->getResult(); if (null !== $config && ConfigUtil::isRelationInitialized($config)) { // a config already exists return; } $entityClass = $context->getClassName(); if (!$this->doctrineHelper->isManageableEntityClass($entityClass)) { // only manageable entities are supported return; } if (null === $config) { $config = []; } $targetIdFields = $this->doctrineHelper->getEntityIdentifierFieldNamesForClass($entityClass); if (!isset($config[ConfigUtil::EXCLUSION_POLICY])) { $config[ConfigUtil::EXCLUSION_POLICY] = ConfigUtil::EXCLUSION_POLICY_ALL; } $config[ConfigUtil::FIELDS] = count($targetIdFields) === 1 ? reset($targetIdFields) : array_fill_keys($targetIdFields, null); $context->setResult($config); }
/** * @param $fieldName * @param $definition * * @return bool|string */ protected function isAssociationCompletionRequired($fieldName, $definition) { if (!array_key_exists($fieldName, $definition)) { return true; } if (!is_array($definition[$fieldName])) { return false; } if (isset($definition[$fieldName][ConfigUtil::DEFINITION])) { if (null === $definition[$fieldName][ConfigUtil::DEFINITION]) { return true; } if (is_array($definition[$fieldName][ConfigUtil::DEFINITION])) { return false === ConfigUtil::isRelationInitialized($definition[$fieldName][ConfigUtil::DEFINITION]); } } return false === ConfigUtil::isRelationInitialized($definition[$fieldName]); }