Giter VIP home page Giter VIP logo

Comments (9)

weitzman avatar weitzman commented on August 30, 2024 1

I think the entity type is a reasonable improvement. I'm dealing with a jumble of entity types in same folder right now.

from drupal-code-generator.

weitzman avatar weitzman commented on August 30, 2024

A bit of a stretch to appeal to "established best practices". Slight -1 from me. I like using a new namespace here. Its easier to delete the dir and regenerate classes.

from drupal-code-generator.

Chi-teck avatar Chi-teck commented on August 30, 2024

Entity Bundle Classes is still a pretty new thing so I doubt that best practices are already established on this. Personally I have no opinion about that. So I am ok to change this If considerable number of people request it.

from drupal-code-generator.

drubb avatar drubb commented on August 30, 2024

Personally, I'm fine with the new namespace. But e.g. Drupal Core doesn't use it this way, e.g. in core/modules/system/tests/modules/entity_test_bundle_class/src/Entity:

<?php

namespace Drupal\entity_test_bundle_class\Entity;

use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\entity_test\Entity\EntityTest;

/**
 * The bundle class for the bundle_class bundle of the entity_test entity.
 */
class EntityTestBundleClass extends EntityTest {
  ...
}

from drupal-code-generator.

drubb avatar drubb commented on August 30, 2024

Currently doing some work on a pretty large codebase, I'd even introduce one more level for the namespace: the entity type!

So we'd end up with something like Drupal/mymodule/entity/Bundle/media or Drupal/mymodule/entity/Bundle/node

Really, it's totally opinionated - but what could be a reasonable default?

from drupal-code-generator.

Chi-teck avatar Chi-teck commented on August 30, 2024

I wonder if "Bundle" suffix was a good idea. In Drupal bundles are configuration entities. So "ArticleBundle" sounds like a bundle configuration entity for nodes.

from drupal-code-generator.

 avatar commented on August 30, 2024

I wonder if "Bundle" suffix was a good idea. In Drupal bundles are configuration entities. So "ArticleBundle" sounds like a bundle configuration entity for nodes.

I would now drop them in a Drupal/<modulename>/Entity/<EntityTypeName> namespace. Otherwise it would be confusing to drop multiple entity bundle classes of different entity types in the same folder. Then you would have to open the file before being able to check the entity type by checking the class extension.

If every which way the editor provided class jumping into this file I would say the namespace didn't matter. But since entity bundle classes provide public getFunctions to twig files it's still useful to provide a more descriptive namespace for the developer to find the right file.

I think as well that the Bundle suffix of the class name is not needed.

from drupal-code-generator.

DieterHolvoet avatar DieterHolvoet commented on August 30, 2024

I have been using entity bundle classes for about 4 years now, even before it landed in Drupal core. I always stuck to the Drupal/<modulename>/Entity/<EntityTypeName> convention.

from drupal-code-generator.

Chi-teck avatar Chi-teck commented on August 30, 2024

The generator has been updated in 3.x branch.

  1. "All" option has been removed. Symfony has fixed a bug with autocompletion for mutly-select questions. So
    that it's much easier now to select multiple bundles. That also made the implementation a bit simpler.
  2. Namespace for generated classes has been changed to Drupal/<modulename>/Entity/<EntityTypeName> as suggested above.
  3. Bundle suffix has been removed from suggested bundle class names.
  4. Added Base suffix to suggested name for base bundle class.
$ ./vendor/bin/dcg entity:bundle-class 

 Welcome to bundle-class generator!
––––––––––––––––––––––––––––––––––––

 Module machine name:
 ➤ example

 Entity type:
  [ 1] Custom block
  [ 2] Comment
  [ 3] Contact message
  [ 4] File
  [ 5] Custom menu link
  [ 6] Content
  [ 7] URL alias
  [ 8] Shortcut link
  [ 9] Taxonomy term
  [10] User
 ➤ Content

 Bundles, comma separated:
  [1] Article
  [2] Basic page
 ➤ 1,2

 Class for "Article" bundle [Article]:
 ➤ 

 Class for "Basic page" bundle [Page]:
 ➤ 

 Use a base class? [No]:
 ➤ Yes

 Base class [NodeBase]:
 ➤ 

 The following directories and files have been created or updated:
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
 • example.module
 • src/Entity/Node/Article.php
 • src/Entity/Node/NodeBase.php
 • src/Entity/Node/Page.php

Thank you all for feedback.

from drupal-code-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.