Commit 4edba9e5 authored by Aleksey.Alekseev's avatar Aleksey.Alekseev
Browse files

add path alias import

parent 3f1ce308
......@@ -3,12 +3,11 @@
namespace Drupal\synhelper\Drush;
use Drush\Commands\DrushCommands;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Url;
use Drupal\media\Entity\Media;
use Drupal\pathauto\PathautoState;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\File\FileSystemInterface;
use Drupal\menu_link_content\Entity\MenuLinkContent;
/**
* A Drush commandfile.
......@@ -224,12 +223,18 @@ class DrushContentImport extends DrushCommands {
*/
private function importContacts($data) {
$path = \Drupal::service('path_alias.manager')->getPathByAlias('/contacts');
if ($path == '/contacts') {
$path = \Drupal::service('path_alias.manager')->getPathByAlias('/kontakty');
}
$params = Url::fromUri("internal:" . $path)->getRouteParameters();
$entity_type = key($params);
$node = \Drupal::entityTypeManager()->getStorage($entity_type)->load($params[$entity_type]);
$node->body->format = $data['body']['format'];
$node->body->value = $data['body']['value'];
$node->path = [
'alias' => $data['path'],
'pathauto' => PathautoState::SKIP,
];
$node->save();
}
......@@ -265,13 +270,18 @@ class DrushContentImport extends DrushCommands {
$n[$key] = $value;
break;
}
}
$node = $storage->create($n);
if (!empty($data['field_image_big'])) {
$node->set('field_image_big', $this->importMedia($data['field_image_big']));
}
if (!empty($data['path'])) {
$node->path = [
'alias' => $data['path'],
'pathauto' => PathautoState::SKIP,
];
}
$node->save();
if (array_key_exists('is_front', $data) && $data['is_front'] == TRUE) {
$id = $node->id();
......@@ -433,4 +443,4 @@ class DrushContentImport extends DrushCommands {
return !empty($term) ? $term->id() : 0;
}
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment