Content types are not transform to it labels.

My variant of ListItemProcessor:

public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigManagerInterface $config_manager, EntityFieldManagerInterface $entity_field_manager) {
    .....
    $this->entityTypeBundleInfo = \Drupal::service('entity_type.bundle.info');
  }

  public function build(FacetInterface $facet, array $results) {
    ....
    $allowed_values = $field->getSetting('allowed_values');

    if (empty($allowed_values) && $function = $field->getSetting('allowed_values_function')) {
      $allowed_values = ${$function}($field);
    }

    if (empty($allowed_values) && $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity)) {
      foreach ($bundles as $key => $bundle) {
        $allowed_values[$key] = $bundle['label'];
      }
    }
 
    ....
  }

Comments

divined created an issue. See original summary.

divined’s picture

Issue summary: View changes
sylvainm’s picture

Status: Active » Needs review
StatusFileSize
new2.46 KB

Thanks, I dit the attached patch, which works for me ;-)

Status: Needs review » Needs work

The last submitted patch, 3: facets-list_item_label_processor_type-2765371-3.patch, failed testing.

The last submitted patch, 3: facets-list_item_label_processor_type-2765371-3.patch, failed testing.

sylvainm’s picture

Status: Needs work » Needs review
StatusFileSize
new3.54 KB

With attached patch, test should be ok now

Status: Needs review » Needs work

The last submitted patch, 6: facets-list_item_label_processor_type-2765371-4.patch, failed testing.

The last submitted patch, 6: facets-list_item_label_processor_type-2765371-4.patch, failed testing.

sylvainm’s picture

Status: Needs work » Needs review
StatusFileSize
new4.77 KB

Well, hope this one will be green...

borisson_’s picture

StatusFileSize
new5.19 KB
new8.43 KB

This changed the __contruct, so we needed to update the docblock for that as well, this expands the description. Also adds a unit test.

sylvainm’s picture

Status: Needs review » Reviewed & tested by the community

Thanks

  • borisson_ committed 421be91 on 8.x-1.x
    Issue #2765371 by SylvainM, borisson_: List item label processor not...
borisson_’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed, thanks for helping!

john franklin’s picture

#10 mostly works on our site. Unless the machine name of the bundle has an underscore, in which case it shows the underscoreless version of the machine name. e.g., 'news_story' => 'News Story' shows 'newsstory'.

I cherry-picked this specific patch for our site. If it works for you guys, that would mean there is a dependent patch to handle the underscore.

Status: Fixed » Closed (fixed)

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