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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

DataObject plural_name() Method Truncates 'e'?


Go to End


4 Posts   866 Views

Avatar
HARVS1789UK

Community Member, 31 Posts

6 January 2014 at 10:49pm

There is a method on DataObject which returns a 'best guess' plural name of you data object, see - http://api.silverstripe.org/3.0/source-class-DataObject.html#659-676

$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.

Cheers,

HARVS1789UK

Avatar
martimiz

Forum Moderator, 1391 Posts

7 January 2014 at 12:41am

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?

Martine

Avatar
HARVS1789UK

Community Member, 31 Posts

7 January 2014 at 1:33am

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?

Cheers,

HARVS1789UK

Avatar
martimiz

Forum Moderator, 1391 Posts

7 January 2014 at 2:33am

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 :)