Skip to content

Commit 874f936

Browse files
committed
added field type conversion error
1 parent 66996a5 commit 874f936

File tree

1 file changed

+49
-17
lines changed

1 file changed

+49
-17
lines changed

docs/pattern_builder_importer.md

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ It converts an library of JSON Schemas into Drupal paragraph bundles, and the JS
3232
- Template directories
3333

3434
1. Use Drush to run the pattern builder import command
35-
- If there are new patterns, first rsync webrh
36-
- SSL into sandbox
35+
- If there are new patterns, then sync changes to the patternbuilder schema and template directories.
3736
- Run `drush pbi`
3837

3938
1. View the imported patterns now stored as paragraph bundles
@@ -45,10 +44,7 @@ It converts an library of JSON Schemas into Drupal paragraph bundles, and the JS
4544

4645
1. Manage Display: Set the display format on the paragraph field to "Patternbuilder rendered items"
4746
1. Other Notes:
48-
- Don’t forget to load the webrh.css via a pre-process function or the style module
49-
- Optional: Modify the content type node--[type].tpl.php as needed to remove other regions etc
50-
- To use the test pattern, enabled “Red Hat webrh test” on the modules page: /admin/modules?filter=webrh_test&enabled=1&disabled=1&required=1&unavailable=1 -- it will take a while to import so you have to wait for the page to be done refreshing
51-
47+
- Optional: Modify the content type node--[type].tpl.php as needed to remove other regions etc.
5248

5349
1. Drush Commands
5450
1. Imports patterns from defined library
@@ -294,23 +290,59 @@ This is an edge case. If encountered, please open an issue on the patternbuilder
294290
295291
- - -
296292
297-
**ERROR: '@field (@field_type): @base_field_error'**
298-
299-
field_402_text (text => text_long): Cannot change an existing field's type.
300-
301-
TODO: Get field type error.
302-
303-
Note on how to convert text fields.
304-
305-
306-
293+
**ERROR: 'field_123_text (text => text_long): Cannot change an existing field's type.'**
294+
295+
This error occurs when the field type determine from the property's schema is different than the existing field's type in Drupal.
296+
297+
The patternbuilder.install provides a helper function to convert text fields. This should be added to an update function before the fields are imported.
298+
299+
```php
300+
function mymodule_update_7123() {
301+
$pattern_name = 'awesome_pattern';
302+
$property_name = 'text';
303+
$field_type_new = 'text_long';
304+
305+
$instance = patternbuilder_field_info_property_instance($pattern_name, array($property_name));
306+
if (!empty($instance['field_name'])) {
307+
module_load_install('patternbuilder');
308+
$converted = patternbuilder_convert_text_field($field_name, $new_type);
309+
if ($converted) {
310+
// Import schema to allow the importer to set any customizations for the
311+
// field and instances.
312+
patternbuilder_importer_import_schemas(array($pattern_name));
313+
}
314+
else {
315+
$t = get_t();
316+
$error_message = $t('@pattern @property could not be converted.', array(
317+
'@pattern' => $pattern_name,
318+
'@property' => implode('.', $property_names),
319+
));
320+
321+
if ($converted === FALSE) {
322+
// Hard fail.
323+
throw new DrupalUpdateException($error_message);
324+
}
325+
else {
326+
// Soft fail for incomplete data or conversion not allowed.
327+
watchdog('mymodule_update_7123', $error_message);
328+
}
329+
}
330+
}
331+
}
332+
```
333+
334+
Allowed conversions:
335+
336+
- 'text' TO 'text_long' or 'text_with_summary'.
337+
- 'text_long' TO 'text_with_summary'
338+
- 'text_with_summary' TO 'text_long': The 'summary' column is kept.
307339

308340

309341
- - -
310342

311343
**ERROR: 'The property references a schema that is not imported due to the status "inactive": "schema_really_old.json#/properties/display_title"'**
312344

313-
This message is logged if the referenced property's schema has never been imported and there is a property referencing it.
345+
This message is logged if the referenced property's schema has never been imported and there is a property referencing it.
314346

315347
A referenced Drupal field cannot be found if the schema was never imported to a paragraph bundle.
316348

0 commit comments

Comments
 (0)