You are here

function farm_location_is_movement_default_value in farmOS 2.x

Sets the default value for log movement 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_movement_default_value'
farm_location_log_base_fields in modules/core/location/farm_location.base_fields.inc
Define log location base fields.

File

modules/core/location/farm_location.module, line 120
Contains farm_location.module.

Code

function farm_location_is_movement_default_value(ContentEntityInterface $entity, FieldDefinitionInterface $definition) : array {
  $default = FALSE;

  // Load the entity bundle.
  $bundle = \Drupal::service('entity_type.manager')
    ->getStorage('log_type')
    ->load($entity
    ->bundle());

  // Use the bundle's is_movement third-party setting as a default.
  $is_movement = $bundle
    ->getThirdPartySetting('farm_location', 'is_movement');
  if (!empty($is_movement)) {
    $default = TRUE;
  }
  return [
    [
      'value' => $default,
    ],
  ];
}