
| Current Path : /var/www/html/vendor/chi-teck/drupal-code-generator/templates/plugin/migrate/source/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/vendor/chi-teck/drupal-code-generator/templates/plugin/migrate/source/source.twig |
<?php
namespace Drupal\{{ machine_name }}\Plugin\migrate\source;
use Drupal\migrate\Plugin\migrate\source\{{ base_class }};
use Drupal\migrate\Row;
/**
* The '{{ plugin_id }}' source plugin.
*
* @MigrateSource(
* id = "{{ plugin_id }}",
* source_module = "{{ machine_name }}"
* )
*/
class {{ class }} extends {{ base_class }} {
{% if source_type == 'sql' %}
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('example', 'e')
->fields('e', ['id', 'name', 'status']);
return $query;
}
{% else %}
/**
* {@inheritdoc}
*/
public function __toString() {
// @DCG You may return something meaningful here.
return '';
}
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
// @DCG
// In this example we return a hardcoded set of records.
//
// For large sets of data consider using generators like follows:
// @code
// foreach ($foo->nextRecord() as $record) {
// yield $record;
// }
// @endcode
$records = [
[
'id' => 1,
'name' => 'Alpha',
'status' => TRUE,
],
[
'id' => 2,
'name' => 'Beta',
'status' => FALSE,
],
[
'id' => 3,
'name' => 'Gamma',
'status' => TRUE,
],
];
return new \ArrayIterator($records);
}
{% endif %}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'id' => $this->t('The record ID.'),
'name' => $this->t('The record name.'),
'status' => $this->t('The record status'),
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['id'] = [
'type' => 'integer',
'unsigned' => TRUE,
'size' => 'big',
];
return $ids;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// @DCG
// Extend/modify the row here if needed.
//
// Example:
// @code
// $name = $row->getSourceProperty('name');
// $row->setSourceProperty('name', Html::escape('$name');
// @endcode
return parent::prepareRow($row);
}
}