You are here

function __defaultcontent_import_one in Default Content 8

import any nodes found in this module's config

File

./defaultcontent.module, line 41

Code

function __defaultcontent_import_one($config) {
  $node = Node::Create([
    'type' => $config
      ->get('type'),
  ])
    ->setCreatedTime($config
    ->get('created'))
    ->setOwnerId($config
    ->get('created'))
    ->setRevisionCreationTime($config
    ->get('created'))
    ->setPromoted($config
    ->get('promote'))
    ->setPublished($config
    ->get('status'))
    ->setSticky($config
    ->get('sticky'))
    ->set('title', $config
    ->get('title'))
    ->set('langcode', $config
    ->get('langcode'))
    ->set('path', $config
    ->get('alias'));
  foreach ($config
    ->get('fields') as $field_name => $field_contents) {
    $node
      ->set($field_name, $field_contents);
  }
  $node
    ->save();
  if ($menu_link = $config
    ->get('menu_link')) {
    $props = $menu_link + [
      'link' => [
        'uri' => 'entity:node/' . $node
          ->id(),
      ],
    ];
    MenuLinkContent::create($props)
      ->save();
  }
  $config
    ->delete();
}