Updated: Comment #0

Problem/Motivation

The Taxonomy Term entity type's name and description fields are still handled through custom code in entity forms and entity views.

Proposed resolution

Move to widgets and formatters.

AFAICT the following base fields cannot yet do the switch:

  1. langcode, because its visibility depends upon very specific settings, that I don't think can easily be generalized
  2. parent & weight, because they must be inside the "Relations" <details>, which is pretty much a field group, which we don't have in core

That only leaves the Taxonomy Term entity type's name and description fields.

Remaining tasks

Fix test failures.

User interface changes

None.

API changes

None. The taxonomy_term.name and taxonomy_term.description base fields are rendered using widgets and formatters, and are no longer exposed as "extra fields".

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

Status: Active » Needs review
FileSize
8.59 KB

Note: this patch was split off from Berdir's patch in #2010930: [META] Apply formatters and widgets to rendered entity base fields (all besides node.title).

Changes I made:

  1. The .taxonomy-term-description class was no longer being added; upgraded test coverage.
  2. Updating the CSS corresponding to .taxonomy-term-description did not make sense: its utility was highly questionable anyway. I've asked Lewis Nyman to check in/confirm that.
  3. The changes in template_preprocess_taxonomy_term() used to break the taxonomy-term.html.twig template.

Status: Needs review » Needs work

The last submitted patch, 1: taxonomy_term_base_fields_configurable-2225431-1.patch, failed testing.

Wim Leers’s picture

Issue summary: View changes
yched’s picture

Issue summary: View changes

Yay !
Adjusted issue summary, this does not turn the base fields into configurable fields, only makes them use widgets / formatters.

yched’s picture

side note: I'd happily leave it to someone to update the summaries on #2225371: Apply formatters and widgets to Custom Block base fields and #2225399: Apply formatters and widgets to Feed base fields similarly ;-)

mr.baileys’s picture

Assigned: Unassigned » mr.baileys

Assigning to myself to work on this during the Drupal Developer Days Szeged sprint.

mr.baileys’s picture

Assigned: mr.baileys » Unassigned
Status: Needs work » Needs review
FileSize
17.19 KB
22.35 KB

Fixed the test failures.

yched’s picture

  1. +++ b/core/modules/forum/config/entity.form_display.taxonomy_term.forums.default.yml
    @@ -3,11 +3,6 @@ targetEntityType: taxonomy_term
    -content:
    -  name:
    -    weight: -5
    -  description:
    -    weight: 0
    

    Hm, we still want to provide a 'content' section with 'name' and 'description' entries in the display shipped in default config.
    We just want to extend each of those entries with properties for "being displayed by a widget / formatter" - see how it appears in a real-life entity.form_display.taxonomy_term.forums.default.yml file after the patch (and after submiting the corresponding "Manage Form" screen)

  2. +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermViewBuilder.php
    @@ -19,30 +19,9 @@ class TermViewBuilder extends EntityViewBuilder {
    +    /** @var \Drupal\taxonomy\TermInterface $entity */
    

    Unrelated / not needed ?
    (I know we put those more and more, still hate them ;-)

mr.baileys’s picture

Thanks for the review @yched!

Regarding your first point, this might be indicative of another bug, but we had to remove this to prevent ContainerFormController from breaking:

Widget instantiation in EntityFormDisplay::getRenderer():

    // Instantiate the widget object from the stored display properties.
    if (($configuration = $this->getComponent($field_name)) && isset($configuration['type']) && ($definition = $this->getFieldDefinition($field_name))) {
      $widget = $this->pluginManager->getInstance(array(
        'field_definition' => $definition,
        'form_mode' => $this->originalMode,
        // No need to prepare, defaults have been merged in setComponent().
        'prepare' => FALSE,
        'configuration' => $configuration
      ));
    }

EntityDisplayBase::getComponent():

  /**
   * {@inheritdoc}
   */
  public function getComponent($name) {
    return isset($this->content[$name]) ? $this->content[$name] : NULL;
  }

If we left the content section in, then $this->content['name'|'description'] would no longer be empty but contain weight. This caused the widget for the fields to fail initialization, since getComponent() returned a configuration array with just weight, none of the other properties like type, and the widgets for name and description ended up being NULL.

I have removed the @var type hinting mentioned in your second point.

mr.baileys’s picture

FileSize
828 bytes

Forgot to attach interdiff in previous comment.

yched’s picture

@mr.baileys : that's because the entries should turn from "entries for an 'extra field'" to "entries for a field rendered by a widget" - i.e, they should now have a 'type' property, which is the name of the widget (and optionnally, not needed in our case here, a 'settings' property).

Something like :
core/modules/forum/config/entity.form_display.taxonomy_term.forums.default.yml

 content:
   name:
+    type: string
     weight: -5
   description:
+    type: text_textfield
     weight: 0

#1875974: Abstract 'component type' specific code out of EntityDisplay will make the difference between the two kind of entries (extra fields / fields using a widget) more explicit, but for now that's how it works.

mr.baileys’s picture

Thanks @yched! Fixed with help from Wim Leers and swentel.

Status: Needs review » Needs work

The last submitted patch, 12: 2225431-12-taxonomy-term-base-fields.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
FileSize
23.6 KB
1.24 KB

Oh wow, this was fun to debug

Wim Leers’s picture

FileSize
24.77 KB
1.68 KB

Talked to swentel and we agreed that the addition to text.schema.yml in #14 belongs in entity.schema.yml.

yanniboi’s picture

Hey, so this is a review of @swentel's patch in #14 (because @Wim is too fast for me... ;) ) Will reapply patch and double check for #15.

Patch applies fine and form display and rendering of taxonomy term look identical to pre-patch.

Here are screenshots of working formatters:

yanniboi’s picture

Status: Needs review » Reviewed & tested by the community

Confirmation: Patch #15 works just as well.

RTBC pending test result.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Needs a reroll

git ac https://drupal.org/files/issues/2225431-15.patch
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 25369  100 25369    0     0  19986      0  0:00:01  0:00:01 --:--:-- 23360
error: patch failed: core/modules/taxonomy/taxonomy.module:135
error: core/modules/taxonomy/taxonomy.module: patch does not apply
mr.baileys’s picture

Assigned: Unassigned » mr.baileys
mr.baileys’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll +Avoid commit conflicts
FileSize
22.37 KB
mr.baileys’s picture

Previous patch was missing changes from #14/#15. Here is the correct re-roll.

yanniboi’s picture

Status: Needs review » Reviewed & tested by the community

Test is green, since it is just a reroll (and currently applies), I'm moving it to RTBC.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

  • Commit d19928b on 8.x by catch:
    Issue #2225431 by mr.baileys, Wim Leers, swentel: Apply formatters and...
Wim Leers’s picture

Issue tags: -sprint

Status: Fixed » Closed (fixed)

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