In 7.x we implemented hook_field_extra_fields() to allow the scheduler fieldset to be exposed in the content-type 'manage fields' tab, so that admins could adjust the position in the form.

This code was removed from 8.x in this commit. However, we still need this functionality in 8.x and it is still available - the hook has been renamed hook_entity_extra_field_info(). The core issue which changed it to entity API is #2225629: Move hook_field_extra_fields() to the entity API and here is the change record for extra field definitions and the hook_entity_extra_field_info() API page

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonathan1055 created an issue. See original summary.

jonathan1055’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
1.56 KB

Here is the function, converted to the new hook and updated for 8.x.
I think this should also have test coverage too, which I will work on, but for now here's the function, for review and comment.

Status: Needs review » Needs work

The last submitted patch, 2: 2667692-1.extra_field_info.patch, failed testing.

jonathan1055’s picture

Status: Needs work » Needs review
FileSize
2.38 KB

I have added a second set of tests to FieldsDisplayTest to check that the weight item is shown on the form when it should be and not shown when it shouldn't. This patch contains just the changes to the test file, so there should be an extra failing class now.

Status: Needs review » Needs work

The last submitted patch, 4: 2667692-4.extra_field_info_test_only.patch, failed testing.

jonathan1055’s picture

As expected we get a new class fail

2	1	Scheduler.Drupal\scheduler\Tests\SchedulerFieldsDisplayTest
✓		- setUp
✓		- testFieldsDisplay
	✗	- testManageFormDisplay

fail: [Browser] Line 110 of modules/scheduler/src/Tests/SchedulerFieldsDisplayTest.php:
The scheduler settings weight entry is shown when the display mode is "fieldset"

Next I'll provide a patch with the tests and fixed code.

jonathan1055’s picture

Status: Needs work » Needs review
FileSize
3.94 KB

Patch with new test + fixed .module

Status: Needs review » Needs work

The last submitted patch, 7: 2667692-7.extra_field_info_test_only.patch, failed testing.

jonathan1055’s picture

I realised that there is no need to only allow the weight entry for 'fieldset'. So

if (($publishing_enabled || $unpublishing_enabled) && $fields_display_mode == 'fieldset') {

simply becomes

if ($publishing_enabled || $unpublishing_enabled) {

If this restriction is removed then the weight setting works for vertical tabs too, which is better. New patch, including tests.

pfrenssen’s picture

Status: Needs review » Reviewed & tested by the community

I don't remember why I deleted this, apparently I thought this was no longer used since we are now using base fields. I possibly thought all the relevant code was already factored out of it and this was just the wrapper. But yes we obviously still need it.

Thanks for adding test coverage, this will ensure I will not mess with it any more in the future :)

Also very very nice to see a fully green test. Amazing work!!

If this restriction is removed then the weight setting works for vertical tabs too, which is better.

Good idea!

  1. +++ b/scheduler.module
    @@ -458,6 +458,30 @@ function _scheduler_scheduler_api(NodeInterface $node, $action) {
    +function scheduler_entity_extra_field_info() {
    +  // Expose the Scheduler group on the 'Manage Form Display' tab when editing a
    +  // content type. This allows admins to adjust the weight of the group, and it
    +  // works for vertical tabs and separate fieldsets.
    

    Thanks for adding this documentation, that clarifies why we need it.

  2. +++ b/scheduler.module
    @@ -458,6 +458,30 @@ function _scheduler_scheduler_api(NodeInterface $node, $action) {
    +      $fields['node'][$type->get('type')]['form']['scheduler_settings'] = array(
    

    Still using the old array() syntax. This is OK since it is consistent with the remainder of the module file. We should maybe do a cleanup to convert all of these when we are closer to release.

  3. +++ b/src/Tests/SchedulerFieldsDisplayTest.php
    @@ -17,6 +17,12 @@ use Drupal\node\Entity\NodeType;
       /**
    +   * SchedulerTestBase loads the standard modules.
    +   * Additional module field_ui is required for the 'manage form display' test.
    +   */
    +  public static $modules = ['field_ui'];
    

    This surprised me. This should override the static from SchedulerTestBase, so logically the Node module and Scheduler itself should no longer be enabled now. But since the tests are green this seems to work.

    I looked into it and this is handled by WebTestBase::installModulesFromClassProperty(). It loops over all parent classes and merges the properties together. Nice trick, I didn't know this.

  4. +++ b/src/Tests/SchedulerFieldsDisplayTest.php
    @@ -75,4 +81,31 @@ class SchedulerFieldsDisplayTest extends SchedulerTestBase {
    +  /**
    +   * Tests the settings entry in the content type form display.
    +   * This test covers scheduler_entity_extra_field_info().
    +   */
    

    There is the @covers keyword now, but I'm not sure if this applies to WebTestBase as well. It does apply to PHPUnit based tests. It's fine to leave it for now.

Looking good, RTBC!

pfrenssen’s picture

Assigned: jonathan1055 » Unassigned
Status: Reviewed & tested by the community » Fixed

Committed to 8.x-1.x. Thanks!

jonathan1055’s picture

Hi Pieter,
Thanks for all the review info above.
2. Yes we could do an array syntax cleanup. Let's pick a time when we have only a few patches waiting review, as it is bound to cause many re-rolls.
3. SchedulerTestBase loads the standard modules ... I discovered this by chance, checked it, then I cleaned up the other test files, removing the unnecessary lines. I added the comment specifically to say way, and share the knowledge. Thanks for looking deeper into the reason.
4. I did not know about @covers and will use it in future test coding.

Yes, it is very good to see the full set of green test passes. In addition to being "a good thing" in itself, it also makes our development/review/retest process cleaner and easier, and the issue status properly reflects the state of the submitted patch .

Status: Fixed » Closed (fixed)

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