function LanguageItem::generateSampleValue
Same name in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php \Drupal\Core\Field\Plugin\Field\FieldType\LanguageItem::generateSampleValue()
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php \Drupal\Core\Field\Plugin\Field\FieldType\LanguageItem::generateSampleValue()
- 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php \Drupal\Core\Field\Plugin\Field\FieldType\LanguageItem::generateSampleValue()
Overrides FieldItemBase::generateSampleValue
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldType/ LanguageItem.php, line 113
Class
- LanguageItem
- Defines the 'language' entity field item.
Namespace
Drupal\Core\Field\Plugin\Field\FieldTypeCode
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
// Defer to the callback in the item definition as it can be overridden.
$constraint = $field_definition->getItemDefinition()
->getConstraint('ComplexData');
if (isset($constraint['value']['AllowedValues']['callback'])) {
$languages = call_user_func($constraint['value']['AllowedValues']['callback']);
}
else {
$languages = array_keys(\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL));
}
$values['value'] = $languages[array_rand($languages)];
return $values;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.