X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffield%2Fsrc%2FPlugin%2Fmigrate%2Fsource%2Fd7%2FFieldInstance.php;h=452c6bbfde480c4d795a1eefed808075f2a7685e;hp=d06336e1538bcc838240993942eb9aacdd4944b4;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php b/web/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php index d06336e15..452c6bbfd 100644 --- a/web/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php +++ b/web/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php @@ -8,9 +8,14 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; /** * Drupal 7 field instances source from database. * + * @internal + * + * This class is marked as internal and should not be extended. Use + * Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase instead. + * * @MigrateSource( * id = "d7_field_instance", - * source_provider = "field" + * source_module = "field" * ) */ class FieldInstance extends DrupalSqlBase { @@ -21,14 +26,12 @@ class FieldInstance extends DrupalSqlBase { public function query() { $query = $this->select('field_config_instance', 'fci') ->fields('fci') - ->condition('fci.deleted', 0) + ->fields('fc', ['type']) ->condition('fc.active', 1) - ->condition('fc.deleted', 0) ->condition('fc.storage_active', 1) - ->fields('fc', ['type']); - - $query->innerJoin('field_config', 'fc', 'fci.field_id = fc.id'); - $query->addField('fc', 'data', 'field_data'); + ->condition('fc.deleted', 0) + ->condition('fci.deleted', 0); + $query->join('field_config', 'fc', 'fci.field_id = fc.id'); // Optionally filter by entity type and bundle. if (isset($this->configuration['entity_type'])) { @@ -42,19 +45,43 @@ class FieldInstance extends DrupalSqlBase { return $query; } + /** + * {@inheritdoc} + */ + protected function initializeIterator() { + $results = $this->prepareQuery()->execute()->fetchAll(); + + // Group all instances by their base field. + $instances = []; + foreach ($results as $result) { + $instances[$result['field_id']][] = $result; + } + + // Add the array of all instances using the same base field to each row. + $rows = []; + foreach ($results as $result) { + $result['instances'] = $instances[$result['field_id']]; + $rows[] = $result; + } + + return new \ArrayIterator($rows); + } + /** * {@inheritdoc} */ public function fields() { return [ - 'field_name' => $this->t('The machine name of field.'), + 'id' => $this->t('The field instance ID.'), + 'field_id' => $this->t('The field ID.'), + 'field_name' => $this->t('The field name.'), 'entity_type' => $this->t('The entity type.'), 'bundle' => $this->t('The entity bundle.'), - 'default_value' => $this->t('Default value'), - 'instance_settings' => $this->t('Field instance settings.'), - 'widget_settings' => $this->t('Widget settings.'), - 'display_settings' => $this->t('Display settings.'), - 'field_settings' => $this->t('Field settings.'), + 'data' => $this->t('The field instance data.'), + 'deleted' => $this->t('Deleted'), + 'type' => $this->t('The field type'), + 'instances' => $this->t('The field instances.'), + 'field_definition' => $this->t('The field definition.'), ]; } @@ -62,29 +89,16 @@ class FieldInstance extends DrupalSqlBase { * {@inheritdoc} */ public function prepareRow(Row $row) { - $data = unserialize($row->getSourceProperty('data')); - - $row->setSourceProperty('label', $data['label']); - $row->setSourceProperty('description', $data['description']); - $row->setSourceProperty('required', $data['required']); - - $default_value = !empty($data['default_value']) ? $data['default_value'] : []; - if ($data['widget']['type'] == 'email_textfield' && $default_value) { - $default_value[0]['value'] = $default_value[0]['email']; - unset($default_value[0]['email']); + foreach (unserialize($row->getSourceProperty('data')) as $key => $value) { + $row->setSourceProperty($key, $value); } - $row->setSourceProperty('default_value', $default_value); - - // Settings. - $row->setSourceProperty('instance_settings', $data['settings']); - $row->setSourceProperty('widget_settings', $data['widget']); - $row->setSourceProperty('display_settings', $data['display']); - // This is for parity with the d6_field_instance plugin. - $row->setSourceProperty('widget_type', $data['widget']['type']); - - $field_data = unserialize($row->getSourceProperty('field_data')); - $row->setSourceProperty('field_settings', $field_data['settings']); + $field_definition = $this->select('field_config', 'fc') + ->fields('fc') + ->condition('id', $row->getSourceProperty('field_id')) + ->execute() + ->fetch(); + $row->setSourceProperty('field_definition', $field_definition); $translatable = FALSE; if ($row->getSourceProperty('entity_type') == 'node') { @@ -100,8 +114,8 @@ class FieldInstance extends DrupalSqlBase { else { // This is not a node entity. Get the translatable value from the source // field_config table. - $data = unserialize($row->getSourceProperty('field_data')); - $translatable = $data['translatable']; + $field_data = unserialize($field_definition['data']); + $translatable = $field_data['translatable']; } $row->setSourceProperty('translatable', $translatable); @@ -128,4 +142,11 @@ class FieldInstance extends DrupalSqlBase { ]; } + /** + * {@inheritdoc} + */ + public function count($refresh = FALSE) { + return $this->initializeIterator()->count(); + } + }