function DefaultContentManager::getFilesInOrder in Default Content 8
1 call to DefaultContentManager::getFilesInOrder()
- DefaultContentManager::importContent in src/DefaultContentManager.php
- Imports default content for a given module.
File
- src/DefaultContentManager.php, line 305
- Contains \Drupal\defaultcontent\DefaultContentManager.
@todo remove all references to linkmanager?
Class
- DefaultContentManager
- A service for handling import of default content.
@todo throw useful exceptions
Namespace
Drupal\defaultcontent
Code
function getFilesInOrder($folder) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type_id == 'menu_link_content') {
continue;
}
$reflection = new \ReflectionClass($entity_type
->getClass());
if ($reflection
->implementsInterface('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) {
continue;
}
if (!file_exists($folder . '/' . $entity_type_id)) {
continue;
}
$files = $this
->scanner()
->scan($folder . '/' . $entity_type_id, 'json');
foreach ($files as $file) {
$contents = $this
->parseFile($file);
$decoded = $this->serializer
->decode($contents, 'hal_json');
$self = $decoded['_links']['self']['href'];
if (isset($this->file_map[$self])) {
$args = array(
'@href' => $self,
'@first' => $this->file_map[$self]->uri,
'@second' => $file->uri,
);
throw new \Exception(t('Default content with href @href exists twice: @first @second', $args));
}
$file->entity_type_id = $entity_type_id;
$this->file_map[$self] = $file;
$vertex = $this
->getVertex($self);
$this->graph[$vertex->link]['edges'] = [];
if (empty($decoded['_embedded'])) {
continue;
}
foreach ($decoded['_embedded'] as $embedded) {
foreach ($embedded as $item) {
$edge = $this
->getVertex($item['_links']['self']['href']);
$this->graph[$vertex->link]['edges'][$edge->link] = TRUE;
}
}
}
}
return $this
->sortTree($this->graph);
}