Follow-up to #2873395: [meta] Add @internal to core classes, methods, properties

Problem/Motivation

https://www.drupal.org/core/d8-bc-policy#controllers
Core modules contain many route controllers that are bound to individual routes, as well as form classes. These form classes are not part of the API of the module unless specifically marked with an @api tag on the method or class.

Proposed resolution

Add @internal tag to the Form Classes.
Add @internal tag to the tests Form Classes.

After discussion it has been decided to not add the @internal tag on the following case:

  • abstract Form Base classes which are a part of the API.
  • ContentEntityForm and EntityForm. Examples module suggests to extend them.

As an exception of this rules, we keep the tag in the EntityDeleteForm. Examples module suggests to use EntityConfirmFormBase (config entity) and ContentEntityConfirmFormBase (content entity).

How to fix this issue

  1. Read the description for a category in its issue
  2. Identify and confirm an example. Ask in IRC if unclear.
  3. Search core for the relevant category.
  4. Add @internal per the backwards compatibility policy.
  5. Reviewers should confirm that each @internal mention is appropriate for that category according to the policy.

Remaining tasks

Make the Patch and post it

User interface changes

None.

API changes

There should be no implicit API changes.

Comments

naveenvalecha created an issue. See original summary.

naveenvalecha’s picture

Issue summary: View changes
nvexler’s picture

Hello! I'm at #drupalcon baltimore and I'm working on this issue :). I've talked to @naveenvalecha and @eojthebrave about how important this issue is and how it's a very high priority. So far I have a working copy that I've made a short while ago https://github.com/nathanv/core. I'll be doing my work there in a branch https://github.com/nathanv/core/tree/edit_add_internal_to-2873696 . Feel free to come help me there. I'm hanging out in 301 in the Conference Centre and also in #drupal-docs on irc.

nvexler’s picture

StatusFileSize
new151.16 KB

Hello! I have here a WIP. It's probably almost done. I did a tonne of work somewhat quickly so I might have missed some style stuff. I'm uploading it now but will be checking it over right away.

My method was to do the following:

  • git clone core to a clean folder, load up PhpStorm and launch the New Project From Existing Files Wizard.
  • Add core via this with the "Source files are in a local directory, no Web server is yet configured." option selected.
  • I then used PhpStorm's nifty subclass hinting feature. I went to lib/Drupal/Core/Form/FormBase.php and hovered my mouse over the editor gutter which displays the indicator that the class has subclasses.
  • I then clicked on it and went to all the subclasses and implemented the @internal piece. When there was no docblock, I created one. I hope they are all ok. If not, I am happy to reroll as necessary.
nvexler’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: edit_add_internal_to-2873696-1.patch, failed testing.

nvexler’s picture

StatusFileSize
new143.07 KB

Sorry folks... wrong process here for creating patches... I pulled down just core instead of all of Drupal. This should work.

nvexler’s picture

Status: Needs work » Needs review
xjm’s picture

Thanks @nvexler! Excellent work documenting your specific process for further contributors.

wim leers’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

This no longer applies unfortunately. Which makes reviewing this quite hard. This is looking wonderful already though!

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new142.53 KB

BundleModerationConfigurationForm has been removed since the patch in #7 was created (see #2843083: Select entity type / bundle in workflow settings).

Re-rolled.

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.

gido’s picture

I'will help with this one during DrupalCon Vienna

wengerk’s picture

Working on it during the DrupalConEU Vienna.

valthebald’s picture

Issue tags: +Novice, +Vienna2017

Tagging

mradcliffe’s picture

Status: Needs review » Needs work

Are *FormBase classes internal? I thought that all/most base classes were a part of the API.

The following abstract base classes are marked as internal in the patch above.

  • * core/lib/Drupal/Core/Entity/BundleEntityFormBase
  • * core/lib/Drupal/Core/Entity/ContentEntityConfirmFormBase
  • * core/modules/locale/src/Form/TranslateFormBase
  • * core/lib/Drupal/Core/Entity/EntityConfirmFormBase
  • * core/lib/Drupal/Core/Entity/EntityForm
  • * core/lib/Drupal/Core/Form/ConfigFormBase
  • * core/lib/Drupal/Core/Form/ConfirmFormBase
  • * core/modules/action/src/ActionFormBase
  • * core/modules/config_translation/src/Form/ConfigTranslationFormBase
  • * core/modules/field_ui/src/Form/EntityDisplayFormBase
  • * core/modules/field_ui/src/Form/EntityDisplayModeFormBase
  • * core/modules/filter/src/FilterFormatFormBase
  • * core/modules/image/src/Form/ImageEffectFormBase
  • * core/modules/image/src/Form/ImageStyleFormBase
  • * core/modules/language/src/Form/LanguageFormBase
  • * core/modules/locale/src/Form/TranslateFormBase
  • * core/modules/path/src/Form/PathFormBase
  • * core/modules/search/src/Form/SearchPageFormBase
  • * core/modules/system/src/Form/DateFormatFormBase
  • * core/modules/views_ui/src/Form/Ajax/ViewsFormBase
  • * core/modules/views_ui/src/ViewFormBase

Additionally the following abstract classes might be considered part of the API because they are abstract:

  • * core/modules/user/src/AccountForm

The following base form class is in form_test only and I think that is fine to be @internal.

  • * core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectFormBase

Please review and discuss these to make sure that we actually want to make them @internal

wengerk’s picture

StatusFileSize
new141.04 KB

The previous patch in #11 not apply on 8.5.x for multiple reasons:

The new patch 2873696-12.patch is based on the commit b4ce4af60c and should works now.

Here why the previous patch didn't applied:

  • core/modules/system/src/Tests/Form/StubForm.php has been removed.
  • core/modules/outside_in/src/Block/BlockEntityOffCanvasForm.php has been removed.
  • core/modules/statistics/src/StatisticsSettingsForm.php has changed since the previous patch.
  • core/modules/system/src/Form/CronForm.php has changed since the previous patch.
valthebald’s picture

Valid point, base forms should not be marked internal per description in the parent issue

wengerk’s picture

StatusFileSize
new132.61 KB

As suggested by @mradcliffe in #16 & discuss with @valthebald & @gido, we remove the @internal tag on the abstract Base classes but keep them on:

  • core/modules/system/tests/modules/form_test/src/Form/FormTestTableSelectFormBase

We suggest to also not tag as @internal the following classes:

  • core/modules/user/src/AccountForm
  • Drupal\Core\Entity\ContentEntityForm
  • Drupal\Core\Entity\EntityDeleteForm
  • Drupal\Core\Entity\EntityForm
mradcliffe’s picture

Status: Needs work » Needs review

I agree, @wengerk. I looked at Examples module, which suggests extending ContentEntityForm and EntityForm.

The exception might be for EntityDeleteForm. Examples module suggests to use EntityConfirmFormBase (config entity) and ContentEntityConfirmFormBase (content entity).

gido’s picture

StatusFileSize
new137.21 KB

I updated the patch and made a review. I found and tagged the following new Form classes in 8.5x:

  • Drupal\form_test\Form\FormTestRadiosCheckedForm
  • Drupal\ajax_forms_test\Form\AjaxFormsTestImageButtonForm
  • Drupal\ajax_forms_test\Form\AjaxFormsTestAjaxElementsForm
  • Drupal\Tests\system\Functional\Form\StubForm
  • Drupal\form_test\Form\FormTestOptionalContainerForm
  • Drupal\media\MediaTypeForm
  • Drupal\media\MediaForm
  • Drupal\media\Form\MediaTypeDeleteConfirmForm
  • Drupal\media\Form\MediaDeleteMultipleConfirmForm

removed tag from ContentEntityForm and EntityForm.

mradcliffe’s picture

If you have a neighbor looking to help, they could add an explanation of form classes as discovered by @wengerk, @gido and @valthebald above that are not marked as @internal to the issue summary under the proposed resolution section.

wengerk’s picture

Issue summary: View changes

As suggested by @mradcliffe, I updated the Proposed Resolution section.

gido’s picture

Just for documenting the way I reviewed the patch:

  1. I Applied the patch on a clean 8.5.x branch
  2. I Opened the hierarchy class tree with my IDE (with PHPStorm, ctrl+c) to find all children classes of Drupal\Core\Form\FormBase
  3. checked one by one if we missed something (thankfully the IDE highlight changed files to make this easier)
valthebald’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update

1. Removed "Needs issue summary update" because issue summary is updated in #23
2. Repeated steps outline in #24 and ensured that all child classes (with exceptions) now have @internal tag
3. Moving to RTBC

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed ee0f806 and pushed to 8.5.x. Thanks!

  • catch committed ee0f806 on 8.5.x
    Issue #2873696 by nvexler, wengerk, gido, Jo Fitzgerald, xjm: Add @...
xjm’s picture

Great work on this, everyone!

Added credit for valthebald for mentoring

Status: Fixed » Closed (fixed)

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

avpaderno’s picture

Title: Add @internal to core classes, methods, properties to Form Classes » Add @internal to core form classes, methods, and properties