You are here

function farm_location_log_base_fields in farmOS 2.x

Define log location base fields.

1 call to farm_location_log_base_fields()
farm_location_entity_base_field_info in modules/core/location/farm_location.module
Implements hook_entity_base_field_info().

File

modules/core/location/farm_location.base_fields.inc, line 113
Code for creating farmOS entity location base field definitions.

Code

function farm_location_log_base_fields() {
  $fields = [];

  // Location asset reference field.
  $options = [
    'type' => 'entity_reference',
    'label' => t('Location'),
    'description' => t('Where does this take place?'),
    'target_type' => 'asset',
    'multiple' => TRUE,
    'weight' => [
      'form' => 90,
      'view' => 90,
    ],
  ];
  $field = \Drupal::service('farm_field.factory')
    ->baseFieldDefinition($options);
  $field
    ->setSetting('handler', 'views');
  $field
    ->setSetting('handler_settings', [
    'view' => [
      'view_name' => 'farm_location_reference',
      'display_name' => 'entity_reference',
    ],
  ]);
  $fields['location'] = $field;

  // Geometry field.
  // This is added as a bundle field definition to all log types rather than
  // a base field definition so that data is stored in a dedicated database
  // table.
  $options = [
    'type' => 'geofield',
    'label' => t('Geometry'),
    'description' => t('Add geometry data to this log to describe where it took place.'),
    'weight' => [
      'form' => 95,
      'view' => 95,
    ],
    'populate_file_field' => 'file',
  ];
  $fields['geometry'] = \Drupal::service('farm_field.factory')
    ->bundleFieldDefinition($options);

  // Movement boolean field.
  $options = [
    'type' => 'boolean',
    'label' => t('Is movement'),
    'description' => t('If this log is a movement, then all assets referenced by it will be located in the referenced locations and/or geometry at the time the log takes place. The log must be complete in order for the movement to take effect.'),
    'default_value_callback' => 'farm_location_is_movement_default_value',
    'weight' => [
      'form' => 95,
    ],
    'view_display_options' => [
      'label' => 'inline',
      'type' => 'hideable_boolean',
      'settings' => [
        'format' => 'default',
        'format_custom_false' => '',
        'format_custom_true' => '',
        'hide_if_false' => TRUE,
      ],
      'weight' => 95,
    ],
  ];
  $fields['is_movement'] = \Drupal::service('farm_field.factory')
    ->baseFieldDefinition($options);
  return $fields;
}