I was unable to set default value of the field.

Comments

jibran’s picture

Issue tags: +need tests
StatusFileSize
new1.15 KB

Here is the fix.

jibran’s picture

Status: Active » Needs review
Issue tags: -need tests +Needs tests
jibran’s picture

Issue tags: -Needs tests
StatusFileSize
new1.3 KB
new2.45 KB

Now with tests.

The last submitted patch, 3: 2365297-3-test-only.patch, failed testing.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

  • jibran committed 4bc3a2f on 8.x-1.x
    Issue #2365297 by jibran: Fixed can't set field default value.
    
jibran’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

aaronbauman’s picture

Q: how do i set a default value in my entity form builder?

A:

$form['drupal_entity']['widget'][0]['target_type']['#default_value'] = $drupal_entity->getEntityTypeId();
$form['drupal_entity']['widget'][0]['target_id']['#default_value'] = $drupal_entity;

edit: browser cache was hanging onto my form inputs.

jibran’s picture

This should work

$form['drupal_entity']['widget'][0]['target_type']['#default_value'] = $drupal_entity->getEntityTypeId();
$form['drupal_entity']['widget'][0]['target_id']['#default_value'] = $drupal_entity->id();