Account created on 22 October 2010, over 13 years ago
#

Merge Requests

Recent comments

πŸ‡ͺπŸ‡ΈSpain eidoscom

I figured out that you can translate the menu item using the menu interface but it will be very useful to do it on the term editing page like the content

πŸ‡ͺπŸ‡ΈSpain eidoscom

Hello @london6339, the code that I shared has nothing to do with it.

Not 100% sure but as the label is not stored in the DDBB, you can not access the label using Views.

Nevertheless, you can easily make a link with the label inside views by using the fields that you want for create the label and then link it to the profile.

πŸ‡ͺπŸ‡ΈSpain eidoscom

What I did to change the label is:

1. Create a module named profile_label
2. Create profile_label.module file with this content:

<?php

/**
 * Implements hook_entity_type_alter().
 */
function profile_label_entity_type_alter(array &$entity_types) {
    // Reemplaza la clase de entidad Profile original con la personalizada.
    $entity_types['profile']->setClass('Drupal\profile_label\Entity\Profile');
  }
  

3. Create the src/Entity/Profile.php file with this content:

<?php

namespace Drupal\profile_label\Entity;

use Drupal\profile\Entity\Profile as BaseProfile;

/**
 * Defines the custom profile entity class.
 */
class Profile extends BaseProfile {

  /**
   * {@inheritdoc}
   */
  public function label() {
    // Customize the logic to generate the profile label here.
     // You can call the original implementation using parent::label() if necessary.
     // For example:
     // $original_label = parent::label();
     // Customize $original_label to your needs.
    
     // Your custom logic to generate the profile label here.
    $first_name = $this->get('field_nom')->getString();
    $last_name = $this->get('field_primer_cognom')->getString();
    //$curs = "(" . $this->get('field_curs')->getString() .")";

    if($first_name != "" && $last_name != "") {
      $custom_label = "$first_name $last_name";
      return $custom_label;
    }
  }

}

You can modify the logic to make your functionality. In my case, field_nom, field_cognom and field_curs are fields attached to the profile entity.

Hope this can help someone.
Thanks!

Production build 0.69.0 2024