Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Refactor how to get the entity or module name
Comment | File | Size | Author |
---|---|---|---|
#39 | 3169818-39.patch | 31.4 KB | liuchanggang |
#32 | 3169818-32.patch | 31.38 KB | liuchanggang |
Comments
Comment #2
liuchanggang CreditAttribution: liuchanggang commentedThis is just a test patch. Not ready for reveiw.
Comment #3
liuchanggang CreditAttribution: liuchanggang commentedComment #4
liuchanggang CreditAttribution: liuchanggang commentedThis is for test only.
Comment #5
liuchanggang CreditAttribution: liuchanggang commentedThis patch is ready for review. Thanks.
Comment #6
liuchanggang CreditAttribution: liuchanggang commentedComment #7
liuchanggang CreditAttribution: liuchanggang commentedComment #9
liuchanggang CreditAttribution: liuchanggang commentedComment #10
liuchanggang CreditAttribution: liuchanggang commentedComment #11
liuchanggang CreditAttribution: liuchanggang commentedComment #12
yas@liuchanggang
Thank you for the refactoring. Is there any reason why you put the convert methods into CloudService? Could we place the methods to
Drupal\cloud\Traits\CloudContentEntityTrait
?Comment #13
liuchanggang CreditAttribution: liuchanggang commentedComment #14
liuchanggang CreditAttribution: liuchanggang commented@yas
The methods are defined in CloudContentEntityTrait. However, there are a few places in .module files, where we can't call trait directly.
In that case, I called CloudServiceBase who USE CloudContentEntityTrait, so we can call those methods.
Let me know if there is better way to do.
Thanks
Chang
Comment #15
liuchanggang CreditAttribution: liuchanggang commentedComment #16
liuchanggang CreditAttribution: liuchanggang commentedRebased latest 3.x-dev.
Comment #17
liuchanggang CreditAttribution: liuchanggang commented@yas,
I made following changes.
1, added method getLowerCaseSpace() and updated code
2, changed method name to getCamelCase()
3, added comments
Thanks
Comment #18
yasThis can be replaced to
getModuleNameWhitespace()
.The method name can be
getUpperCaseWithWhitespace()
.Also, the method can be used in the following methods:
CloudContentEntityTrait::getShortEntityTypeNameWhitespace()
CloudContentEntityTrait::getShortEntityTypeNamePluralCamel()
CloudContentEntityTrait::getShortEntityTypeNameWhitespace()
K8sFormTrait
trait, too?strtolower()
is required?The method name can be
getCamelCaseWithWhitespace()
.CloudContentEntityTrait::getModuleNameWhitespace()
toCloudContentEntityTrait::getModuleNameWithWhitespace()
Comment #19
liuchanggang CreditAttribution: liuchanggang commented@yas,
I have updated code by your comments.
Thanks
Comment #20
liuchanggang CreditAttribution: liuchanggang commentedComment #21
liuchanggang CreditAttribution: liuchanggang commentedComment #22
liuchanggang CreditAttribution: liuchanggang commentedComment #23
yasIn this case, the method can be
changeUndersocreToWhiteSpace()
.The method name can be
getCamelCaseWithWhiteSpace()
.The method name can be
getCamelCaseWithoutWhiteSpace()
.Please change the method name to
getModuleNameWithWhiteSpace().
Comment #24
liuchanggang CreditAttribution: liuchanggang commented@yas,
I have updated the code. Thanks
Comment #25
yas@liuchanggang
Thank you for the update.
Those methods are overlapped in
CloudContentEntityTrait
. Could you removeK8sFormTrait
by aggregating those method? In that case, please consider thegetShortEntityTypeNameUnderscore()
as more generic function.On second thought, can you change the method name to
convertUndersocreToWhiteSpace()
?Comment #26
liuchanggang CreditAttribution: liuchanggang commented@yas,
Thanks for insight. I have updated the code.
Comment #27
liuchanggang CreditAttribution: liuchanggang commentedComment #28
yas@liuchanggang
Thank you for the update. In my comment #26,
What about this refactoring? (Could you remove
K8sFormTrait
by aggregating those method? In that case, please consider thegetShortEntityTypeNameUnderscore()
as more generic function.)Comment #29
liuchanggang CreditAttribution: liuchanggang commented@yas,
Thanks for reviewing. I misunderstood that line.
I just found that K8sFormTrait is not used anywhere in code base and all functions in K8sFormTrait have mirrors in CloudContentEntityTrait.
I have removed K8sFormTrait. Now all valid functions are in CloudContentEntityTrait.
Comment #30
yas@liuchanggang
Thank you for the update. It looks good to me now. We need the test cases for the additional methods but we should create another issue.
@baldwinlouie
What do you think?
Comment #31
baldwinlouie CreditAttribution: baldwinlouie commented@liuchanggang,
Thank you for the patch. I have the following comments.
There is a typo in underscore
Do you think
lcfirst
should be an option for thegetCamelCaseWithoutWhiteSpace
method? That way, it can be reused in other places in the future.Comment #32
liuchanggang CreditAttribution: liuchanggang commented@baldwinlouie @yas,
Thanks for insight. I have done following changes
Fixed underScore typo
Process lcfirst() in one function
Whitespace in one word.
Comment #33
yas@liuchanggang
Thank you for the update. It looks good to me now.
@baldwinlouie
What do you think?
Comment #34
yasComment #35
baldwinlouie CreditAttribution: baldwinlouie commented@yas and @liuchanggang,
Looks good to me.
Comment #36
yas@baldwinlouie
Thank you for your review.
@liuchangchang
Could you please create the patch for
8.x-1.x
and8.x-2.x
?Comment #37
yasComment #38
liuchanggang CreditAttribution: liuchanggang commentedThis patch is adjusted for 8.x-1.x and 8.x-2.x Thanks
Comment #39
liuchanggang CreditAttribution: liuchanggang commentedComment #40
liuchanggang CreditAttribution: liuchanggang commentedComment #41
yas@liuchanggang
Thank you for the update. I'll merge the patch to
8.x-1.x
,8.x-2.x
and3.x
and close this issue asFixed
.Comment #45
yas