0

I have 2 content type. I want content type 2 to contain a custom field that holds the following information in that field:

  • Text field 1
  • Text field 2
  • Entity reference to Content type 1

I declared my hook_field_info() along with the widget_info, formatter info and hook_field_schema.

And used the entityreference_autocomplete contrib (https://www.drupal.org/project/entityreference_autocomplete) for the entityreference field within my widget.

All works well except for the fact that Drupal throws a PDO exception when saving the node that has the custom field.

It tells me that the insert value list does not match column list: 1136 Column count doesn't match value count.

After some debugging, I discovered that the entityreference_autocomplete field is trying to save all params (entity type, bundle, entity_id, ...) to my table. Where I just want then entity_id that is referenced to be saved (just like entity_reference works by default).

Any ideas on how to fix this?

I wanted to take this approach to avoid using field_collections...

It is also important to note that i will need to build a view based on this custom field's entity reference.

Many thanks in advance

Autocomplete implementation in field widget

    $element['service_category'] = array(
      '#type' => 'entityreference',
      '#title' => t('Service Category'),
      '#era_entity_type' => 'node',
      '#era_bundles' => array('service_category'),
      '#era_cardinality' => 1,
    );
  • If there is no actual code, it is very hard to say what is the problem. Unless someone made exactly same thing as you, but it is very rare. BTW, I checked entityreference_autocomplete_value_callback(), the element should only return one value rather then a list of params. How do you implement the autocomplete into your custom field? – Jimmy Ko Aug 10 '16 at 1:10
  • Dear JImmy, thanks for the reply. I have updated then answer with my widget implementation. If i could have some kind of callback where i could alter the value before it is being submitted, this might solve the problem. Although i wonder how views will be able to handle this reference. – Guardian Aug 10 '16 at 4:49
  • I can't see the full picture though I know you are altering the field widget by appending the new element. If there is a full code which I can test in my machine, it would be easier for me to find the solution.. – Jimmy Ko Aug 10 '16 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.