In light of the work being done on the unified Entity Field API, is Field API's concept of 'extra fields' still relevant?

I don't think I was around Drupal when this was introduced, but it seems to me that it only serves the purpose off adding 'stuff' to entity displays and forms that are *not* configurable fields. Given that we now have a new API for entity fields (formerly known as properties), and we want to move in a direction that allows existing field formatters and widget to be used by them, I think that a lot of special-casing code can be dropped and cleaned up.

Comments

Berdir’s picture

Issue tags: -sprint

As said in IRC, extra fields is currently used to expose all kinds of UI elements on entity forms and displays to the manage fields pages, e.g. contact settings for users. They're not going to become a field so we still need a solution for that.

Removing sprint tag, that is only used for issues that are actively being worked on at the moment and we can't work on this before the NG conversion is done and the field modules updated to work with it.

yched’s picture

Title: Drop the concept of 'extra fields' » Revaluate the concept of 'extra fields'

Agreed with Berdir.

A (possibly large) part the stuff that is currently exposed as an "extra field" could stop doing so if/when widgets and formatters become applicable to entity properties, since they will appear in Field UI as being "fields" (whether EntityFields or configurable fields). But :
- I couldn't say for sure that this will cover everything that is currently an "extra field"
- the premises are still hypothetical at this point :-).

So no, I don't think we're ready to drop the concept right now :-(.

amateescu’s picture

Title: Revaluate the concept of 'extra fields' » Reevaluate the concept of 'extra fields'
Priority: Major » Normal
Status: Active » Postponed

Ok then, let's discuss this again when more issues from #1346214: [meta] Unified Entity Field API are done.

andypost’s picture

Seems this one have duplicate as feature #1818680: Eliminate hook_field_extra_fields() / Redesign field UI architecture
Probably it's enough to use the issue to implement special kind of Typed data for all extra-fields as was done in #1732730: [meta] Implement the new entity field API for all field types

rudiedirkx’s picture

I would really really miss extra_fields, but I do want them with formatters and settings: #1983398: Allow formatters & formatter settings for extra_fields (display). Currently (D7) that's not possible with clean contrib, so the Field API will have to progress a bit.

rszrama’s picture

With this discussion on hold, is it worth pursuing a fix in a separate issue to the extra fields system as is to actually use the extra field weight values when building entity forms? Right now, the default extra field weights and UI configured weights are completely ignored. A simple example is to move a node type's title extra field to appear beneath the body - it will not move.

amateescu’s picture

rszrama’s picture

Ahh, yeah, Bojan indicated that might be the case. I'd assumed that patch was already in when I started seeing form display variables in the $form_state. That patch is ginormous! I'll apply it while I'm fiddling around to see if it brings up any problems and make sure it fixes the one I know about. : )

yched’s picture

Title: Reevaluate the concept of 'extra fields' » Move the concept of 'extra fields' to entity.module
Status: Postponed » Active
Issue tags: +API change, +Field API

So, right, I think 'extra_fields' are here to stay in D8.

Strictly speaking, the handling of extra fields has nothing to do in field.module though.
The corresponding hooks and functions should move to entity.module / the entity system:

Note that storing & loading their display configuration is already taken care of by EntityDisplay / EntityFormDisplay objects.

- field_info_extra_fields() / FieldInfo::getBundleExtraFields() / FieldInfo::prepareExtraFields()
(collect and cache the list of available extra fields)
I would say this would make sense split in two (extra fields in displayed entities, extra fields in forms), and moved to
EntityRenderController / EntityFormController.
- hook_field_extra_fields() / hook_field_extra_fields_alter()
(let modules expose their extra fields)
According to the above, hook_field_extra_fields() would be split in two separate hooks, one for entity views (called by EntityRenderController), the other for entity forms (called by EntityFormController)
Would be named hook_entity_something(), and would be documented in entity.api.php

Would need sign-off from a core committer for the API changes:
- hook_field_extra_fields() / hook_field_extra_fields_alter() renamed
- field_info_extra_fields() renamed (not too likely to be used in contrib though)

Dries’s picture

Version: 8.x-dev » 9.x-dev
Status: Active » Closed (won't fix)

Discussed this with Alex Pott, effulgentsia and xjm at the Drupal Developer Summit in Chicago and we felt the extra field stuff should no longer exist. Given that the "extra fields" concept will most likely be removed in Drupal 9, we should just leave it alone for Drupal 8. It's not worth an API change at this stage of the release cycle. I believe we're tracking the proper solution in #1818680: Eliminate hook_field_extra_fields() / Redesign field UI architecture, hence I'm marking this "won't fix".

yched’s picture

I do think the concept of "extra fields" is here to stay... "Add an arbitrary render array to an entity_view, and let admins reorder it through the 'entity display UI" is not a need that's going away even with more flexible fields. Not everything can be reduced to "a given formatter applied to a given field".

But I can live with the status quo in D8.

yched’s picture

Title: Move the concept of 'extra fields' to entity.module » Revaluate the concept of 'extra fields'
Status: Closed (won't fix) » Active
Issue tags: -API change

Then, retitling (back) rather than won't fixing.

effulgentsia’s picture

Not everything can be reduced to "a given formatter applied to a given field".

No, but can't it be reduced to a component once we have #1875974: Abstract 'component type' specific code out of EntityDisplay?

yched’s picture

Well, #1875974: Abstract 'component type' specific code out of EntityDisplay introduces component types, not individual components.

The scenario you describe is:
every arbitrary piece of render array currently added in FooRenderController::buildContent() or some flavor of hook_entity_view()/_alter(), becomes its own separate 'component type' plugin class.

- If the actual rendering stays in buildContent() / hook_entity_view() and is not in the plugin classes, then those plugin classes are all the same, and it's weird to have them be separate plugins. The current D8 way of "expose your stuff in a hook somewhere & a single 'component type' plugin will take care of managing their settings" makes more sense IMO.
- If the actual rendering happens in the classes, then what we have is just Blocks :-), and this is the "merge entity display with the block system" approach that was discussed at some point.

So yes, IMO the only thing that would let us remove "extra fields" in D9 is to fully merge "components in a rendered entity (fields, field groups, extra fields, DS 'custom components'...)" with blocks. EntityDisplay then become an entity-level "populated layout", like SCOTCH provides page-level "populated layouts". It was far too big / too late for D8, notably while SCOTCH was still a moving thing up in the air, but maybe for D9...

This means hook_entity_view() & friends become much less useful, and the DX to get "some arbitrary piece of output" into an entity becomes a bit more involved - you need to declare a block.

One challenge that comes to mind (among others...), is that field_groups introduces nesting, and I don't know if SCOTCH planned to account for that.
One other challenge is performance :-). SCOTCH's mission is "display one page layout fast enough". With the above, it becomes "display one page layout + 10s of entity layouts".
[edit - oh, and another challenge was node.tpl becomes basically unworkable]

andypost’s picture

Suppose the easiest way to move extra fields to calculated and allow entity display use 'em

ordermind’s picture

Issue summary: View changes

Extra fields are genius, I'm planning to build a distribution that uses extra fields as a complete replacement for blocks. No more hacking template files or preprocess functions to embed blocks inside nodes! Instead we shall have one simple, unified way of displaying content through view modes.

ordermind’s picture

One year later I still hold the same opinion. Extra fields and field UI can potentially solve the issue of slow block rendering and more elegantly than panels since it's more native to Drupal core. Use field groups and you'll have a completely flexible layout manager without having to create panels layouts in code. What you need to do is create a module that exposes all blocks as extra fields and then create a sweet ipe-like interface to place field groups, normal fields and extra fields/blocks wherever you wish. With the power of render cache and cache tags in D8, it should be really performant. The only thing that I really miss is to be able to create field formatters for extra fields, so that you can output for example author information in different ways. Maybe I'll be able to create a contrib solution for that, we'll see how far I can get within the limits of Drupal core.

Anonymous’s picture

#15 is now the obvious solution. Why do we have to wait for d9 to do this?

rudiedirkx’s picture

@ordermind We do need extra field formatters/settings. Contrib could do this, but it won't be well known enough unless it's provided by Drupal. Relevant: #1983398: Allow formatters & formatter settings for extra_fields (display) and many duplicates

catch’s picture

Version: 9.x-dev » 8.1.x-dev

We should see what we can do with this in minor releases.

benjy’s picture

Adding an extra field from custom code or contrib still requires hook_entity_extra_field_info and hook_entity_view_alter. Also, I couldn't get thirdPartySettings to work on the extra field itself even though it gets initialised with an empty array. If you want to add custom settings you also need a hook_form_FORM_ID_alter and a form submit callback.

Could we wrap all these hooks up into a new plugin type? @ExtraFIeld, that made it easier for developers to add extra fields without having to find all the procedural hooks?

andypost’s picture

ExtraFieldComponent is good idea

Anonymous’s picture

Currently I am using a dummy field type

/**
 * Dummy field item with required methods for field items that do not store
 * any data in the database.
 */
class DummyItem extends FieldItemBase {

  public static function schema(FieldStorageDefinitionInterface $field_definition) {
    return [];
  }

  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    return [];
  }

  public function isEmpty() {
    return FALSE;
  }

}

as a base class which I extend by any fields that do not require DB.

/**
 * @FieldType(
 *   id = "entity_label",
 *   label = @Translation("Label"),
 *   description = @Translation("A field representing the title."),
 *   default_formatter = "entity_label"
 * )
 */
class EntityLabelItem extends DummyItem {
}

Then I use either custom formatters or I will alter the formatter info to support my dummy field(s) so that I can use any formatter I like.
I use hook_entity_base_field_info to attach the field I need and set it as computed and that's it. I get the full "power" of Field API and it is working just fine for me. I don't see any point in extra fields anymore and I also don't think "ExtraFieldComponent" is needed as well.

Since introduction of computed flag for fields and the support for fields without any storage was introduced into the core I think this whole issue is obsolete.

benjy’s picture

With that approach you have to have one of those dummy field item classes for each field you add? Plus, if you want to format the output differently, you need a new field formatter each time as well. I did actually contemplate this approach myself for a contrib module but ended up using an extra field to place a simple link.

Anonymous’s picture

"you have to have one of those dummy field item classes for each field you add" - yes, and having a plugin instead of some array entry makes more sense to me.

"if you want to format the output differently, you need a new field formatter each time as well" - no. As I've said I alter the formatter info via hook_field_formatter_info_alter, or provide formatter if I need to.

DuaelFr’s picture

@ivanjaros I think you're genius! Thank you for sharing your solution. It's not perfect but it's far better than current extra field :)
It'd be really great to have something in Core to modernize these concepts.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jibran’s picture

I think we should something similar to #23 in core as well.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jonathanshaw’s picture

#21 I couldn't get thirdPartySettings to work on the extra field

There's a new contrib module called "Extra field settings" that makes this easier, see this article.

#21 Could we wrap all these hooks up into a new plugin type? @ExtraFIeld, that made it easier for developers to add extra fields without having to find all the procedural hooks?

There's a new contrib called "Extra field" module that does just this.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.