Problem/Motivation

The documentation in Form API's EntityAutocomplete class, of what properties are allowed in different configuration arrays, is difficult to find. Some properties are described in method docblocks; some on the class docblock; other docblocks are incomplete.

Proposed resolution

Rewrite inline documentation for EntityAutocomplete and DefaultSelection to clarify what property keys are permitted in config arrays:

* Move explanation of common config properties to class-level docblocks.
* Reference these in method level docblocks, to avoid duplication.
* Expand descriptions of properties where appropriate.
* Two classes to reference each other with @see, to avoid duplication.

Remaining tasks

Approve this issue summary change.

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Tronux created an issue. See original summary.

jp.stacey’s picture

Version: 8.2.x-dev » 8.3.x-dev
Status: Active » Needs review
FileSize
4.42 KB

@Tronux thanks for this. I think you're right, that the properties in the settings and element arrays being passed around aren't clear. There is actually documentation of $element properties on this class, but it's buried down in one of the static method docblocks. Also, the sub-properties of $element['#selection_settings'] are not clearly explained anywhere.

Based on this ticket and discussion here https://api.drupal.org/comment/62553#comment-62553 , I attach a patch which modifies two classes:

EntityAutocomplete
Move the documentation for what $element might contain, up to the top of the class, and improve method docblocks on the way. Reference the below class for more information of the sub-properties of handler_settings.
DefaultSelection
Make explicit the documentation of default properties on the handler_settings configuration, so these don't have to be documented in the previous.
Both
Add a @see ... so each class references the other.

Feedback welcome!

kiwimind’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +mssprintjan17

This all makes sense.

Having the @see references and moving the target_bundles to the main body of the comment is very helpful.

Thanks, RTBC.

cilefen’s picture

Status: Reviewed & tested by the community » Needs review

I'd like to see an issue title that describes the documentation deficiency and an issue summary that reflects the direction of the patch in #2.

jp.stacey’s picture

Status: Needs review » Needs work

Looking at this now.

jp.stacey’s picture

Title: form api and attributes » Rewrite docs for EntityAutocomplete and DefaultSelection to make clear what config properties are used
Issue summary: View changes
Status: Needs work » Needs review

@cilefen thanks: you're right that the problem @tronux kindly originally reported, pointed away from the ultimate fix (it referenced a solution in another class, that was actually a red herring, just coincidentally describing the same config property.)

Out of interest, I see a few issue summaries beginning "Enter a descriptive title (above) relating to class EntityAutocomplete, then describe the problem you have found:" and they're often in need of a tidyup. Is that coming from a particular submission channel? I don't know if that could be improved to get better summaries from reporters, or whether that would be intimidating; maybe a summary that needs tidying is better than no summary at all.

Anyway, I've used the standard issue template to reword the description now, and redrafted the title. Would appreciate a re-review.

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.

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.

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.

baikho’s picture

ranjith_kumar_k_u’s picture

Re-rolled from #2

ranjith_kumar_k_u’s picture

joachim’s picture

Status: Needs review » Needs work

The most recent patches are losing a lot of the changes from patch #2.

ankithashetty’s picture

Status: Needs work » Needs review
FileSize
3.4 KB
3.86 KB

Here is the rerolled patch from #2, thanks!

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.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Documentation change looks like a good improvement.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

Always nice to see documentation improvements.

+++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php
@@ -25,6 +25,18 @@
+ * Plugin configuration must contain a key handler_settings referencing an

The first thing I noticed in this documentation was a double space. Then, I thought 'handler_settings' should be in quotes but then, as I read this, I think we can do better here. The descriptions should start with what the key is for, not the default value. And the reader should know what keys are required and which ones are optional, using the standard format. It is easier to express my ideas by example so I made a suggestion.

 * Available configuration keys.
 * - handler_settings: (required) An array with the following keys.
 *   - auto_create: (?) If TRUE, create referenced entities
 *     if they don't already exist. Defaults to FALSE.
 *   - auto_create_bundle: (?) Bundle name for auto-created entities, if
 *     auto-create is TRUE. Defaults to NULL.
 *   - sort: (?) An array of sort parameters. Default to ['field' => '_none'].
 *   - target_bundles: (?) An array of bundle names. Defaults to NULL. NULL means
 *     "allow entities from any bundle to be referenced"; an empty array
 *     means "no entities from any bundle can be referenced".
 *

There is still work to do here. The text '(?)' needs to be replaced with (optional) or (required). And, maybe the description for target_bundles needs a tweak as well. It is not obvious why the two phrases are in double quotes.

See Making lists in documentation

joachim’s picture

target_bundles, sort, auto_create, auto_create_bundle are optional, since they default to something in defaultConfiguration().

> * - sort: (?) An array of sort parameters. Default to ['field' => '_none'].

We should say it's an array containing 'field' - the field name to sort on and 'direction' - one of ASC/DEC.

Also, auto_create_bundle MUST be specified if auto_create is TRUE.

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.