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

Backlink not working #793

Closed
fritzmg opened this issue Apr 10, 2015 · 5 comments
Closed

Backlink not working #793

fritzmg opened this issue Apr 10, 2015 · 5 comments
Assignees
Labels
bug A bug! A bug! Fast, squish it! frontend This seems to be a bug in the frontend
Milestone

Comments

@fritzmg
Copy link
Contributor

fritzmg commented Apr 10, 2015

Problem description

Assume you have two MetaModels, e.g. mm_items and mm_categories or something similar. Assume you want to create a frontend list that shows you all items of a specific category. Furthermore you have a detail page, where you show the details of a single item. Now assume you want the jumpTo link of that single item to point back towards the item list of the category. In theory this should be possible, by inserting the specific {{link_url::*}} for the jumpTo page of the category list and selecting the correct filter (which filters the items by category). This is also explained in the german Contao Wiki (MetaModels Beispiel 2 - Detailansicht erstellen).

However, this does not seem to work currently. Assume your item list for a specific category is under the following URL:

category/lorem-ipsum.html

Where lorem-ipsum is the alias of the category and "Lorem ipsum" would be the name of the category. This should also be the URL where the back-link points to in the detail list view of a specific item. However, the actual generated URL will be the following:

category/Lorem ipsum.html

So instead of using the alias, the system erroneously retrieves the name of the category.

Possible cause

I debugged through the code a little bit and the problem seems to originate from MetaModels\Filter\Setting::generateFilterUrlFrom.

public function generateFilterUrlFrom(IItem $objItem, IRenderSettings $objRenderSetting)
{
    $objAttribute = $this->getMetaModel()->getAttributeById($this->get('attr_id'));
    if ($objAttribute) {
        // TODO: shall we omit returning of empty values?
        $strResult = $objAttribute->getFilterUrlValue($objItem->get($objAttribute->getColName()));var_dump(get_class($objAttribute));
        return array($this->getParamName() => $strResult);
    }

    return array();
}

More specifically: the function call $objAttribute->getFilterUrlValue(...) actually calls MetaModels\Attribute\Base::getFilterUrlValue, which simply does

public function getFilterUrlValue($varValue)
{
    // We are parsing as text here as this was the way before this method was implemented. See #216.
    $arrResult = $this->parseValue(array($this->getColName() => $varValue), 'text');

    return urlencode($arrResult['text']);
}

i.e. it returns the user defined textual representation of the foreign column - which is the category's name in this case. Instead the call should probably go to MetaModels\Attribute\Select\Select::getFilterUrlValue which, I am guessing, would return the correct value of the alias field. So maybe this is just a polymorphism problem or something? Because the function $this->getMetaModel()->getAttributeById($this->get('attr_id')) actually returns a MetaModels\Attribute\Select\MetaModelSelect object and not a MetaModels\Attribute\Select\Select object.

References

Backlink funktioniert nicht
MetaModels - erste Versuche - im Wiki

@tim-bec tim-bec added this to the 2.1.0 milestone Apr 14, 2015
@discordier
Copy link
Member

The analysis is correct. Well done @fritzmg. There should be in fact an separate MetaModelSelect::getFilterUrlValue().

@discordier discordier added bug A bug! A bug! Fast, squish it! frontend This seems to be a bug in the frontend easy pick This issue is a good start for beginners labels Apr 15, 2015
@zonky2
Copy link
Contributor

zonky2 commented Jun 10, 2016

@fritzmg it´s possible to you to make a PR?

Thanks

@fritzmg
Copy link
Contributor Author

fritzmg commented Jun 10, 2016

Sorry, it has been a long time since I last used MetaModels, I don't know if I would ever get around to it.

@zonky2
Copy link
Contributor

zonky2 commented Jun 10, 2016

What a pity!

@zonky2 zonky2 modified the milestones: 2.1.0, 2.2.0 Mar 14, 2018
@zonky2 zonky2 removed the easy pick This issue is a good start for beginners label Jul 2, 2020
@zonky2
Copy link
Contributor

zonky2 commented May 24, 2021

Checked in MM 2.1 - maybe this already works in MM 2.1

Filtered with domain.tld/de/listenausgabe/division/produktion

FireShot Pro Webpage Screenshot #386 - 'Listenausgabe - MM 2_2 - DE' - mm
Link "Details": domain.tld/de/listenausgabe/details/doe-john

FireShot Pro Webpage Screenshot #387 - 'Details - MM 2_2 - DE' - mm

Link "Details": domain.tld/de/listenausgabe/division/produktion

@zonky2 zonky2 closed this as completed May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug! A bug! Fast, squish it! frontend This seems to be a bug in the frontend
Projects
None yet
Development

No branches or pull requests

4 participants