Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaRepresentation::displayTitle's $default parameter is used only if 'source' is empty #2108

Open
jajm opened this issue Oct 30, 2023 · 2 comments

Comments

@jajm
Copy link
Contributor

jajm commented Oct 30, 2023

Not sure if it's a bug. I'm talking about this method:

public function displayTitle($default = null, $lang = null)
{
$source = $this->source();
if (!$source) {
$source = $default;
}
return parent::displayTitle($source, $lang);
}

For a media created by file upload, or URL (and probably others) there will always be a "source", so the $default parameter will never be used for those media.

Shouldn't the source be used only if $default === null ?

@zerocrates
Copy link
Member

The idea here is to have "untitled" or similar only show up when we have nothing to use. Most uploaded files don't get given titles manually, so the fallback to the source gets used a lot, but we still want to pass a default so there's text like "[Untitled]" for those media that have no title and no source.

@jajm
Copy link
Contributor Author

jajm commented Dec 12, 2023

I'm probably missing something, but couldn't it be achieved by something like this:

$media->displayTitle( $media->source() )

as displayTitle returns "[Untitled]" when there is no title and $default === null

My use case is I want to display the "display title" (that is dcterms:title or the title property defined in the resource template) and if it doesn't exist I want something else than the source. I never want to display the source.
Is there a way to do this without duplicating the code of AbstractResourceEntityRepresentation::displayTitle ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants