Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

DataObject plural_name() Method Truncates 'e'?


4 Posts   239 Views


6 January 2014 at 10:49pm Community Member, 21 Posts

There is a method on DataObject which returns a 'best guess' plural name of you data object, see -

$name = $this->singular_name();
if(substr($name,-1) == 'e') $name = substr($name,0,-1);
else if(substr($name,-1) == 'y') $name = substr($name,0,-1) . 'ie';
return ucfirst($name . 's');

This is used by GridFields 'Link Existing' auto completer. I am confused by the nested if() in this method. I understand the purpose of truncating a 'y' and replacing with 'ies' e.g. Party -> Parties etc.

The first part of the if() checks to see if the name ends with 'e', if so it truncates it (and then proceeds to make it plural by adding 's')!

I cannot think of any good reason for this? Perhaps I am missing something but I do not see why this line of code exists? It is returning 'Carousel Slids' instread of 'Carousel Slides' for one of my data objects. Other incorrect examples it would return include:

- Tree = Tres
- Page = Pags
- Attribute = Attributs
- etc

I know I can solve this issue by adding a 'private static $plural_name = "Carousel Slides";' on my data object, but thats not the point, I am trying to understand if there is any logical reason for this line of code, or if it should be marked as a bug?

Any suggestions appreciated.




7 January 2014 at 12:41am Forum Moderator, 1091 Posts

Interesting :) I can see how this wouldn't work at all for other locales besides en_US !

I'm all for just returning the singular name, that is at least a valid name, even if not syntactically correct in the context. And maybe update the documentation about the importance of setting your own plural_name?



7 January 2014 at 1:33am Community Member, 21 Posts

Thanks for the reply Martimiz,

Out of pure curiosity can you give me some examples of how this does work for words in en_US locale?

I'm just trying to work out how truncating the 'e' is beneficial in any locale and am struggling to come up with any examples where it works?




7 January 2014 at 2:33am Forum Moderator, 1091 Posts

haha - no! I meant to agree with you on the e, and then go even further by saying that replacing an y for an ie might not always be a good idea in, say, Dutch :)