diff --git a/README.txt b/README.txt index 9211219..7c57477 100644 --- a/README.txt +++ b/README.txt @@ -2,30 +2,27 @@ HEAD to HEAD ------------ -This module provides upgrade paths for schema changes in Drupal 7 until the -HEAD-HEAD upgrade path is officially supported (after Drupal 7.0-beta1 is -released.) +This module provides upgrade paths for schema changes in Drupal 8 until the +HEAD-HEAD upgrade path is officially supported. In order to use this module, you will need to create a custom module that calls the appropriate head2head_[issue number]() functions needed for your specific installation. -Alpha to Alpha +Beta to Beta -------------- -Alpha2Alpha is a helper module that depends on head2head. It can only be used if -your website only uses official alpha releases. It cannot be used if your -website is using Drupal HEAD from CVS. +Beta2Beta is a helper module that depends on head2head. It can only be used if +your website only uses official beta releases. It cannot be used if your website +is using Drupal HEAD from git. -The alpha2alpha module uses the head2head upgrade functions in its .install file +The beta2beta module uses the head2head upgrade functions in its .install file to provide upgrades through Drupal's normal update.php page. -If you install and use alpha2alpha, you should not uninstall it or alpha2alpha +If you install and use beta2beta, you should not uninstall it or beta2beta will forget which updates have been completed the next time you install it. -However, you can safely disable the module; the next time you enable it, it will -remember which updates have already been run. However, just because this module is easier to use than head2head, in no way -should it be seen as an endorsement of running a real website on Drupal alpha. +should it be seen as an endorsement of running a real website on Drupal beta. There are no guarantees that you won't lose all your data. diff --git a/beta2beta/beta2beta.info.yml b/beta2beta/beta2beta.info.yml new file mode 100644 index 0000000..1bcdb15 --- /dev/null +++ b/beta2beta/beta2beta.info.yml @@ -0,0 +1,7 @@ +type: module +name: 'Beta to Beta' +description: 'Provides an upgrade path for beta versions of Drupal 8 until the upgrade path is officially supported in core.' +core: 8.x +#configure: admin/config/development/beta2beta +dependencies: + - head2head diff --git a/beta2beta/beta2beta.install b/beta2beta/beta2beta.install new file mode 100644 index 0000000..7447891 --- /dev/null +++ b/beta2beta/beta2beta.install @@ -0,0 +1,65 @@ +getEditable('beta2beta.settings')->clear('version'); + $current_beta_version = beta2beta_get_beta_version(); + if (!$current_beta_version || $current_beta_version < $beta_version) { + throw new UpdateException(String::format('Not yet on Drupal 8.0.0-beta@version.', array('@version' => $beta_version))); + } + else { + // Run the head2head update, passing along any additional arguments that + // were provided. + $args = func_get_args(); + array_shift($args); + array_shift($args); + $function = 'head2head_' . $head2head_update; + call_user_func_array($function, $args); + } +} + +/** + * @defgroup updates-beta-7-to-8 Drupal updates from 8.0.0-beta7 to 8.0.0-beta8 + * @{ + */ + +/** + * Convert Taxonomy term reference fields to Entity reference. + */ +function beta2beta_update_8800() { + beta2beta_update_helper('1847596', 8); +} + +/** + * @} End of "defgroup updates-beta-7-to-8" + */ diff --git a/beta2beta/beta2beta.module b/beta2beta/beta2beta.module new file mode 100644 index 0000000..6378f25 --- /dev/null +++ b/beta2beta/beta2beta.module @@ -0,0 +1,47 @@ +get('version', FALSE); + + if (!$version) { + $version = beta2beta_determine_beta_version(); + } + return $version; +} + +/** + * Determines the core beta version. + * + * @return int|false + * Returns an integer representing the current Drupal core beta version. If + * Drupal core is not on an beta version, return FALSE. + */ +function beta2beta_determine_beta_version() { + if (strpos(\Drupal::VERSION, '8.0.0-beta') === 0) { + return str_replace('8.0.0-beta', '', \Drupal::VERSION); + } + else { + return FALSE; + } +} + +/** + * Implements hook_field_info_alter(). + */ +function beta2beta_field_info_alter(&$info) { + // The 'taxonomy_term_reference' has been removed in 8.0.0-beta8. + $info['taxonomy_term_reference']['id'] = 'taxonomy_term_reference'; + $info['taxonomy_term_reference']['label'] = t('Term reference'); + $info['taxonomy_term_reference']['description'] = t('This field type has been removed.'); + $info['taxonomy_term_reference']['class'] = '\Drupal\beta2beta\PluginOverride\Field\FieldType\TaxonomyTermReferenceItem'; + $info['taxonomy_term_reference']['list_class'] = '\Drupal\Core\Field\EntityReferenceFieldItemList'; + $info['taxonomy_term_reference']['no_ui'] = TRUE; +} diff --git a/beta2beta/src/PluginOverride/Field/FieldType/TaxonomyTermReferenceItem.php b/beta2beta/src/PluginOverride/Field/FieldType/TaxonomyTermReferenceItem.php new file mode 100644 index 0000000..1d55e5b --- /dev/null +++ b/beta2beta/src/PluginOverride/Field/FieldType/TaxonomyTermReferenceItem.php @@ -0,0 +1,25 @@ +getStorage('field_storage_config')->loadByProperties(array('type' => 'taxonomy_term_reference'))) { + return; + } + + /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */ + // Update the field storage settings. + foreach ($field_storage_configs as $field_storage) { + // Since the usual workflow for field storages do not allow changing the + // field type, we have to work around it in this case. + $new_field_storage = $field_storage->toArray(); + $new_field_storage['type'] = 'entity_reference'; + $new_field_storage['module'] = 'core'; + $new_field_storage['settings']['target_type'] = 'taxonomy_term'; + + $vocabulary_name = $new_field_storage['settings']['allowed_values'][0]['vocabulary']; + unset($new_field_storage['settings']['allowed_values']); + + $new_field_storage = FieldStorageConfig::create($new_field_storage); + $new_field_storage->original = $new_field_storage; + $new_field_storage->enforceIsNew(FALSE); + + $new_field_storage->save(); + + // Update the field settings. + $field_name = $field_storage->getName(); + if (!$fields = \Drupal::entityManager()->getStorage('field_config')->loadByProperties(array('field_name' => $field_name))) { + continue; + } + + /** @var \Drupal\field\FieldConfigInterface $field */ + // Update the field settings. + foreach ($fields as $field) { + $new_field = $field->toArray(); + $new_field['field_type'] = 'entity_reference'; + $new_field['settings'] = array( + 'handler' => 'default:taxonomy_term', + 'handler_settings' => array( + 'target_bundles' => array($vocabulary_name => $vocabulary_name), + // Enable auto-create. + 'auto_create' => TRUE, + ), + ); + + $new_field = FieldConfig::create($new_field); + $new_field->original = $field; + $new_field->enforceIsNew(FALSE); + $new_field->save(); + + // Update entity view displays. + $properties = array( + 'targetEntityType' => $field->getTargetEntityTypeId(), + 'bundle' => $field->getTargetBundle() + ); + if ($view_displays = \Drupal::entityManager()->getStorage('entity_view_display')->loadByProperties($properties)) { + foreach ($view_displays as $view_display) { + if ($component = $view_display->getComponent($field_name)) { + $view_display->setComponent($field_name, array( + 'type' => 'entity_reference_label', + 'settings' => array( + 'link' => TRUE, + ), + ) + $component)->save(); + } + } + } + + // Update entity form displays. + $properties = array( + 'targetEntityType' => $field->getTargetEntityTypeId(), + 'bundle' => $field->getTargetBundle() + ); + if ($form_displays = \Drupal::entityManager()->getStorage('entity_form_display')->loadByProperties($properties)) { + foreach ($form_displays as $form_display) { + if ($component = $form_display->getComponent($field_name)) { + $form_display->setComponent($field_name, array( + 'type' => 'entity_reference_autocomplete_tags', + 'settings' => array( + 'match_operator' => 'CONTAINS', + 'size' => '60', + 'placeholder' => '', + ), + ) + $component)->save(); + } + } + } + } + } +} + /** * Increase size of init field on users table to 254 characters. */