FieldGroup.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @file
  4. * Contains \Drupal\field_group_migrate\Plugin\migrate\source\d7\FieldGroup.
  5. */
  6. namespace Drupal\field_group_migrate\Plugin\migrate\source\d7;
  7. use Drupal\migrate\Row;
  8. use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
  9. /**
  10. * Drupal 7 field_group source.
  11. *
  12. * @MigrateSource(
  13. * id = "d7_field_group"
  14. * )
  15. */
  16. class FieldGroup extends DrupalSqlBase {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function query() {
  21. return $this->select('field_group', 'f')->fields('f');
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function prepareRow(Row $row) {
  27. $data = unserialize($row->getSourceProperty('data'));
  28. $format_settings = $data['format_settings'] + $data['format_settings']['instance_settings'];
  29. unset($format_settings['instance_settings']);
  30. $settings = array(
  31. 'children' => $data['children'],
  32. 'parent_name' => $row->getSourceProperty('parent_name'),
  33. 'weight' => $data['weight'],
  34. 'label' => $data['label'],
  35. 'format_settings' => $format_settings,
  36. 'format_type' => $data['format_type'],
  37. );
  38. switch ($data['format_type']) {
  39. case 'div':
  40. $settings['format_type'] = 'html_element';
  41. $settings['format_settings']['element'] = 'div';
  42. break;
  43. case 'tabs':
  44. $settings['format_type'] = 'tabs';
  45. $settings['format_settings']['direction'] = 'vertical';
  46. break;
  47. case 'htabs':
  48. $settings['format_type'] = 'tabs';
  49. $settings['format_settings']['direction'] = 'horizontal';
  50. break;
  51. case 'htab':
  52. $settings['format_type'] = 'tab';
  53. break;
  54. case 'multipage-group':
  55. // @todo Check if there is a better way to deal with this format type.
  56. $settings['format_type'] = 'tabs';
  57. break;
  58. case 'multipage':
  59. // @todo Check if there is a better way to deal with this format type.
  60. $settings['format_type'] = 'tab';
  61. break;
  62. }
  63. $row->setSourceProperty('settings', $settings);
  64. return parent::prepareRow($row);
  65. }
  66. /**
  67. * {@inheritdoc}
  68. */
  69. public function getIds() {
  70. $ids['id']['type'] = 'integer';
  71. return $ids;
  72. }
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public function fields() {
  77. $fields = array(
  78. 'id' => $this->t('ID'),
  79. 'identifier' => $this->t('Identifier'),
  80. 'group_name' => $this->t('Group name'),
  81. 'entity_type' => $this->t('Entity type'),
  82. 'bundle' => $this->t('Bundle'),
  83. 'mode' => $this->t('View mode'),
  84. 'parent_name' => $this->t('Parent name'),
  85. 'data' => $this->t('Data'),
  86. );
  87. return $fields;
  88. }
  89. }