add getName method to element types #4211
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.