Omitting singular_name in Contenttypes breaks URL generation during Record creation #823

Closed
GawainLynch opened this Issue Jan 10, 2014 · 14 comments

Comments

Projects
None yet
6 participants
Owner

GawainLynch commented Jan 10, 2014

Some words (I can only speak for how they are used in English), have the same plural as singular. e.g. "multimedia", "news", "sheep" & "moose".

Creating a content such as:

multimedia:
    name: Multimedia
    singular_name: Multimedia

Will give the error:

The name and singular_name for 'multimedia' are the same (Multimedia). Please edit contenttypes.yml, and make them distinct.

Whereas, if the singular_name variable is omitted, a blank URL stub is generated when a new Record is created with that Contenttype.

Owner

bobdenotter commented Jan 10, 2014

I've bumped into this once or twice as well. Although, mostly with "news" or "media".. I've never tried to create a contenttype for "sheep". ;-)

I'm not sure yet how we should fix this. The reason that Bolt complains about it, is to prevent the routes from getting confused:

http://example.org/pages - an overview listing of pages
http://example.org/page/foo - a specific page, identified by 'foo'

If we allow the singular and plural version to be the same, these routes would get messed up. To be specific:

screen shot 2014-01-10 at 17 22 28

Suggestions how we should fix this?

Owner

GawainLynch commented Jan 10, 2014

I've never tried to create a contenttype for "sheep". ;-)

All manner of laughter and further jokes went through my head reading this late on a Friday afternoon!

I'm only a day into reading Bolt documentation and code, so an immediate suggestion is beyond me. Especially considering that the above is also already mentioned in the "Templates and routing" document page (it's Friday) ;-)

Having said that and further thinking out aloud, contentlink and contentlisting theoretically should still somehow route separately as they may be similar, but not identical. But I was a victim of reading the WordPress codebase, so I am still recovering.

However, others might have better insight.

Contributor

rarila commented Jan 10, 2014

I also had this problem (with german words). I "solved" it by using the english words for the contentypes and some german routing that translated to the correspondending datatype. In another case I used "news" and "newsitem".

But I don't know why this could confuse the routes anyway. Without knowing anything about the internals of routing some simple regex would solve the problem:

http://example.org/sheep -> "/sheep$%" an overview listing of sheep
http://example.org/sheep/shaun -> "/sheep/(?<slug>.+)$%" - a specific page, identified by 'sheep'

Simply said, if the URL ends with the contenttype then listing is selected and if the contenttype is followed by an "selector" the selected item is displayed. Am I overseeing here something?

Contributor

CoolGoose commented Jan 13, 2014

Why don't we think it "rest" like
so it's /pages for all of the item and /pages/ means we want a specifc item.
Adding query strings /pages?page=1 will keep it on /pages with the whole listing,

PS:
I'm an idiot, i was meaning exactly what @rarila said

Owner

bobdenotter commented Jan 14, 2014

I've looked into this a bit more.. If we decide that we will allow 'slug' and 'singular_slug' to be the same, we need to fix the routing. Not just for the frontend, but also for the backend. So, it's slightly more work than just fixing routing.yml, but it should be do-able.

I've bumped into this once or twice as well. Although, mostly with "news" or "media".. I've never tried to create a contenttype for "sheep". ;-)

@bobdenotter : how did you manage to solve this problem ?
I want to name my "News Item" -> News, because I want the path to be : foo.com/news/title-news-slug (for the SEO, "newsitem" is not very clean...)
But when I go to foo.com/news, I have an error page.

And there is another problem : we don't have any hand on the "plural_name". (or maybe yes and I didn't see it yet ! :) ). And for some words in french :
In english : animal -> animals.
In french : animal -> animaux (journal -> journaux, cheval (horse) -> chevaux...)

Is there a way to fix theses two problems ?

Owner

bobdenotter commented Feb 7, 2014

Well, turns out this was relatively easy to fix. With the above changes, you can now have a slug and singular_slug that are the same. Like 'news'. Or 'sheep'. :-)

Links like example.org/news and example.org/news/foo both work with the expected results. So, I'm closing this issue.

@WilliamVercken I think your other problem is more related to multi-lingual content than the actual contenttypes, right? You can define the slug seperate from the name, maybe that helps:

cafes:
  slug: cafes
  name: Cafés
  singular_slug: cafe
  singular_name: Café

bobdenotter closed this Feb 7, 2014

Oh, I didn't know that there was that option !
So, it means that I can have :

/article/slug-article-1 => article-1
/article/ (still singular) => list of articles

?

Owner

bobdenotter commented Feb 7, 2014

Yes, you can do that now (after the changes i committed earlier this afternoon. ;-) )

Great news/sheep !
These two issues were crucial for my project... I had to considering others cms (drupal 8 alpha... I really want to use twig :) ), but now that you solved this I can return back to Bolt !

Owner

GawainLynch commented Feb 7, 2014

Excellent, thank you yet again @bobdenotter

Contributor

rarila commented Feb 7, 2014

Great!
I think we should dump the kitchensink example in favour of a sheep example and perhaps create a sheep named Bolty as mascot! ;-))

Owner

GawainLynch commented Feb 7, 2014

I can not tell you how much I truly love this idea, @rarila!

I, too, am very happy that this is now the case. I can finally restructure my URL tree. Thanks, @bobdenotter!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment