According to the documentation the computed fields should return empty array as their schema.
The \Drupal\field\Entity\FieldConfig::getSchema() though throws errors because it's missing the 'columns' value in the schema array.
The method adds the default values like indexes and foreign keys but it does leaves out the columns.

This simple patch fixes that.

CommentFileSizeAuthor
fieldconfig-getschema.patch600 bytesAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

Why do you even have a FieldConfig of a computed field type? If we really want to support this then I think more changes will be necessary, like completely skipping the schema handling because there is nothing to store.. I believe this would right now create field tables that have no value columns or something like that...

Anonymous’s picture

In order to use Entity View Mode instead of Views to dispaly an entity with various fields one has two options to achieve this:
a) use hook_entity_extra_field_info
b) use FieldType

The first scenario is good for simple things but one has to also take care of displaying the data via hook_entity_view which is fine BUT only for simple fields. Let's say I have some sort of data I want to display but I WANT to use field formatter(own or existing) and use some of it's settings for my data so I have the flexibility to alter the form or dispaly of my field/data. In such case only the second option is a viable solution.

Right now even Path module has computed field that even though it has data in the database it does store them in it's own table.

Personally I don't understand why we still cannot use custom values with field formatters and widgets but the Entity fields. This bothers my since times of CCK and I though D8 will finally solve this issue of empty tables for computed fields.

Anyway I tihnk there was some work done about this especially when it comes to base entity fields which now support Field UI Form and display settings, even the computed fields, though I can't find the issue right now(some things are already commited in A12).

---------

I would use Views but what I'm doing requires an average user to change fields and layouts(Display Suite) for entities and Views are just sooooo muuuuch complicated for an average user. Therefore I have to use View modes(which is fine with me and DS makes it soo great to use).

--------

I think the best solution would be to allow fields added via hook_entity_extra_field_info to at least have access to formatters OR have some option to specify a settings form that would act like formatter settings but would be handled by the module defining the extra fields.

Berdir’s picture

I see, so you're using a fake field to be able to have a formatter for it. Then I would suggest you add that in hook_entity_bundle_field_info() as a FieldDefinition, just like path.module does it?

Anonymous’s picture

Status: Needs review » Closed (works as designed)

Oh, I didn't know about those family of hooks.
Seems that would be a proper way to do this then.
Thanks for pointing me to the right direction. Now I have to figure out how to make it work :)

I guess I'll close this then.

Anonymous’s picture

Status: Closed (works as designed) » Active

I'm reopening this issue since:
a) Path module provides such computed field(mentioned above)
b) the \Drupal\Core\Field\FieldItemInterface::schema() specifically says:

Computed fields having no schema should return an empty array.

and

@return array
* An empty array if there is no schema...

Also we really need to have (computed)fields without schema because we can have whatever field formatter we like but, in many cases, we cannot use the default field types ina various situations.

For example: I have a form that needs to be displayed with my entity and this form a) cannot use any existing field typa and b) it has to use ONLY it's own field formatter.

Example No. 2: I have an entity which has title field. This COULD be just a string type BUT I want to be able to make this field into a link pointing to the entity. Sure, I can create a formatter BUT I cannot/want user to use this formatter with another string-typed field.

Therefore in many situations we need a custom field type and field formatter(s) that are compatible only with each other.

Anonymous’s picture

Anonymous’s picture

In addition to my comment in #5 I tihnk it would be good DX to add support for formatters and widgets to extra fields fields since the extra fields are basically the same thing as computed base fields anyway.

Anonymous’s picture

Status: Active » Closed (works as designed)