Updated: Comment #0

Problem/Motivation

Currently WidgetBase::formSingleElement() wrongly passes to context a flag indicating that default value used for widget by examining property that never set so there's no way for widgets' alter implementation to detect field_ui usage of widget.

$context = array(
...
        'default' => !empty($entity->field_ui_default_value),

Proposed resolution

Replace this with $element['#field_parents'] != array('default_value_input') at least

Remaining tasks

Suggest proper method for widget to detect default value usage

User interface changes

no

API changes

no

tbd

Comments

andypost’s picture

Status: Active » Needs review
Issue tags: +Field API
StatusFileSize
new808 bytes

There's only one left, probably needs tests

andypost’s picture

Priority: Normal » Major
Issue tags: +Needs tests

This is major because alter functions will always get FALSE so no way to detect widget usage for field instance settings form!

andypost’s picture

With test

PS: the coverage for form already done in /FormTest::testFieldFormSingle()

jibran’s picture

Well issue has fail patch and pass patch so bug is fixed but I don't know a lot about this issue leaving it for @swentel or @yched to RTBC.

andypost’s picture

Issue summary: View changes
StatusFileSize
new1.64 KB

re-roll

Status: Needs review » Needs work

The last submitted patch, 5: drupal8.field-system.2084987-5.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.58 KB

re-roll

yched’s picture

in_array('default_value_input', $form['#parents']) is one way to differentiate, yes.
Alternatively, we could also use if (empty($form_state['default_value_widget']), that's what I did for LinkWidget in #2293723: Generate lighter $form[$field] structures.

I hesitated between the two back then in that issue, and considered that a condition on $form_state['default_value_widget'] was a bit more telling (and not dependent on the form tree structure). No big difference I guess, but we should be consistent.

yched’s picture

"But we should be consistent"...

I guess one way would be to encapsulate this check once and for all in a isDefaultValueWidget() method on WidgetBase.
- widgets that need this info, like LinkWidget, can call it directly instead of doing an obscure test
- we can pass that as $context['default'] = $this->isDefaultValueWidget() when calling hook_field_widget_form_alter()

Jalandhar’s picture

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

Patch needs to be updated.

Jalandhar’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new1.58 KB

Here is the updated patch.

jhedstrom’s picture

Status: Needs review » Needs work
+++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php
@@ -569,6 +569,11 @@ function testHelpDescriptions() {
+    // Check that hook_field_widget_form_alter() does believe this is the
+    // default value form.
+    $this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_tags');
+    $this->assertText('From hook_field_widget_form_alter(): Default form is true.', 'Default value form in hook_field_widget_form_alter().');
+

I was a little confused what this code was testing. Instead of hook_field_widget_form_alter(), could the comment mention field_test_field_widget_form_alter()?

jhedstrom’s picture

Also, from #10

"But we should be consistent"...

should be addressed I think.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new2.18 KB
new3.05 KB

#10 fixed

andypost’s picture

StatusFileSize
new818 bytes
new2.99 KB

uh, phpdoc clean-up

yched’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Thanks folks :-)

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed ad555fa on 8.0.x
    Issue #2084987 by andypost, Jalandhar: Remove usage of...
andypost’s picture

Status: Fixed » Needs review
StatusFileSize
new1.04 KB

Follow-up to clean-up the comment widget usage

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community
catch’s picture

Status: Reviewed & tested by the community » Fixed

Follow-up looks good but please open a new issue. Two patches means two commit hashes.

andypost’s picture

Status: Fixed » Closed (fixed)

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