You are here

class Sensor in farmOS 2.x

Provides the sensor asset type.

Plugin annotation


@AssetType(
  id = "sensor",
  label = @Translation("Sensor"),
)

Hierarchy

Expanded class hierarchy of Sensor

1 string reference to 'Sensor'
asset.type.sensor.yml in modules/asset/sensor/config/install/asset.type.sensor.yml
modules/asset/sensor/config/install/asset.type.sensor.yml

File

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

Namespace

Drupal\farm_sensor\Plugin\Asset\AssetType
View source
class Sensor extends FarmAssetType {

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssetTypeBase::getLabel public function Gets the asset type label. Overrides AssetTypeInterface::getLabel
AssetTypeBase::getWorkflowId public function Gets the asset workflow ID. Overrides AssetTypeInterface::getWorkflowId
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FarmEntityTypeBase::$farmFieldFactory protected property The farm_field.factory service.
FarmEntityTypeBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
FarmEntityTypeBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
Sensor::buildFieldDefinitions public function Overrides AssetTypeBase::buildFieldDefinitions
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.