Facet Machine name vs label

Created on 10 May 2020, about 4 years ago
Updated 13 April 2024, 3 months ago

How can I change the Facet name to a custom name on the front-end?

I would like to use a custom label instead of the name that's displayed on the front end.

It's important to understand that I do not wish to change the name of it though. Just the label of it - just on the front end.

Not having to found any option I decided to give it a go with a custom processor but this changes not only the name but the label too.

class CustomLabel extends ProcessorPluginBase implements BuildProcessorInterface {

/**
* {@inheritdoc}
*/
public function build(FacetInterface $facet, array $results) {

  // Get user input custom label.
  $custom_label = $this->getConfiguration()['custom_label_value'];
  // Replace name.
  $facet->set('name',$custom_label);

  $facet->save();

  return $results;
}


  public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
    $config = $this->getConfiguration();

    $build['custom_label_value'] = [
      '#title' => $this->t('Custom Label'),
      '#type' => 'textfield',
      '#default_value' => isset($config['custom_label_value']) ? $config['custom_label_value'] : '',
      '#description' => $this->t("Insert a custom label"),
    ];

    return $build;
  }
}
I was looking for some sort of display function or label option? i.e

$facet->set('label',$custom_label); or
$facet->displayTitle($custom_label); 

Can anyone point me in the right direction?

πŸ’¬ Support request
Status

Postponed: needs info

Version

1.1

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom oli-chowdhury

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Title isn't super clear what's this about

    Also this was a support request so usually don't supply patches for this, unless a bug was discovered. But issue summary doesn't describe a bug or a proposed solution. Please verify on 3.0.x

Production build 0.69.0 2024