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

add getName method to element types #4211

Merged
merged 4 commits into from
May 8, 2019
Merged

add getName method to element types #4211

merged 4 commits into from
May 8, 2019

Conversation

sbatson5
Copy link

@sbatson5 sbatson5 commented May 3, 2019

What's in this PR?

I'm currently learning craft while building a plugin for my company. Working with elements, there have been a few things I've run into that haven't seemed immediately obvious. When editing elements via the provided template:

{% extends '_layouts/elementindex' %}
{% set title = 'Products' %}
{% set elementType = 'ns\\prefix\\elements\\Product' %}

I noticed the first column wasn't showing the id as I expected. It wasn't until I stumbled on fef75e1#diff-0cf13e6e9757a569110e508f362ad1a9R482
that I realized I could update __toString() to return what I wanted.

This felt non-obvious and I felt like I was potentially overwriting a method that could be used elsewhere. So, I thought it would be nice to have a convenience method getLinkText() (happy to rename it if people feel this name is no good).

This method would just return $this->__toString() by default, so it shouldn't break any existing plugins that overwrite __toString() already to accomplish this. But it would allow us to update just that text without overwriting the method we get from the PHP base class.

Copy link
Member

@brandonkelly brandonkelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, but please see my comments. Also, this PR should be made for the 3.2 branch rather than develop, as we wouldn’t introduce a change like this in a 3.1.x build release.

src/base/Element.php Outdated Show resolved Hide resolved
src/base/ElementInterface.php Outdated Show resolved Hide resolved
@sbatson5 sbatson5 changed the base branch from develop to 3.2 May 8, 2019 12:49
@sbatson5
Copy link
Author

sbatson5 commented May 8, 2019

Thanks @brandonkelly! Updated and targets to 3.2

@sbatson5 sbatson5 changed the title add getLinkText method to element types add getName method to element types May 8, 2019
@brandonkelly brandonkelly merged commit 9828bf1 into craftcms:3.2 May 8, 2019
@brandonkelly
Copy link
Member

Thanks!

@sbatson5 sbatson5 deleted the add-getLinkText-method-to-elements branch May 8, 2019 13:42
brandonkelly added a commit that referenced this pull request May 8, 2019
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

Successfully merging this pull request may close these issues.

2 participants