function farm_location_is_location_default_value in farmOS 2.x
Sets the default value for asset is_location boolean field.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity being created.
\Drupal\Core\Field\FieldDefinitionInterface $definition: The field definition.
Return value
array An array of default value keys with each entry keyed with the “value” key.
See also
\Drupal\Core\Field\FieldConfigBase::getDefaultValue()
1 string reference to 'farm_location_is_location_default_value'
- farm_location_asset_base_fields in modules/
core/ location/ farm_location.base_fields.inc - Define asset location base fields.
File
- modules/
core/ location/ farm_location.module, line 60 - Contains farm_location.module.
Code
function farm_location_is_location_default_value(ContentEntityInterface $entity, FieldDefinitionInterface $definition) : array {
$default = FALSE;
// Load the entity bundle.
$bundle = \Drupal::service('entity_type.manager')
->getStorage('asset_type')
->load($entity
->bundle());
// Use the bundle's is_location third-party setting as a default.
$is_location = $bundle
->getThirdPartySetting('farm_location', 'is_location');
if (!empty($is_location)) {
$default = TRUE;
}
return [
[
'value' => $default,
],
];
}