Introduction:

Note: This issue is is only meant for planning / sign-offs. Any work or issues will happen in child issues : please add them here!

This was originally a stand-alone issue but was converted to a [Meta] issue. See "Original Issue Description" for the original issue contents reported by @kalinchernev.

Sub-issues:

Original Issue Description:

  • Fix code formatting
  • Remove deprecated functions that are converted to methods
  • Remove unnecessary code

Comments

kalinchernev created an issue. See original summary.

mh86’s picture

Hi Kalin,

thanks for pushing your code. I was just reviewing it (http://cgit.drupalcode.org/taxonomy_manager/commit/?h=improvement/262440...).

There is one "code style" I would not change, although I know PHPStorm does that automatically for you:

-          TaxonomyManagerTree:self::getFirstPath($term_to_expand, $list);
+          TaxonomyManagerTree:
+          self::getFirstPath($term_to_expand, $list);

or

-        $term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($tid);
+        $term = \Drupal::entityTypeManager()
+          ->getStorage('taxonomy_term')
+          ->load($tid);

So in your version every method call gets a separate line. I think it makes the code longer (more lines), and as long as the single-line-statement is not far too long, also more difficult to read. Furthermore core uses the single-line statement too, as far as I can see.

Apart from that, everything looks good :) Thanks a lot! And don't wait to merge it into the main branch, otherwise you might have to fix conflicts with my commits in the meanwhile ;)

mh86’s picture

Apart from the code style itself, I found some other areas we should address

  • Class names: I think we do not have to prefix everything with TaxonomyManager, as we have our own namespace. Before we change anything in code we can discuss class names here.
  • Paths in routes: currently it's taxonomy_manager/..., probably taxonomy-manager/... is cleaner. (from underscore to dash)
  • Directory structure: I use js/custom/tree.js and js/custom/termData.js. As there is no other code anymore (like the fancytree library), probably it's better to remove the 'custom' folder and move the files just to 'js/'
  • Complete code documentation in general (methods, parameters, etc.)
  • Verify code via code sniffer: http://pareview.sh/
kalinchernev’s picture

Hi Matthias, thanks for your review!

I didn't notice that PHPStorm is putting the chained methods on new lines. I fixed them and merged back to the main branch. For cases of many chained methods, I broke them down to smaller steps to be more readable.
During the fixes, I left taxonomy_manager_voc_list method intact (didn't convert to lowerCamel as required), everything breaks and I don't know how to debug/solve the issue in D8 for now... In the past I left it intact on purpose of easy reference to existing code. To be changed before release.

Class names - I agree, it will simplify things. Few ideas:
- TaxonomyManagerController could be just Main and taxonomy_manager_voc_list could be maybe just list, then the route will result in _controller: '\Drupal\taxonomy_manager\Controller\Main::list'. Could also be Vocabulary as there's no much there right now. Vocabulary is more abstract and will be better fit if we would provide basic operations on vocabularies. Not sure whether if it's ok to skip the Controller in the end when it's under Controller folder.
- TaxonomyManagerSubTreeController -> SubTree or SubTreeController
- TaxonomyManagerTree -> Tree or TreeElement
- TaxonomyManagerAdmin -> AdminForm
- TaxonomyManagerForm -> TreeForm
- TaxonomyManagerHelper - this might end up being replaced/moved to more specific places in classes that uses them. And the methods are having the old function names still to keep the track, but should be different.

Paths in routes - yes, makes sense.

Directory structure - yes, and remove old/ in addition?

Documentation and CS - yes, absolutely. I'd love to do that continuously.

mh86’s picture

Thanks for pushing your changes, they look good :)

Regarding the class naming, before we change anything I will do some more research too, see if there is some documentation on class naming conventions and ask others. My ideas are similar to yours and I would also add the type (Controller / Element / Form / ...) at the end of the class name, like TreeElement (so you immediately know this class is about a form element)

For the rest, feel free to directly push your changes to the main branch.

@Directory structure - yes, and remove old/ in addition?
-> Yes, remove the old stuff. Then it's also easier to use http://pareview.sh/

mh86’s picture

Regarding the class naming, this is the documentation I was able to find:
https://www.drupal.org/node/2156625
https://www.drupal.org/node/1353118

  • kalinchernev committed 158a469 on 8.x-1.x
    Issue #2624404: Major update removing old js files.
    

kalinchernev’s picture

Hi, I thank you! :)
Few updates have been pushed regarding this topic:
- js files reorganized
- 2 controllers refactored
Please run `drush cr` :)

mh86’s picture

Thanks for the updates!

Regarding the class naming, also talked to klausi, so let's keep them short (without TaxonomyManager in general, as we have the namespace), but still it should be clear what it does, so just "Main" might be too generic.

My thoughts on naming:
src

  • Controller
    • VocabularyListController (currently MainController, but IMO too general)
    • SubTreeController
  • Element
    • TreeElement
  • Form
    • SettingsForm (currently TaxonomyManagerAdmin)
    • TaxonomyManagerForm / ManagerForm / VocabularyForm / ... ? (not sure for this one)
    • AddTermsForm
    • DeleteTermsForm
    • MoveTermsForm
    • ExportTermsForm
  • TaxonomyManagerHelper (lets leave the name for this one for the moment)

What do you think?

kalinchernev’s picture

Hi Matthias, yes, sounds good.

  • VocabularyListController -> it's ok, I would be ok as well with VocabularyController
  • TaxonomyManagerForm -> I was thinking about TreeForm yesterday, maybe it will make the relation to TreeElement more implicit? Otherwise, TaxonomyManagerForm as it is now sounds ok for me as it's eventually the essence of the project and "deserves" to be so concrete? :)
  • AddTermsForm -> yes, I think it's better than CreateTerms
  • ImportTermsForm will be logically the last form for now
  • TaxonomyManagerHelper -> yes, sure
mh86’s picture

VocabularyListController -> it's ok, I would be ok as well with VocabularyController

Maybe VocabularyOverviewController?

Otherwise, TaxonomyManagerForm as it is now sounds ok for me as it's eventually the essence of the project and "deserves" to be so concrete? :)

Agreed :)

kalinchernev’s picture

VocabularyOverviewController

Yes, looks/sounds good :)
I'll continue on the refactoring in the next days as agreed so far, but let me know if you come up with better ideas in the meantime.

JacobSanford’s picture

I opened a separate ticket for array format cleanup:

#2959667: Convert use of array() to short form.

JacobSanford’s picture

Status: Active » Needs work
JacobSanford’s picture

As mentioned in #2960831: Migrate from drupal_set_message(), this issue is quite broad in scope. Since all patches have been committed in THIS issue, I feel converting into a Meta issue would increase clarity and help get the cleanup moving in a more orderly manner.

JacobSanford’s picture

Title: Code cleanup migrating to Drupal 8 version » [Meta] Code cleanup migrating to Drupal 8 version
JacobSanford’s picture

Issue summary: View changes
VladimirAus’s picture

Assigned: kalinchernev » Unassigned
Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.