Hi,

looking for a way of keeping field defintions in code (or moving single fields from one installation to another), I was looking for a way of exporting and importing fields and instances. The only useful module I found was Bundle Copy, but it doesn't allow to export only fields, without the underlying entity (at least I wasn't able to figure out how).

As I really needed this I coded a quick version myself: Field Export (sandbox). Then I found your module and thought it might be worth the trouble of integrating this functionality.

I would be glad to give a helping hand, providing patches, ...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

This is something we could add:

- to each field as an export tab
- to the entity type admin as in import tab

Patches gratefully accepted! :)

berliner’s picture

Status: Active » Needs review
FileSize
16.86 KB

Patch adds:

  • Functions for Import / Export of field / groups definitions
  • Column "Export" for each field / group on the fields ui table of any entity
  • Tab "Export" for each field / group
  • Tab "Export" for each entity: allows to export multiple fields / groups
  • Tab "Import" for each entity: allows to import multiple fields / groups
joachim’s picture

Status: Needs review » Needs work

Thanks for the patch! Sorry it's taken me a while to look at it -- big patches are daunting, and I was hoping other users would give it a try too.

This is just a first-pass eyeball review. There are quite a few minor problems that need fixing. Sorry if this seems like a lot of nitpicking, but as a maintainer, I need to keep the code in the module in a form that is readable and understandable. Hence I'm stickler for Drupal coding standards -- please do take some time to familiarize yourself with them :)

+++ b/field_tools.admin.inc
@@ -463,6 +463,374 @@ function field_tools_field_clone_form_submit($form, &$form_state) {
+ * Export all fields of a bundle
+ *
+ * @param string $form ¶
+ * @param string $form_state ¶
+ * @param string $entity_type ¶
+ * @param string $bundle ¶

Can you check the formatting of your docblocks please?

- first line needs a full stop.
- @param lines need a description
- no @return needed if there is no return

+++ b/field_tools.admin.inc
@@ -463,6 +463,374 @@ function field_tools_field_clone_form_submit($form, &$form_state) {
+  ¶

Please trim whitespace before rolling a patch. Also, this blank line shouldn't be here anyway.

+++ b/field_tools.admin.inc
@@ -463,6 +463,374 @@ function field_tools_field_clone_form_submit($form, &$form_state) {
+  // Get the bundle name if the bundle name is really a bundle object.
+  $bundle_name = is_object($bundle) ? $bundle->type : $bundle;

Why would this parameter sometimes be an object and sometimes not? The @param docs need to explain this.

+++ b/field_tools.admin.inc
@@ -463,6 +463,374 @@ function field_tools_field_clone_form_submit($form, &$form_state) {
+  if (isset($form_state['storage']['fields'])) {

What is this testing?

+++ b/field_tools.admin.inc
@@ -463,6 +463,374 @@ function field_tools_field_clone_form_submit($form, &$form_state) {
+    ¶

No need for this blank line.

+++ b/field_tools.admin.inc
@@ -463,6 +463,374 @@ function field_tools_field_clone_form_submit($form, &$form_state) {
+function field_tools_bundle_export_form_submit($form, &$form_state) {

Needs a docblock -- though you can skip the @params since they are standard.

+++ b/field_tools.admin.inc
@@ -463,6 +463,374 @@ function field_tools_field_clone_form_submit($form, &$form_state) {
+  if ($form_state['values']['op'] == $form_state['values']['import_force']) {

What is this testing?

+++ b/field_tools.admin.inc
@@ -463,6 +463,374 @@ function field_tools_field_clone_form_submit($form, &$form_state) {
+    form_set_error('code');

Shouldn't this set an error message too?

+++ b/field_tools.admin.inc
@@ -463,6 +463,374 @@ function field_tools_field_clone_form_submit($form, &$form_state) {
+  unset($group->id);
+  unset($group->identifier);
+  unset($group->bundle);
+  unset($group->entity_type);

This needs to be explained.

+++ b/field_tools.admin.inc
@@ -733,3 +1101,25 @@ function field_tools_field_instances_list($field) {
+function field_tools_textarea($label, $value = NULL) {

I'm not terribly keen on this. It makes forms harder to understand. Do we really need it? How many times is it used? How many times is the form array it returns tweaked a bit by the caller?

+++ b/field_tools.module
@@ -226,12 +267,87 @@ function _field_tools_field_already_attached($entity_type, $bundle_type, $field_
+  if ($form_id == 'field_ui_field_overview_form') {

Use hook_form_FORM_ID_alter() here.

+++ b/field_tools.module
@@ -226,12 +267,87 @@ function _field_tools_field_already_attached($entity_type, $bundle_type, $field_
+    if (isset($form['#after_build']) && is_array($form['#after_build'])) {

What is this testing?

berliner’s picture

Status: Needs work » Needs review
FileSize
19.29 KB
16.62 KB

Thanks for the review. I always thought I was picky with coding standards :-)

I have rerolled the patch with added comments and updated doc blocks.

+++ b/field_tools.admin.inc
@@ -733,3 +1101,25 @@ function field_tools_field_instances_list($field) {
+function field_tools_textarea($label, $value = NULL) {

I'm not terribly keen on this. It makes forms harder to understand. Do we really need it? How many times is it used? How many times is the form array it returns tweaked a bit by the caller?

This is used 4 times and it makes sense to me as it respects the DRY principle.

One thing I changed in the patch though is the menu position of the "Export fields" / "Import fields" menu items which are now local tasks underneath the "manage fields" page. I realized that they are duplicated when comments are enabled, because comments are also fieldable, see attached screenshot. This applies to the "clone" menu items as well, but that would be another topic.

interdruper’s picture

Category: feature » bug

First of all, thanks for this useful patch.

In my tests, I found the following error when trying to Export the fields from an entity created with ECK:

Notice: Trying to get property of non-object in field_tools_bundle_export_form() (line 471 of ...\field_tools.admin.inc).

This is the line 471:

  // Get the bundle name
  $bundle_name = $bundle->type;

The same error appears when trying to Export the fields from any Field Collection.

In these cases, $bundle is just a string, not an array, the opposite that happens in Content Types.

berliner’s picture

Category: bug » feature
FileSize
17.1 KB

Thanks for the feedback. I corrected the patch to be compatible with eck and field collection.

Reverting the category to "feature request" because this is still a feature request with a patch in work.

joachim’s picture

Issue summary: View changes
Status: Needs review » Fixed

Committed a modified version of the patch with a few tweaks:

- Fixed button label on export form.
- Added CTools as dependency.
- Moved menu items under Tools tab.
- Spacing and comments formatting.

git commit -m "Issue #1859388 by berliner: Added tools for field import / export." --author="berliner "

Thanks!

berliner’s picture

Cool! You can add that functionality to the list on the project page as well.

Thanks for maintaing this module!

joachim’s picture

> You can add that functionality to the list on the project page as well.

Already done :)

You're welcome! Thanks again for all your work on this new feature.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

R-H’s picture

I just used the import feature. Thank you for saving me hours of recreating fields!

stpaultim’s picture

I'm looking all over for the "import feature" and can't find where this happens. The "export" portion is pretty clear. Is there a UI option for importing the field? If so, where do I find it?

Ollie222’s picture

@stpaultim

I've come across the same thing and have raised it in a new thread.

https://www.drupal.org/node/2681079