Filters the params down to just the instance parents

@param \stdClass $params
@param ApiInterface $entity

@return \stdClass[]
@throws Exception
15226
private function filterParents(\stdClass $params, ApiInterface $entity) {
        $parents = array();
        foreach($params as $key => $value) {
            if(is_object($value) && get_class($value) == 'stdClass') {
                $alias = ucfirst($key);
                if(in_array($alias, $entity->getParentRelationships())) {
                    $parents[$alias] = $value;
                } else {
                    throw new Exception('Could not find the parent field: ' . $key, 400);
                }
            }
        }
        return $parents;
    }
1267630
private function showParentsAndChildren(\stdClass $output, ApiInterface $entity, Field $field) {
        if(in_array($field->getAlias(), $entity->getParentRelationships())) {

            /** @var ApiInterface $parentEntity */
            $parentEntity = $entity->getRelated($field->getAlias());
            if($parentEntity === false) {//AKA, a nullable vendor
                $output->{$field->getAlias()} = null;
            } else {
                $parentEntities = $entity->getApiParentEntities() ?? [];
                $parentEntities[$entity->getSource()] = $entity;
                $parentEntity->setApiParentEntities($parentEntities);
                $output->{$field->getAlias()} = new \stdClass();
                $this->showRecursive($output->{$field->getAlias()}, $field, $parentEntity);
            }
        } elseif(in_array($field->getAlias(), $entity->getChildrenRelationships())) {
            $output->{$field->getAlias()} = array();
            $resultSet = $entity->getRelated($field->getAlias());
            foreach($resultSet as $key => $currentEntity) {
                $parentEntities = $entity->getApiParentEntities() ?? [];
                $parentEntities[$entity->getSource()] = $entity;
                $currentEntity->setApiParentEntities($parentEntities);

                $subOutput = new \stdClass();
                $output->{$field->getAlias()}[] = $subOutput;
                $this->showRecursive($subOutput, $field, $currentEntity);
            }
        } else {
            throw new Exception('Invalid Field, not on the current object, no child or parent found: ' . $entity->getEntityName() . ' with ' . $field->getAlias(), 400);
        }
    }
492235
private function writeCustomParents($fields, ApiInterface $entity) {
        foreach($entity->getCustomParentRelationships() as $customRelationship) {
            $name = $customRelationship->getReferencedFields();
            if(array_key_exists($name, $fields)) {
                $entity->writeAttribute($name, $fields[$name]);
            }
        }
    }
722926
protected function getDefaultOperations(EntityInterface $entity) {
    $operations = [];
    if ($entity->access('update') && $entity->hasLinkTemplate('edit-form')) {
      $operations['edit'] = [
        'title' => $this->t('Edit'),
        'weight' => 10,
        'url' => $entity->urlInfo('edit-form'),
      ];
    }
    if ($entity->access('delete') && $entity->hasLinkTemplate('delete-form')) {
      $operations['delete'] = [
        'title' => $this->t('Delete'),
        'weight' => 100,
        'url' => $entity->urlInfo('delete-form'),
      ];
    }

    return $operations;
  }
756346
protected function buildConditions(EntityInterface $entity) {
		$conditions = $this->getConfig('scope');
		$scopeFields = (array)$this->getConfig('scopeFields');
		foreach ($scopeFields as $scopeField) {
			$conditions[$scopeField] = $entity->get($scopeField);
		}
		return $conditions;
	}
1199205
public function getFromEntityByIds(string $entityFrom, array $entityIds, array $filterParams = [])
    {
        $uriAppend = "from/{$entityFrom}";
        $params    = ['entityIds' => implode(",", $entityIds)];
        if ($filterParams) {
            $params['params'] = json_encode([$filterParams]);
        }

        $response = $this->handler->handle('GET', false, $uriAppend, $params)->getData();
        if (!$response) {
            return [];
        }

        $functionalNames = [];
        if (isset($filterParams['functionalNames']) && $filterParams['functionalNames']) {
            $functionalNames = $filterParams['functionalNames'];
        }

        return $this->client->elastic()
                            ->search($this->prepareElasticSearchBody($response, ['functionalNameId' => $functionalNames]))
                            ->all();
    }
375435
public function getEntities($id, array $params = array())
    {
        return $this->get($this->path.'/'.rawurlencode($id).'/entities', $params);
    }
216641
public function getAdminForEntity($entity): Admin
    {
        $default = null;
        foreach ($this->adminRegistry->getAdmins() as $admin) {
            if (is_a($entity, $admin->getEntity())) {
                if ($entity instanceof DataInterface) {
                    $default = $default ?: $admin;
                    /** @var array $families */
                    $families = $admin->getOption('families', []);
                    foreach ($families as $family => $config) {
                        if ($entity->getFamilyCode() === $family) {
                            return $admin;
                        }
                    }
                } else {
                    return $admin;
                }
            }
        }

        if ($default) {
            // Or throw exception anyway ?
            return $default;
        }
        $class = \get_class($entity);
        throw new \UnexpectedValueException("No admin matching for entity {$class}");
    }
209575
public function transform($name, $entity, array $params = array()) {
        $transformer = $this->transformers[$name];

        if (!is_object($entity) || !$transformer->isCached()) {
            return $transformer->transform($entity, $params);
        }

        $id = spl_object_hash($entity) . '-' . spl_object_hash($this->groupContext);
        if ($this->arrayCache->contains($id)) {
            return $this->arrayCache->fetch($id);
        }
        $transformation = $transformer->transform($entity, $params);
        $this->arrayCache->save($id, $transformation);

        return $transformation;
    }
112207
protected function getOptions(FieldableEntityInterface $entity) {
    if (!isset($this->options)) {
      // Limit the settable options for the current user account.
      $options = $this->fieldDefinition
        ->getFieldStorageDefinition()
        ->getSetting('allowed_values');

      $module_handler = \Drupal::moduleHandler();
      $context = [
        'fieldDefinition' => $this->fieldDefinition,
        'entity' => $entity,
      ];
      $module_handler->alter('dropdown_list', $options, $context);

      array_walk_recursive($options, [$this, 'sanitizeLabel']);

      $this->options = $options;
    }
    return $this->options;
  }
857409
public function getMethods($entity)
    {
        $reflectionClass = new \ReflectionClass($entity);

        $methods = [];
        foreach ($reflectionClass->getMethods() as $method) {
            /** @var Field $annotation */
            $annotation = $this->reader->getMethodAnnotation($method, self::FIELD_CLASS);

            if ($annotation === null) {
                continue;
            }

            $annotation->value = $method->invoke($entity);
            
            if ($annotation->name == '') {
                throw new SolrMappingException(sprintf('Please configure a field-name for method "%s" with field-annotation in class "%s"', $method->getName(), get_class($entity)));
            }

            $methods[] = $annotation;
        }

        return $methods;
    }
306712
protected function removeEntity(EntityInterface $entity)
    {
        Orm::getRepository($this->getEntityClassName())
            ->getIdentityMap()
            ->remove($entity);
    }
384902
public function getVersions(EntityInterface $entity)
    {
        $primaryKey = (array)$this->_table->getPrimaryKey();

        $query = $this->_table->find('versions');
        $pkValue = $entity->extract($primaryKey);
        $conditions = [];
        foreach ($pkValue as $key => $value) {
            $field = current($query->aliasField($key));
            $conditions[$field] = $value;
        }
        $entities = $query->where($conditions)->all();

        if (empty($entities)) {
            return new Collection([]);
        }

        $entity = $entities->first();

        return $entity->get('_versions');
    }
726548
public function execute($params = array(), $request = array()) {
        //$passableParams = $this->httpRequest->getParameters();
        //remove the uri
        // array_shift($passableParams);

        $this->getQueryBuilder()->where($params);
        $query = '';
        if ($this->entity instanceof AbstractI18nEntity) {
            $query = $this->getQueryBuilder()->getQuery($this->entity, QueryBuilder::GET_ITEM_QUERY, QueryBuilder::PARENT_AND_CHILD);
        } else {
            $query = $this->getQueryBuilder()->getQuery($this->entity, QueryBuilder::GET_ITEM_QUERY);
        }

        $firstResult = $this->query($query);
        $entityName = get_class($this->entity);

        if (is_array($firstResult) && count($firstResult) > 0) {

            $this->loadI18nValues($firstResult, $params);

            $this->loadChildTableParams($firstResult, $params);

            $this->loadOneToOneJoinTables($firstResult);

            $this->loadOneToManyJoinTables($firstResult, $params);


        }

        return array($entityName => is_array($firstResult) ? current($firstResult) : array());
    }
1325076
public function delete($entity, array $options = []) {
		$params = compact('entity', 'options');

		return Filters::run(get_called_class(), __FUNCTION__, $params, function($params) {
			$options = $params + $params['options'] + [
				'model' => get_called_class(),
				'type' => 'delete'
			];
			unset($options['options']);

			$query = static::_instance('query', $options);
			return static::connection()->delete($query, $options);
		});
	}
1355001
public function reverseMap(EntityInterface $entity): array
    {
        /** @var $entity Invoice */
        $services = [];

        foreach ($entity->getServices() as $service) {
            $services[] = [
                'id' => $service->getId(),
                'name' => $service->getName(),
                'tax_symbol' => $service->getTaxSymbol(),
                'unit' => $service->getUnit(),
                'quantity' => $this->reverseMapQuantity($service->getQuantity()),
                'unit_net_price' => $this->reverseMapPrice($service->getUnitNetPrice()),
                'net_price' => $this->reverseMapPrice($service->getNetPrice()),
                'gross_price' => $this->reverseMapPrice($service->getGrossPrice()),
                'tax_price' => $this->reverseMapPrice($service->getTaxPrice()),
                'symbol' => $service->getSymbol(),
                'discount' => $service->getDiscount(),
                'unit_net_price_before_discount' => $this->reverseMapPrice($service->getUnitNetPriceBeforeDiscount()),
            ];
        }

        return [
            'id' => $entity->getId(),
            'number' => $entity->getNumber(),
            'currency' => $entity->getCurrency(),
            'paid_price' => $this->reverseMapPrice($entity->getPaidPrice()),
            'notes' => $entity->getNotes(),
            'kind' => $entity->getKind(),
            'payment_method' => $entity->getPaymentMethod(),
            'recipient_signature' => $entity->getRecipientSignature(),
            'seller_signature' => $entity->getSellerSignature(),
            'invoice_date' => $this->reverseMapDate($entity->getInvoiceDate()),
            'sale_date' => $this->reverseMapDate($entity->getSaleDate()),
            'status' => $entity->getStatus(),
            'payment_date' => $this->reverseMapDate($entity->getPaymentDate()),
            'paid_date' => $this->reverseMapDate($entity->getPaidDate()),
            'net_price' => $this->reverseMapPrice($entity->getNetPrice()),
            'tax_price' => $this->reverseMapPrice($entity->getTaxPrice()),
            'gross_price' => $this->reverseMapPrice($entity->getGrossPrice()),
            'client_id' => $entity->getClientId(),
            'client_company_name' => $entity->getClientCompanyName(),
            'client_street' => $entity->getClientStreet(),
            'client_city' => $entity->getClientCity(),
            'client_post_code' => $entity->getClientPostCode(),
            'client_tax_code' => $entity->getClientTaxCode(),
            'client_country' => $entity->getClientCountry(),
            'bank_name' => $entity->getBankName(),
            'bank_account' => $entity->getBankAccount(),
            'swift' => $entity->getSwift(),
            'vat_exemption_reason' => $entity->getVatExemptionReason(),
            'sale_type' => $entity->getSaleType(),
            'invoice_date_kind' => $entity->getInvoiceDateKind(),
            'services' => $services,
        ];
    }
1181389
public function setParams($params)
    {
        if (is_array($params) && isset($params['application'])) {
            $this->setApplicationEntity($params['application']);
            unset($params['application']);
        } elseif (is_object($params) && isset($params->application)) {
            $this->setApplicationEntity($params->application);
        }

        if (is_array($params) && isset($params['user'])) {
            $this->setUser($params['user']);
            unset($params['user']);
        }

        if (is_array($params) && isset($params['status'])) {
            $this->setStatus($params['status']);
            unset($params['status']);
        }

        return parent::setParams($params);
    }