You are here

public function Sensor::buildFieldDefinitions in farmOS 2.x

Overrides AssetTypeBase::buildFieldDefinitions

File

modules/asset/sensor/src/Plugin/Asset/AssetType/Sensor.php, line 21

Class

Sensor
Provides the sensor asset type.

Namespace

Drupal\farm_sensor\Plugin\Asset\AssetType

Code

public function buildFieldDefinitions() {
  $fields = parent::buildFieldDefinitions();

  // Data stream field.
  $options = [
    'type' => 'entity_reference',
    'label' => $this
      ->t('Data stream'),
    'description' => $this
      ->t('Data streams provided by this sensor.'),
    'target_type' => 'data_stream',
    'multiple' => TRUE,
    'weight' => [
      'form' => 4,
      'view' => 4,
    ],
  ];
  $fields['data_stream'] = $this->farmFieldFactory
    ->bundleFieldDefinition($options);

  // Private key field.
  $options = [
    'type' => 'string',
    'label' => $this
      ->t('Private key'),
    'description' => $this
      ->t('Private key for the sensor.'),
    'default_value_callback' => DataStream::class . '::createUniqueKey',
    'weight' => [
      'form' => 3,
    ],
    'hidden' => 'view',
  ];
  $fields['private_key'] = $this->farmFieldFactory
    ->bundleFieldDefinition($options);

  // Public field.
  $options = [
    'type' => 'boolean',
    'label' => $this
      ->t('Public'),
    'description' => $this
      ->t('Whether or not data from this sensor can be read publicly without the private key.'),
    'default' => FALSE,
    'weight' => [
      'form' => 2,
      'view' => 2,
    ],
  ];
  $fields['public'] = $this->farmFieldFactory
    ->bundleFieldDefinition($options);
  return $fields;
}