diff --git a/lib/MusicBrainz/Server.pm b/lib/MusicBrainz/Server.pm index d05a5401c6b..883ca36e95c 100644 --- a/lib/MusicBrainz/Server.pm +++ b/lib/MusicBrainz/Server.pm @@ -336,6 +336,12 @@ sub handle_unicode_encoding_exception { $self->res->status(HTTP_BAD_REQUEST); } +has current_language => ( + is => 'rw', + isa => 'Str', + default => 'en', +); + # Set and unset translation language sub with_translations { my ($c, $code) = @_; @@ -355,6 +361,7 @@ sub with_translations { my $cookie_lang = Translation->instance->language_from_cookie($c->request->cookies->{lang}); $c->set_language_cookie($c->request->cookies->{lang}->value) if defined $c->request->cookies->{lang}; my $lang = Translation->instance->set_language($cookie_lang); + $c->current_language($lang); my $html_lang = $lang =~ s/_([A-Z0-9]{2,})/-\L$1/r; $c->stash( diff --git a/lib/MusicBrainz/Server/Controller/Artist.pm b/lib/MusicBrainz/Server/Controller/Artist.pm index f45e8b4f614..59815abc765 100644 --- a/lib/MusicBrainz/Server/Controller/Artist.pm +++ b/lib/MusicBrainz/Server/Controller/Artist.pm @@ -146,8 +146,7 @@ after 'load' => sub } } - my $lang = $c->stash->{current_language} // 'en'; - $c->model('Artist')->load_related_info([$artist], $lang); + $c->model('Artist')->load_related_info([$artist], $c->current_language); $c->model('ArtistType')->load(map { $_->target } @{ $artist->relationships_by_type('artist') }); $c->model('Area')->load_containment($artist->area, $artist->begin_area, $artist->end_area); }; diff --git a/lib/MusicBrainz/Server/Controller/Collection.pm b/lib/MusicBrainz/Server/Controller/Collection.pm index 4abb793d2f4..e9508f9bd81 100644 --- a/lib/MusicBrainz/Server/Controller/Collection.pm +++ b/lib/MusicBrainz/Server/Controller/Collection.pm @@ -126,8 +126,7 @@ sub show : Chained('load') PathPart('') { if ($model->can('load_related_info')) { if ($entity_type eq 'artist') { - my $lang = $c->stash->{current_language} // 'en'; - $model->load_related_info($entities, $lang); + $model->load_related_info($entities, $c->current_language); } else { $model->load_related_info(@$entities); } diff --git a/lib/MusicBrainz/Server/Controller/Search.pm b/lib/MusicBrainz/Server/Controller/Search.pm index ad630fd3f94..eca7b7786ff 100644 --- a/lib/MusicBrainz/Server/Controller/Search.pm +++ b/lib/MusicBrainz/Server/Controller/Search.pm @@ -125,8 +125,7 @@ sub direct : Private my @entities = map { $_->entity } @$results; if ($type eq 'artist') { - my $lang = $c->stash->{current_language} // 'en'; - $c->model('Artist')->load_related_info(\@entities, $lang); + $c->model('Artist')->load_related_info(\@entities, $c->current_language); } elsif ($type eq 'editor') { $c->model('Editor')->load_preferences(@entities); @@ -245,15 +244,13 @@ sub do_external_search { my $query = $opts{query}; my $type = $opts{type}; - my $lang = $c->stash->{current_language} // 'en'; - my $search = $c->model('Search'); my $ret = $search->external_search($type, $query, $limit, $page, $advanced, - $lang); + $c->current_language); if (exists $ret->{error}) { diff --git a/lib/MusicBrainz/Server/Controller/Tag.pm b/lib/MusicBrainz/Server/Controller/Tag.pm index 7d535b64946..24cd4e612c0 100644 --- a/lib/MusicBrainz/Server/Controller/Tag.pm +++ b/lib/MusicBrainz/Server/Controller/Tag.pm @@ -6,7 +6,7 @@ use HTTP::Status qw( :constants ); extends 'MusicBrainz::Server::Controller'; -use MusicBrainz::Server::Data::Utils qw( boolean_to_json type_to_model ); +use MusicBrainz::Server::Data::Utils qw( boolean_to_json ); use MusicBrainz::Server::Constants qw( %ENTITIES entities_with ); use MusicBrainz::Server::ControllerUtils::JSON qw( serialize_pager ); use MusicBrainz::Server::Entity::Util::JSON qw( to_json_object ); @@ -90,9 +90,19 @@ sub show : Chained('load') PathPart('') tag => $tag->TO_JSON, taggedEntities => { map { - my ($entities, $total) = $c->model(type_to_model($_))->tags->find_entities( + my $entity_properties = $ENTITIES{$_}; + my $model = $c->model($entity_properties->{model}); + + my ($entity_tags, $total) = $model->tags->find_entities( $tag->id, 10, 0); - $c->model('ArtistCredit')->load(map { $_->entity } @$entities); + + my @entities = map { $_->entity } @$entity_tags; + $model->load_aliases(\@entities, $c->current_language) + if $model->can('load_aliases'); + $c->model('ArtistCredit')->load(@entities); + + $c->model('ArtistCredit')->load(@entities) + if $entity_properties->{artist_credits}; ("$_" => { count => $total, @@ -100,7 +110,7 @@ sub show : Chained('load') PathPart('') count => $_->{count}, entity => $_->{entity}->TO_JSON, entity_id => $_->{entity_id}, - }, @$entities], + }, @$entity_tags], }) } entities_with('tags'), }, @@ -116,11 +126,14 @@ for my $entity_type (entities_with('tags')) { my $method = sub { my ($self, $c) = @_; + my $model = $c->model($entity_properties->{model}); my $entity_tags = $self->_load_paged($c, sub { - $c->model($entity_properties->{model})->tags->find_entities($c->stash->{tag}->id, shift, shift); + $model->tags->find_entities($c->stash->{tag}->id, shift, shift); }); + my @entities = map { $_->entity } @$entity_tags; - $c->model('ArtistCredit')->load(map { $_->entity } @$entity_tags) if $entity_properties->{artist_credits}; + $model->load_aliases(\@entities, $c->current_language) if $model->can('load_aliases'); + $c->model('ArtistCredit')->load(@entities) if $entity_properties->{artist_credits}; $c->stash( current_view => 'Node', component_path => 'tag/EntityList', diff --git a/lib/MusicBrainz/Server/Controller/User/SubscriptionsRole.pm b/lib/MusicBrainz/Server/Controller/User/SubscriptionsRole.pm index 3af71f87e5e..134cff30a85 100644 --- a/lib/MusicBrainz/Server/Controller/User/SubscriptionsRole.pm +++ b/lib/MusicBrainz/Server/Controller/User/SubscriptionsRole.pm @@ -38,9 +38,13 @@ role { unless $user->preferences->public_subscriptions; } + my $model = $c->model(type_to_model($type)); + my $lang = $c->stash->{current_language} // 'en'; my $entities = $self->_load_paged($c, sub { - $c->model(type_to_model($type))->find_by_subscribed_editor($user->id, shift, shift); + $model->find_by_subscribed_editor($user->id, shift, shift); }); + $model->load_aliases($entities, $lang) if $model->can('load_aliases'); + my %extra_props; if ($type eq 'collection') { diff --git a/lib/MusicBrainz/Server/Controller/WS/js/Role/Autocompletion/PrimaryAlias.pm b/lib/MusicBrainz/Server/Controller/WS/js/Role/Autocompletion/PrimaryAlias.pm index d171accf129..33c9cdf1da3 100644 --- a/lib/MusicBrainz/Server/Controller/WS/js/Role/Autocompletion/PrimaryAlias.pm +++ b/lib/MusicBrainz/Server/Controller/WS/js/Role/Autocompletion/PrimaryAlias.pm @@ -21,7 +21,7 @@ role { return map +{ entity => $_, aliases => $aliases->{$_->id}, - current_language => $c->stash->{current_language} // 'en', + current_language => $c->current_language, }, $self->$orig($c, @entities); }; }; diff --git a/lib/MusicBrainz/Server/Data/Artist.pm b/lib/MusicBrainz/Server/Data/Artist.pm index 0b632236b3f..a4831883638 100644 --- a/lib/MusicBrainz/Server/Data/Artist.pm +++ b/lib/MusicBrainz/Server/Data/Artist.pm @@ -14,7 +14,6 @@ use MusicBrainz::Server::Data::Utils qw( add_partial_date_to_row conditional_merge_column_query contains_string - find_best_primary_alias hash_to_row load_subobjects merge_table_attributes @@ -492,24 +491,10 @@ sub load_related_info { my $c = $self->c; my @artists = @{$artists_ref}; + $self->load_aliases($artists_ref, $user_lang); $c->model('ArtistType')->load(@artists); $c->model('Gender')->load(@artists); $c->model('Area')->load(@artists); - - # Load and save aliases so Controller::Artist::show can use them later. - my $artist_aliases = $c->model('Artist')->alias->find_by_entity_ids( - map { $_->id } @artists, - ); - my @all_aliases = map { @$_ } values %$artist_aliases; - $c->model('Artist')->alias_type->load(@all_aliases); - for my $artist (@artists) { - my @aliases = @{ $artist_aliases->{$artist->id} }; - $artist->aliases(\@aliases); - if (defined $user_lang) { - my $best_alias = find_best_primary_alias(\@aliases, $user_lang); - $artist->primary_alias($best_alias->name) if defined $best_alias; - } - } } sub load_meta diff --git a/lib/MusicBrainz/Server/Data/ArtistCredit.pm b/lib/MusicBrainz/Server/Data/ArtistCredit.pm index 6cd7f67784d..5a31239295f 100644 --- a/lib/MusicBrainz/Server/Data/ArtistCredit.pm +++ b/lib/MusicBrainz/Server/Data/ArtistCredit.pm @@ -80,6 +80,9 @@ sub load { my ($self, @objs) = @_; load_subobjects($self, 'artist_credit', @objs); + my $lang = $self->c->stash->{current_language} // 'en'; + my @artists = map { map { $_->artist } $_->artist_credit->all_names} @objs; + $self->c->model('Artist')->load_aliases(\@artists, $lang); } sub find_by_ids diff --git a/lib/MusicBrainz/Server/Data/Relationship.pm b/lib/MusicBrainz/Server/Data/Relationship.pm index f9b73f160e7..ac33ab374a3 100644 --- a/lib/MusicBrainz/Server/Data/Relationship.pm +++ b/lib/MusicBrainz/Server/Data/Relationship.pm @@ -439,6 +439,15 @@ sub load_entities my @series = values %{$data_by_type{'series'}}; $self->c->model('SeriesType')->load(@series); + + my $lang = $self->c->stash->{current_language} // 'en'; + + for my $type (keys %data_by_type) { + my $model = $self->c->model(type_to_model($type)); + next unless $model->can('load_aliases'); + my @entities = values %{$data_by_type{$type}}; + $model->load_aliases(\@entities, $lang); + } } sub _load_subset { diff --git a/lib/MusicBrainz/Server/Data/Role/Alias.pm b/lib/MusicBrainz/Server/Data/Role/Alias.pm index bb010d9e54a..c3cbbaf13db 100644 --- a/lib/MusicBrainz/Server/Data/Role/Alias.pm +++ b/lib/MusicBrainz/Server/Data/Role/Alias.pm @@ -3,7 +3,10 @@ use MooseX::Role::Parameterized; use namespace::autoclean; use MusicBrainz::Server::Data::Alias; -use MusicBrainz::Server::Data::Utils qw( type_to_model ); +use MusicBrainz::Server::Data::Utils qw( + find_best_primary_alias + type_to_model +); use Moose::Util qw( ensure_all_roles ); parameter 'type' => ( @@ -81,6 +84,25 @@ role return \%ret; }; + + method 'load_aliases' => sub { + my ($self, $entities_ref, $user_lang) = @_; + + my @entities = @{$entities_ref}; + my $entity_aliases = $self->alias->find_by_entity_ids( + map { $_->id } @entities, + ); + my @all_aliases = map { @$_ } values %$entity_aliases; + $self->alias_type->load(@all_aliases); + for my $entity (@entities) { + my @aliases = @{ $entity_aliases->{$entity->id} }; + $entity->aliases(\@aliases); + if (defined $user_lang) { + my $best_alias = find_best_primary_alias(\@aliases, $user_lang); + $entity->primary_alias($best_alias->name) if defined $best_alias; + } + } + }; }; diff --git a/lib/MusicBrainz/Server/Entity/Area.pm b/lib/MusicBrainz/Server/Entity/Area.pm index 04603479983..798c6442f8b 100644 --- a/lib/MusicBrainz/Server/Entity/Area.pm +++ b/lib/MusicBrainz/Server/Entity/Area.pm @@ -8,7 +8,8 @@ use MusicBrainz::Server::Entity::Util::JSON qw( to_json_array ); use List::AllUtils qw( first ); extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::DatePeriod', 'MusicBrainz::Server::Entity::Role::Relatable', diff --git a/lib/MusicBrainz/Server/Entity/Artist.pm b/lib/MusicBrainz/Server/Entity/Artist.pm index c7a632ca733..49b79af7a41 100644 --- a/lib/MusicBrainz/Server/Entity/Artist.pm +++ b/lib/MusicBrainz/Server/Entity/Artist.pm @@ -7,7 +7,8 @@ use MusicBrainz::Server::Entity::Types; use MusicBrainz::Server::Entity::Util::JSON qw( to_json_object ); extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::Area', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::DatePeriod', @@ -26,17 +27,6 @@ has 'sort_name' => ( isa => 'Str', ); -has 'aliases' => ( - is => 'rw', - isa => 'ArrayRef[MusicBrainz::Server::Entity::Alias]', - default => sub { [] }, -); - -has 'primary_alias' => ( - is => 'rw', - isa => 'Str', -); - has 'gender_id' => ( is => 'rw', isa => 'Int', @@ -94,7 +84,6 @@ around TO_JSON => sub { begin_area => to_json_object($self->begin_area), end_area => to_json_object($self->end_area), gender => to_json_object($self->gender), - $self->primary_alias ? (primaryAlias => $self->primary_alias) : (), begin_area_id => defined $self->begin_area_id ? (0 + $self->begin_area_id) : undef, end_area_id => defined $self->end_area_id ? (0 + $self->end_area_id) : undef, gender_id => defined $self->gender_id ? (0 + $self->gender_id) : undef, diff --git a/lib/MusicBrainz/Server/Entity/Event.pm b/lib/MusicBrainz/Server/Entity/Event.pm index b1130531b4d..24d58b73a49 100644 --- a/lib/MusicBrainz/Server/Entity/Event.pm +++ b/lib/MusicBrainz/Server/Entity/Event.pm @@ -5,7 +5,8 @@ use MusicBrainz::Server::Entity::PartialDate; use MusicBrainz::Server::Entity::Types; extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::DatePeriod', 'MusicBrainz::Server::Entity::Role::Rating', diff --git a/lib/MusicBrainz/Server/Entity/Genre.pm b/lib/MusicBrainz/Server/Entity/Genre.pm index 8ff57ccfb0b..87bd5156eb9 100644 --- a/lib/MusicBrainz/Server/Entity/Genre.pm +++ b/lib/MusicBrainz/Server/Entity/Genre.pm @@ -4,7 +4,8 @@ use Moose; use MusicBrainz::Server::Entity::Types; extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::Relatable'; diff --git a/lib/MusicBrainz/Server/Entity/Instrument.pm b/lib/MusicBrainz/Server/Entity/Instrument.pm index 3563d0d0a83..4600b8f040f 100644 --- a/lib/MusicBrainz/Server/Entity/Instrument.pm +++ b/lib/MusicBrainz/Server/Entity/Instrument.pm @@ -6,7 +6,8 @@ use MusicBrainz::Server::Translation::Instruments; use MusicBrainz::Server::Translation::InstrumentDescriptions; extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::Relatable', 'MusicBrainz::Server::Entity::Role::Taggable', diff --git a/lib/MusicBrainz/Server/Entity/Label.pm b/lib/MusicBrainz/Server/Entity/Label.pm index 969746c979c..e6cdc8748fd 100644 --- a/lib/MusicBrainz/Server/Entity/Label.pm +++ b/lib/MusicBrainz/Server/Entity/Label.pm @@ -6,7 +6,8 @@ use MusicBrainz::Server::Entity::PartialDate; use MusicBrainz::Server::Entity::Types; extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::Area', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::DatePeriod', diff --git a/lib/MusicBrainz/Server/Entity/Place.pm b/lib/MusicBrainz/Server/Entity/Place.pm index 2b2cd6f8edb..b9e306feeba 100644 --- a/lib/MusicBrainz/Server/Entity/Place.pm +++ b/lib/MusicBrainz/Server/Entity/Place.pm @@ -5,7 +5,8 @@ use MusicBrainz::Server::Entity::PartialDate; use MusicBrainz::Server::Entity::Types; extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::Area', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::DatePeriod', diff --git a/lib/MusicBrainz/Server/Entity/Recording.pm b/lib/MusicBrainz/Server/Entity/Recording.pm index e4c52effb38..332670d3266 100644 --- a/lib/MusicBrainz/Server/Entity/Recording.pm +++ b/lib/MusicBrainz/Server/Entity/Recording.pm @@ -11,7 +11,8 @@ use MusicBrainz::Server::Entity::Util::JSON qw( use List::AllUtils qw( uniq_by ); extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::ArtistCredit', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::Rating', diff --git a/lib/MusicBrainz/Server/Entity/Release.pm b/lib/MusicBrainz/Server/Entity/Release.pm index a635063108b..85f702b2328 100644 --- a/lib/MusicBrainz/Server/Entity/Release.pm +++ b/lib/MusicBrainz/Server/Entity/Release.pm @@ -11,7 +11,8 @@ use MusicBrainz::Server::Entity::Util::MediumFormat qw( combined_medium_format_n use MusicBrainz::Server::Entity::Util::JSON qw( to_json_array to_json_object ); extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::ArtistCredit', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::Relatable', diff --git a/lib/MusicBrainz/Server/Entity/ReleaseGroup.pm b/lib/MusicBrainz/Server/Entity/ReleaseGroup.pm index 535cede3ad1..c39fc86d241 100644 --- a/lib/MusicBrainz/Server/Entity/ReleaseGroup.pm +++ b/lib/MusicBrainz/Server/Entity/ReleaseGroup.pm @@ -10,7 +10,8 @@ use MusicBrainz::Server::Entity::Types; use MusicBrainz::Server::Entity::Util::JSON qw( to_json_object ); extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::ArtistCredit', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::Rating', diff --git a/lib/MusicBrainz/Server/Entity/Role/Alias.pm b/lib/MusicBrainz/Server/Entity/Role/Alias.pm new file mode 100644 index 00000000000..ab34c79c843 --- /dev/null +++ b/lib/MusicBrainz/Server/Entity/Role/Alias.pm @@ -0,0 +1,42 @@ +package MusicBrainz::Server::Entity::Role::Alias; +use Moose::Role; + +use MusicBrainz::Server::Entity::Types; + +has 'aliases' => ( + is => 'rw', + isa => 'ArrayRef[MusicBrainz::Server::Entity::Alias]', + default => sub { [] }, +); + +has 'primary_alias' => ( + is => 'rw', + isa => 'Str', +); + +around TO_JSON => sub { + my ($orig, $self) = @_; + + my $json = $self->$orig; + my $primary_alias = $self->primary_alias; + + if (defined $primary_alias) { + $json->{primaryAlias} = $primary_alias; + } + + return $json; +}; + +no Moose::Role; +1; + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2024 MetaBrainz Foundation + +This file is part of MusicBrainz, the open internet music database, +and is licensed under the GPL version 2, or (at your option) any +later version: http://www.gnu.org/licenses/gpl-2.0.txt + +=cut + diff --git a/lib/MusicBrainz/Server/Entity/Series.pm b/lib/MusicBrainz/Server/Entity/Series.pm index a2ea1701ffb..15fa1639350 100644 --- a/lib/MusicBrainz/Server/Entity/Series.pm +++ b/lib/MusicBrainz/Server/Entity/Series.pm @@ -4,7 +4,8 @@ use Moose; use MusicBrainz::Server::Entity::Types; extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::Relatable', 'MusicBrainz::Server::Entity::Role::Taggable', diff --git a/lib/MusicBrainz/Server/Entity/Work.pm b/lib/MusicBrainz/Server/Entity/Work.pm index 953a47cf5cd..a094d6c6468 100644 --- a/lib/MusicBrainz/Server/Entity/Work.pm +++ b/lib/MusicBrainz/Server/Entity/Work.pm @@ -7,7 +7,8 @@ use MusicBrainz::Server::Entity::Util::JSON qw( to_json_array to_json_object ); use aliased 'MusicBrainz::Server::Entity::WorkAttribute'; extends 'MusicBrainz::Server::Entity'; -with 'MusicBrainz::Server::Entity::Role::Annotation', +with 'MusicBrainz::Server::Entity::Role::Alias', + 'MusicBrainz::Server::Entity::Role::Annotation', 'MusicBrainz::Server::Entity::Role::Comment', 'MusicBrainz::Server::Entity::Role::Rating', 'MusicBrainz::Server::Entity::Role::Relatable', diff --git a/root/static/scripts/common/components/EntityLink.js b/root/static/scripts/common/components/EntityLink.js index 85376e01e90..8fc0b83ac2f 100644 --- a/root/static/scripts/common/components/EntityLink.js +++ b/root/static/scripts/common/components/EntityLink.js @@ -165,7 +165,6 @@ component EntityLink( | LinkTypeT | TrackT | ReleaseEditorTrackT, - hover as passedHover?: string, nameVariation as passedNameVariation?: boolean, showArtworkPresence: boolean = false, showCreditedAs: boolean = false, @@ -188,9 +187,17 @@ component EntityLink( const hasSubPath = nonEmpty(subPath); // $FlowIgnore[prop-missing] const comment = nonEmpty(entity.comment) ? ko.unwrap(entity.comment) : ''; + const entityName = ko.unwrap(entity.name); + const primaryAlias = (entity.entityType !== 'instrument' && + entity.entityType !== 'track' && + nonEmpty(entity.primaryAlias) && + entity.primaryAlias !== entityName) + ? entity.primaryAlias + : ''; + let content = passedContent; - let hover = passedHover; + let hover = ''; let nameVariation = passedNameVariation; let showDisambiguation = passedShowDisambiguation; let showIcon = passedShowIcon; @@ -211,18 +218,16 @@ component EntityLink( showDisambiguation = !hasCustomContent; } - if (entity.entityType === 'artist' && empty(hover)) { - hover = entity.sort_name + (comment ? ' ' + bracketedText(comment) : ''); - } - - if (showDisambiguation === 'hover') { - hover = empty(hover) - ? comment - : hover + ' ' + bracketedText(comment); + if (showDisambiguation === 'hover' || entity.entityType === 'artist') { + const sortName = entity.entityType === 'artist' ? entity.sort_name : ''; + const additionalName = nonEmpty(primaryAlias) ? primaryAlias : sortName; + hover = nonEmpty(additionalName) ? ( + nonEmpty(comment) ? ( + additionalName + ' ' + bracketedText(comment) + ) : additionalName + ) : comment; } - const entityName = ko.unwrap(entity.name); - /* * If we were asked to display the credited-as text explicitly, * display the entity name as the content instead. @@ -482,12 +487,6 @@ component EntityLink( />, ); } - const primaryAlias = - (entity.entityType !== 'track' && - nonEmpty(entity.primaryAlias) && - entity.primaryAlias !== entityName) - ? entity.primaryAlias - : ''; if (nonEmpty(comment) || nonEmpty(primaryAlias)) { parts.push(