Get included resources.

@param \Tobscure\JsonApi\ElementInterface $element
@param bool $includeParent

@return \Tobscure\JsonApi\Resource[]
193399
protected function getIncluded(ElementInterface $element, $includeParent = false)
    {
        $included = [];

        foreach ($element->getResources() as $resource) {
            if ($resource->isIdentifier()) {
                continue;
            }

            if ($includeParent) {
                $included = $this->mergeResource($included, $resource);
            } else {
                $type = $resource->getType();
                $id = $resource->getId();
            }

            foreach ($resource->getUnfilteredRelationships() as $relationship) {
                $includedElement = $relationship->getData();

                if (! $includedElement instanceof ElementInterface) {
                    continue;
                }

                foreach ($this->getIncluded($includedElement, true) as $child) {
                    // If this resource is the same as the top-level "data"
                    // resource, then we don't want it to show up again in the
                    // "included" array.
                    if (! $includeParent && $child->getType() === $type && $child->getId() === $id) {
                        continue;
                    }

                    $included = $this->mergeResource($included, $child);
                }
            }
        }

        $flattened = [];

        array_walk_recursive($included, function ($a) use (&$flattened) {
            $flattened[] = $a;
        });

        return $flattened;
    }
860236
public function getElements()
    {
        // Get dependencies
        $toolbox = $this->container->toolbox;
        $json = $this->container->json;

        if (isset($this->elementOptions)) {
            return $this->elementOptions;
        }

        // Get all JSON files in directory
        $jsonPath = ROOT_DIR . "structure/definitions/elements/";
        $elements = [];

        foreach ($toolbox->getDirectoryFiles($jsonPath) as $key => $file) {
            if (null === $definition = $json->getJson($jsonPath . $file['filename'], 'element')) {
                throw new Exception('Element JSON definition error: ' . print_r($json->getErrorMessages(), true));
            } else {
                $definition->filename = $file['filename'];
                $elements[] = $definition;
            }
        }

        return $this->elementOptions = $elements;
    }
951206
private function includeResourceIfAvailable(
        Scope $scope,
        $data,
        $includedData,
        $include
    ) {
        if ($resource = $this->callIncludeMethod($scope, $include, $data)) {
            $childScope = $scope->embedChildScope($include, $resource);

            if ($childScope->getResource() instanceof Primitive) {
                $includedData[$include] = $childScope->transformPrimitiveResource();
            } else {
                $includedData[$include] = $childScope->toArray();
            }
        }

        return $includedData;
    }
529296
public function getAncestors(ConfigurationInterface $configuration, $included = false)
    {
        $ancestors = [];

        if ($included) {
            $ancestors[$configuration->getResourceName()] = $configuration;
        }

        while (null !== $configuration->getParentId()) {
            $configuration = $this->findConfiguration($configuration->getParentId());
            $ancestors[$configuration->getResourceName()] = $configuration;
        }

        return array_reverse($ancestors);
    }
419627
protected function _includeResource(ModelEntityInterface $entity)
    {
        $cache  = $entity->getIdentifier()->name.'-'.$entity->getHandle();

        if (!isset($this->_included_resources[$cache])) {
            $this->_included_resources[$cache] = $this->_createResource($entity, array('relationships' => false));
        }

        $resource = $this->_included_resources[$cache];

        return array(
            'data' => array(
                'type' => $resource['type'],
                'id'   => $resource['id']
            )
        );
    }
82828
private Map<String, Object> getIncludedResources(JsonNode parent)
			throws IOException, IllegalAccessException, InstantiationException {
		Map<String, Object> result = new HashMap<>();

		if (parent.has(INCLUDED)) {
			for (JsonNode jsonNode : parent.get(INCLUDED)) {
				String type = jsonNode.get(TYPE).asText();

				Class<?> clazz = configuration.getTypeClass(type);

				if (clazz != null) {
					Object object = readObject(jsonNode, clazz, false);
					if (object != null) {
						result.put(createIdentifier(jsonNode), object);
					}
				} else if (!deserializationFeatures.contains(DeserializationFeature.ALLOW_UNKNOWN_INCLUSIONS)) {
					throw new IllegalArgumentException("Included section contains unknown resource type: " + type);
				}
			}
		}

		return result;
	}
1235594
public function getParent($parentId)
    {
        if ($parentId && isset($this->site->pages[$parentId])) {
            return $this->site->pages[$parentId];
        }

        return [];
    }
320527
public function getRelatedEntries(ElementInterface $element, Section $section, string $field): array
    {
        $query = Entry::find();

        $query->section = $section;
        $query->limit = null;
        $query->status = null;
        $query->enabledForSite = null;
        $query->relatedTo = [
            'targetElement' => $element,
            'field' => $field,
        ];

        return $query->all();
    }
39499
protected function renderElement(ElementInterface $element)
    {
        $collection = $this->getAttributesCollection($element);

        $this->addElementChildren($element, $collection);
        $this->addElementDependencies($element, $collection);
        $this->addElementRules($element, $collection);

        return $this->formatter->formatAttributesCollection($collection);
    }
1268100
private function getAttributes(\SimpleXMLElement $resource, string $elementName, bool $topLevel = false): array
    {
        $attributes = [];
        foreach ($resource->{$elementName} as $attribute) {
            $value = isset($attribute->attribute[0]) ? $this->getAttributes($attribute, 'attribute') : XmlUtils::phpize($attribute);
            // allow empty operations definition, like <collectionOperation name="post" />
            if ($topLevel && '' === $value) {
                $value = [];
            }
            if (isset($attribute['name'])) {
                $attributes[(string) $attribute['name']] = $value;
            } else {
                $attributes[] = $value;
            }
        }

        return $attributes;
    }
1216200
public function findByInterface(string $interface, $include_disabled = false, $sort = false): Collection
    {
        $modules = $this->all($include_disabled)
            ->filter($this->interfaceFilter($interface));

        switch ($interface) {
            case ModuleFooterInterface::class:
                return $modules->sort($this->footerSorter());

            case ModuleMenuInterface::class:
                return $modules->sort($this->menuSorter());

            case ModuleSidebarInterface::class:
                return $modules->sort($this->sidebarSorter());

            case ModuleTabInterface::class:
                return $modules->sort($this->tabSorter());

            default:
                if ($sort) {
                    return $modules->sort($this->moduleSorter());
                }

                return $modules;
        }
    }
1340503
public function getAllChildren($includeSelf = false)
    {
        return call_user_func("$this->ownerClassName::find")
            ->where([
                $this->primaryKey => $this->getChildrenId($includeSelf),
            ])
            ->orderBy("$this->parentIdField ASC, $this->sortField ASC, $this->primaryKey ASC");
    }
854264
public function findAllPlatformRoles($includeRoleUser = true, $getBuilder = false)
    {
        $queryBuilder = $this
            ->createQueryBuilder('role')
            ->andWhere('role.type = :roleType')
            ->setParameter('roleType', Role::PLATFORM_ROLE);
        $queryBuilder->andWhere($queryBuilder->expr()->not($queryBuilder->expr()->eq('role.name', '?1')))
            ->setParameter(1, 'ROLE_ANONYMOUS');

        if (!$includeRoleUser) {
            $queryBuilder->andWhere($queryBuilder->expr()->not($queryBuilder->expr()->eq('role.name', '?2')))
                ->setParameter(2, 'ROLE_USER');
        }

        if ($getBuilder) {
            return $queryBuilder;
        }

        $query = $queryBuilder->getQuery();

        return $query->getResult();
    }
1285660
public function add(ElementInterface $element)
    {
        if ($element instanceof File) {
            $this->setAttribute('enctype', 'multipart/form-data');
        }
        return parent::add($element);
    }
9364
protected function getElementData(
        ContainerInterface $container, &$data = []
    ) {
         foreach ($container as $element) {
             if ($element instanceof InputInterface) {
                 $data[$element->getName()] = $element->getValue();
                 continue;
             }

             if ($element instanceof ContainerInterface) {
                 $this->getElementData($element, $data);
                 continue;
             }
        }
    }
637675
public function toArray(bool $withParentAndChild = true): array
    {
        $array = [
            'name'                  => $this->getName(),
            'shortName'             => $this->getShortName(),
            'configurationRootName' => $this->getConfigurationRootName(),
            'rootNamespace'         => $this->getRootNamespace(),
            'path'                  => $this->getPath(),
            'dataFixtures'          => $this->getDataFixtures()->toArray(),
        ];

        if ($withParentAndChild) {
            if (null !== $this->getParentBundleDescriptor()) {
                $array['parentBundleDescriptor'] = $this->getParentBundleDescriptor()->toArray(false);
            }

            if (null !== $this->getChildBundleDescriptor()) {
                $array['childBundleDescriptor'] = $this->getChildBundleDescriptor()->toArray(false);
            }
        }

        return $array;
    }
442061
public static function getChildElements($element, $withText = false)
    {
        $children = $element->childNodes;
        $returnValue = array();
        
        for ($i = 0; $i < $children->length; $i++) {
            if ($children->item($i)->nodeType === XML_ELEMENT_NODE || ($withText === true && ($children->item($i)->nodeType === XML_TEXT_NODE || $children->item($i)->nodeType === XML_CDATA_SECTION_NODE))) {
                $returnValue[] = $children->item($i);
            }
        }
        
        return $returnValue;
    }