Skip to content
Snippets Groups Projects

Issue #3223811: Support migrate content with its translations

All threads resolved!
All threads resolved!
Compare and
5 files
+ 258
13
Compare changes
  • Side-by-side
  • Inline
Files
5
<?php
namespace Drupal\migrate_drupal_d8_definition_export\Commands;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drush\Commands\DrushCommands;
use Drupal\field\Entity\FieldConfig;
use Drush\Drush;
/**
* Export definitions.
*
* For example translatable fields.
*/
class MigrateDrupalD8DefinitionExportCommands extends DrushCommands {
/**
* Entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
private $entityFieldManager;
/**
* Construct.
*
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* Entity field manager.
*/
public function __construct(EntityFieldManagerInterface $entity_field_manager) {
$this->entityFieldManager = $entity_field_manager;
}
/**
* Export field definitions.
*
* @param array $options
* An associative array of options.
*
* @option entity_type
* Entity type.
* @option bundle
* Bundle.
* @option properties
* A list of properties.
*
* @command d8_definition:export
* @aliases d8-d:export
* @usage drush d8-d:export --entity_type=node --bundle=product --properties=translatable > /tmp/test.json
* Export the property translatable from node of type product
* to the file test.json.
*/
public function export(array $options = [
'entity_type' => '',
'bundle' => '',
'properties' => '',
]) {
$definition = $this->entityFieldManager->getFieldDefinitions($options['entity_type'], $options['bundle']);
$extract_properties_list = explode(',', $options['properties']);
$properties = [];
$fields = array_keys($definition);
foreach ($fields as $field) {
foreach ($extract_properties_list as $property) {
if ($definition[$field] instanceof FieldConfig) {
$properties[$field][$property] = $definition[$field]->get($property);
}
}
}
Drush::output()->write(dt(json_encode($properties, JSON_PRETTY_PRINT)));
}
}
Loading