View source
<?php
namespace Drupal\fieldable_panels_panes\Plugin\migrate\source\d7;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FieldablePanelsPane extends FieldableEntity {
protected $moduleHandler;
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_type_manager);
$this->moduleHandler = $module_handler;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $migration, $container
->get('state'), $container
->get('entity_type.manager'), $container
->get('module_handler'));
}
const JOIN = 'fpp.vid = fppr.vid';
public function query() {
$query = $this
->select('fieldable_panels_panes_revision', 'fppr')
->fields('fpp', [
'fpid',
'bundle',
'link',
'path',
'admin_title',
'admin_description',
'category',
'reusable',
'view_access',
'edit_access',
'language',
'created',
'changed',
])
->fields('fppr', [
'vid',
'title',
'log',
'timestamp',
]);
$query
->addField('fppr', 'uid', 'entity_uid');
$query
->addField('fppr', 'uid', 'revision_uid');
$query
->innerJoin('fieldable_panels_panes', 'fpp', static::JOIN);
if (isset($this->configuration['bundle'])) {
$query
->condition('fpp.bundle', $this->configuration['bundle']);
}
return $query;
}
public function prepareRow(Row $row) {
$fpid = $row
->getSourceProperty('fpid');
$vid = $row
->getSourceProperty('vid');
$bundle = $row
->getSourceProperty('bundle');
$entity_translatable = $this
->isEntityTranslatable('fieldable_panels_pane');
$source_language = $this
->getEntityTranslationSourceLanguage('fieldable_panels_pane', $fpid);
$language = $entity_translatable && $source_language ? $source_language : $row
->getSourceProperty('language');
foreach ($this
->getFields('fieldable_panels_pane', $bundle) as $field_name => $field) {
$field_language = $entity_translatable && $field['translatable'] ? $language : NULL;
$row
->setSourceProperty($field_name, $this
->getFieldValues('fieldable_panels_pane', $field_name, $fpid, $vid, $field_language));
}
if ($this
->moduleExists('title')) {
$title_field = $row
->getSourceProperty('title_field');
if (isset($title_field[0]['value'])) {
$row
->setSourceProperty('title', $title_field[0]['value']);
}
}
return parent::prepareRow($row);
}
public function fields() {
$fields = [
'fpid' => $this
->t('Fieldable Panel Pane ID'),
'bundle' => $this
->t('Bundle'),
'title' => $this
->t('Title'),
'entity_uid' => $this
->t('Panel pane authored by (uid)'),
'revision_uid' => $this
->t('Revision authored by (uid)'),
'admin_title' => $this
->t('Administrative title for panel pane'),
'admin_description' => $this
->t('Administrative description for panel pane'),
'category' => $this
->t('Panel pane category'),
'reusable' => $this
->t('Whether the panel pane is reusable'),
'created' => $this
->t('Created timestamp'),
'changed' => $this
->t('Modified timestamp'),
'revision' => $this
->t('Create new revision'),
'language' => $this
->t('Language (fr, en, ...)'),
'timestamp' => $this
->t('The timestamp the latest revision of this panel pane was created.'),
];
return $fields;
}
public function getIds() {
$ids['fpid']['type'] = 'integer';
$ids['fpid']['alias'] = 'fpp';
return $ids;
}
}