EntityBundleInfo->bundleInfo does not document the internal structure of the bundle info array. After #2712367: Extend EntityTypeBundleInfoInterface's docblocks and make them more explicit has been committed, we can easily reference the API documentation on this property.

Issue fork drupal-2712379

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Xano created an issue. See original summary.

xano’s picture

Status: Active » Needs review
StatusFileSize
new626 bytes
dawehner’s picture

Component: entity system » documentation
Status: Needs review » Reviewed & tested by the community

Nice, this improves the documentation!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  /**
   * Get the bundle info of all entity types.
   *
   * @return array
   *   An array of all bundle information.
   */
  public function getAllBundleInfo();

I dunno perhaps we should improve this at the same time because tbh this is not much better than no documentation.

xano’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

@Xano imo this issue should just be merged into that one that. It's all the same scope to me.

xano’s picture

I've been told off for scope creep when it comes to documentation several times now, and I fail to see consistency in the reasons I've been given. These issues actually come from another in which that happened. I don't feel much for doing it differently again, to be honest.

xjm’s picture

Title: Improve EntityBundleInfo->bundleInfo's docblock » Improve entity bundle info return value docs and consolidate them in one place
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new4.29 KB
new966 bytes

Thanks @Xano for keeping patch sizes manageable and for fixing this documentation inconsistency.

In the case of these issues, I think a single patch is best because one is not really complete without the other -- they are all a part of fixing the same conceptual gap in the docs about the bundle info array. When we split patches up, it should be because they are different concepts, or because they are unmanageably large. https://www.drupal.org/core/scope#examples gives examples. In this case it's confusing because one of the issues removes documentation, another adds it back in a different place, and a third adds a reference to that documentation in a third place. This makes it so that reviewers cannot actually see the whole picture of what's being fixed.

Attached combines this with #2712367: Extend EntityTypeBundleInfoInterface's docblocks and make them more explicit and #2712373: Improve hook_entity_bundle_info()'s and hook_entity_bundle_info_alter()'s docblocks. The interdiff shows changes I did not include from the combination of all three issues, because those should just be part of #2571965: [meta] Fix PHP coding standards in core, stage 1. Let's review this one as a whole.

xjm’s picture

StatusFileSize
new3.92 KB

Heh except I did not actually exclude what I said I did. ;) Attached does.

jhodgdon’s picture

Status: Needs review » Needs work
Issue tags: -Documentation

Thanks for the patch! I have no opinion on what should and shouldn't be in this patch, but I do have opinions on the documentation in the patch (which is mostly great). A few small things to address:

  1. +++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfoInterface.php
    @@ -10,8 +10,12 @@
    +   * @return array[]
    +   *   Keys are entity type IDs. Values are arrays of which keys are bundle
    +   *   names, and values are arrays with the same structure as the return value
    +   *   of static::getBundleInfo().
    

    This is very clear, except that we normally want to start the @return docs with a description of what is returned, like what was in here before: "An array of all bundle information." Or better yet: "An associative array of all bundle information, where the keys are... and the values are...".

  2. +++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfoInterface.php
    @@ -19,10 +23,17 @@ public function getAllBundleInfo();
    +   *   Keys are bundle names, and values are arrays with the following keys:
    

    See note above.

  3. +++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfoInterface.php
    @@ -19,10 +23,17 @@ public function getAllBundleInfo();
    +   *   - uri_callback: The same as the 'uri_callback' key defined for the entity
    +   *     type in its definition, but for the bundle only. When determining the
    +   *     URI of an entity, if a 'uri_callback' is defined for both the entity
    +   *     type and the bundle, the one for the bundle is used.
    

    Isn't uri_callback deprecated?

  4. +++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfoInterface.php
    @@ -19,10 +23,17 @@ public function getAllBundleInfo();
    +   *   - translatable: (optional) A boolean value specifying whether this bundle
    

    boolean => Boolean

    Another (perhaps clearer) way to write this would be:

    TRUE if the bundle has translation support; FALSE (default) if not.

  5. +++ b/core/lib/Drupal/Core/Entity/entity.api.php
    @@ -706,16 +706,9 @@ function hook_entity_view_mode_info_alter(&$view_modes) {
    + * @return array[]
    + *   The array has the same structure as the return value of
    + *   \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getAllBundleInfo().
    

    See not above about the start of @return docs.

  6. +++ b/core/lib/Drupal/Core/Entity/entity.api.php
    @@ -728,8 +721,9 @@ function hook_entity_bundle_info() {
    + *   The array has the same structure as the return value of
    + *   \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getAllBundleInfo().
    

    And here too.

xano’s picture

This is very clear, except that we normally want to start the @return docs with a description of what is returned, like what was in here before: "An array of all bundle information." Or better yet: "An associative array of all bundle information, where the keys are... and the values are...".

Why is this done? It duplicates information from the one-line summary and the type hint.

jhodgdon’s picture

Our documentation is normally written in English, and the description of the return value normally starts by stating what the function returns. Why is this so much of a problem to ask that the way it was already documented is not removed, but added to?

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new2.84 KB
new4.05 KB

Our documentation is normally written in English, and the description of the return value normally starts by stating what the function returns. Why is this so much of a problem to ask that the way it was already documented is not removed, but added to?

No problem at all. I was just curious why you gave the feedback you did as I was not familiar with the documentation standard that requires us to write this way, and the duplication sounded unnecessary to me.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! This looks pretty good. I have a few suggestions for improvement:

  1. +++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfo.php
    @@ -19,7 +19,9 @@ class EntityTypeBundleInfo implements EntityTypeBundleInfoInterface {
    +   * @var array[]
    +   *   The array has the same structure as the return value of
    +   *   \Drupal\Core\Entity\EntityTypeBundleInfoInterface::getAllBundleInfo().
    

    @var doesn't have a description, so this text should go above.

  2. +++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfoInterface.php
    @@ -10,8 +10,12 @@
    +   *   An array of all bundle information, of which keys are entity type IDs and
    +   *   values are arrays of which keys are bundle names, and values are arrays
    +   *   with the same structure as the return value of static::getBundleInfo().
    

    This is correct, but a little bit hard to read.

    Suggest something like:

    An associative array of bundle information. In the outer array, the keys are ... and the values are arrays whose keys are ... and whose values are ...

  3. +++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfoInterface.php
    @@ -19,10 +23,18 @@ public function getAllBundleInfo();
    +   *   An array of bundle information of which keys are bundle names and values
    +   *   are arrays with the following keys:
    

    of which -> whose

  4. +++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfoInterface.php
    @@ -19,10 +23,18 @@ public function getAllBundleInfo();
    +   *   - uri_callback: The same as the 'uri_callback' key defined for the entity
    

    So, uri_callback is deprecated for entities. Is this normally even in here?

xano’s picture

Where is the deprecation notice? I'd say EntityTypeInterface::getUriCallback() is the part of the API responsible for these callbacks, and it does not mention deprecation. Even if it is deprecated, it is officially supported and should therefore be documented.

jhodgdon’s picture

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new5.29 KB

Re-roll because of duplicate issue #2720077: EntityTypeBundleInfo::getBundleInfo() @return needs more detail, and incorporating the feedback from #14.

of which -> whose

The dictionaries do not seem to agree on this one, especially because whose traditionally is for living subjects only. I corrected it as @jhodgdon requested, but there does not seem to be a universal correct way of writing this.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

ranjith_kumar_k_u’s picture

StatusFileSize
new5.37 KB

Re-rolled for 9.2

Status: Needs review » Needs work

The last submitted patch, 27: 2712379-27.patch, failed testing. View results

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

srilakshmier’s picture

Assigned: Unassigned » srilakshmier

I am working on it.

srilakshmier’s picture

Assigned: srilakshmier » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.53 KB
new720 bytes

Fixed the error from #27, attaching the patch.

joachim’s picture

Status: Needs review » Needs work

Looks like a good docs clean-up!

Just a couple of points:

  1. +++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfoInterface.php
    @@ -24,11 +26,16 @@ public function getAllBundleInfo();
    +   * @return mixed[]
    

    Should be array[], since it's always an array of arrays?

  2. +++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfoInterface.php
    @@ -24,11 +26,16 @@ public function getAllBundleInfo();
    +   *   - translatable: (optional) TRUE if the bundle has translation support,
    

    What does it mean for a return value to be optional? Does it mean that the 'translatable' key might sometimes not be there at all?

    If that is the case, then the docs should say what it means if it's not there. Presumably it's the same as FALSE?

srilakshmier’s picture

Assigned: Unassigned » srilakshmier

I will work on this.

srilakshmier’s picture

Assigned: srilakshmier » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.53 KB
new597 bytes

Thanks for the feedback @joachim.

Point 1- Has been addressed and uploading the patch.

Point 2: This has been already addressed:

+++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfoInterface.php
@@ -24,11 +26,16 @@ public function getAllBundleInfo();
+   *   - translatable: (optional) TRUE if the bundle has translation support,
+   *     FALSE (default) if not.

Please review.

Thanks

joachim’s picture

Thanks!

+++ b/core/lib/Drupal/Core/Entity/EntityTypeBundleInfoInterface.php
@@ -24,11 +26,16 @@ public function getAllBundleInfo();
+   *   - translatable: (optional) TRUE if the bundle has translation support,

However, this still says 'optional' in a return description.

What does it mean to say part of a return array is optional?

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

nikhil_110’s picture

StatusFileSize
new13.76 KB

Attached patch against drupal 10.1.x

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bharath-kondeti made their first commit to this issue’s fork.

bharath-kondeti’s picture

@joachim translatable key is set, only if the language modules are enabled and setup. Maybe that's the reason its marked optional.

bharath-kondeti’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Did a small review but don't think the MR was reviewed before being put into review as it contains tons of out of scope changes. Also this was a documentation change with code changes now.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.