ParagraphsType.php in Paragraphs 8
File
src/Plugin/migrate/source/d7/ParagraphsType.php
View source
<?php
namespace Drupal\paragraphs\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\paragraphs\Plugin\migrate\source\DrupalSqlBase;
class ParagraphsType extends DrupalSqlBase {
public function defaultConfiguration() {
return [
'add_description' => FALSE,
] + parent::defaultConfiguration();
}
public function query() {
$query = $this
->select('paragraphs_bundle', 'pb')
->fields('pb');
return $query;
}
public function prepareRow(Row $row) {
if ($this->configuration['add_description']) {
$name = $row
->getSourceProperty('name');
$row
->setSourceProperty('description', 'Migrated from paragraph bundle ' . $name);
}
else {
$row
->setSourceProperty('description', '');
}
return parent::prepareRow($row);
}
public function fields() {
return [
'bundle' => $this
->t('Paragraph type machine name'),
'name' => $this
->t('Paragraph type label'),
'description' => $this
->t('Paragraph type description'),
];
}
public function getIds() {
$ids['bundle']['type'] = 'string';
return $ids;
}
public function setConfiguration(array $configuration) {
if (isset($configuration['addDescription'])) {
@trigger_error("addDescription configuration key is deprecated in 8.x-1.0 and will be removed prior to 9.x. Use add_description instead. See https://www.drupal.org/project/paragraphs/issues/2911242", E_USER_DEPRECATED);
if (!isset($configuration['add_description'])) {
$configuration['add_description'] = $configuration['addDescription'];
}
unset($configuration['addDescription']);
}
parent::setConfiguration($configuration);
}
}