Verified Commit f8a0d181 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3331397 by gcb, DanielVeza, Tatsiana, arisen:...

Issue #3331397 by gcb, DanielVeza, Tatsiana, arisen: ListItemBase::generateSampleValue() white screen when options list is empty

(cherry picked from commit 52fbc9ad)
parent 5b8eff89
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -65,6 +65,10 @@ public function getSettableOptions(AccountInterface $account = NULL) {
   */
  public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
    $allowed_options = options_allowed_values($field_definition->getFieldStorageDefinition());
    if (empty($allowed_options)) {
      $values['value'] = NULL;
      return $values;
    }
    $values['value'] = array_rand($allowed_options);
    return $values;
  }
+10 −0
Original line number Diff line number Diff line
@@ -98,4 +98,14 @@ public function testUpdateAllowedValues() {
    $this->entityValidateAndSave($entity);
  }

  /**
   * Tests that ::generateSampleItems does not fail with empty allowed values.
   */
  public function testGenerateSampleItemsWithNoAllowedValues() {
    $this->fieldStorage->setSetting('allowed_values', [])->save();
    $entity = EntityTest::create();
    $value = $entity->{$this->fieldName}->generateSampleItems();
    $this->assertNull($value);
  }

}