mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Use dependency injection for farm_field.factory service.
This commit is contained in:
parent
a576bad88d
commit
2028e84dc4
|
@ -61,7 +61,7 @@ class Animal extends FarmAssetType {
|
|||
],
|
||||
];
|
||||
foreach ($field_info as $name => $info) {
|
||||
$fields[$name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($info);
|
||||
$fields[$name] = $this->farmFieldFactory->bundleFieldDefinition($info);
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class Equipment extends FarmAssetType {
|
|||
],
|
||||
];
|
||||
foreach ($field_info as $name => $info) {
|
||||
$fields[$name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($info);
|
||||
$fields[$name] = $this->farmFieldFactory->bundleFieldDefinition($info);
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class Plant extends FarmAssetType {
|
|||
],
|
||||
];
|
||||
foreach ($field_info as $name => $info) {
|
||||
$fields[$name] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($info);
|
||||
$fields[$name] = $this->farmFieldFactory->bundleFieldDefinition($info);
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
|
42
modules/core/entity/src/FarmEntityTypeBase.php
Normal file
42
modules/core/entity/src/FarmEntityTypeBase.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_entity;
|
||||
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Plugin\PluginBase;
|
||||
use Drupal\farm_field\FarmFieldFactoryInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a FarmEntityTypeBase for plugins to extends.
|
||||
*/
|
||||
abstract class FarmEntityTypeBase extends PluginBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The farm_field.factory service.
|
||||
*
|
||||
* @var \Drupal\farm_field\FarmFieldFactoryInterface
|
||||
*/
|
||||
protected $farmFieldFactory;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, FarmFieldFactoryInterface $farm_field_factory) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->farmFieldFactory = $farm_field_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('farm_field.factory')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace Drupal\farm_entity\Plugin\Asset\AssetType;
|
||||
|
||||
use Drupal\Core\Plugin\PluginBase;
|
||||
use Drupal\farm_entity\FarmEntityTypeBase;
|
||||
|
||||
/**
|
||||
* Provides the base asset type class.
|
||||
*/
|
||||
abstract class AssetTypeBase extends PluginBase implements AssetTypeInterface {
|
||||
abstract class AssetTypeBase extends FarmEntityTypeBase implements AssetTypeInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace Drupal\farm_entity\Plugin\Log\LogType;
|
||||
|
||||
use Drupal\Core\Plugin\PluginBase;
|
||||
use Drupal\farm_entity\FarmEntityTypeBase;
|
||||
|
||||
/**
|
||||
* Provides the base log type class.
|
||||
*/
|
||||
abstract class LogTypeBase extends PluginBase implements LogTypeInterface {
|
||||
abstract class LogTypeBase extends FarmEntityTypeBase implements LogTypeInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace Drupal\farm_entity\Plugin\Plan\PlanType;
|
||||
|
||||
use Drupal\Core\Plugin\PluginBase;
|
||||
use Drupal\farm_entity\FarmEntityTypeBase;
|
||||
|
||||
/**
|
||||
* Provides the base plan type class.
|
||||
*/
|
||||
abstract class PlanTypeBase extends PluginBase implements PlanTypeInterface {
|
||||
abstract class PlanTypeBase extends FarmEntityTypeBase implements PlanTypeInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -30,7 +30,7 @@ class Harvest extends FarmLogType {
|
|||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['lot_number'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['lot_number'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class Input extends FarmLogType {
|
|||
'view' => -45,
|
||||
],
|
||||
];
|
||||
$fields['lot_number'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['lot_number'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Material.
|
||||
$options = [
|
||||
|
@ -45,7 +45,7 @@ class Input extends FarmLogType {
|
|||
'view' => -50,
|
||||
],
|
||||
];
|
||||
$fields['material'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['material'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Method.
|
||||
$options = [
|
||||
|
@ -57,7 +57,7 @@ class Input extends FarmLogType {
|
|||
'view' => -30,
|
||||
],
|
||||
];
|
||||
$fields['method'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['method'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Purchase date.
|
||||
$options = [
|
||||
|
@ -69,7 +69,7 @@ class Input extends FarmLogType {
|
|||
'view' => -35,
|
||||
],
|
||||
];
|
||||
$fields['purchase_date'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['purchase_date'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Source.
|
||||
$options = [
|
||||
|
@ -81,7 +81,7 @@ class Input extends FarmLogType {
|
|||
'view' => -40,
|
||||
],
|
||||
];
|
||||
$fields['source'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['source'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class LabTest extends FarmLogType {
|
|||
'view' => -40,
|
||||
],
|
||||
];
|
||||
$fields['lab'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['lab'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Lab test type.
|
||||
$options = [
|
||||
|
@ -42,7 +42,7 @@ class LabTest extends FarmLogType {
|
|||
'view' => -50,
|
||||
],
|
||||
];
|
||||
$fields['lab_test_type'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['lab_test_type'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class Medical extends FarmLogType {
|
|||
'view' => -40,
|
||||
],
|
||||
];
|
||||
$fields['vet'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['vet'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class Purchase extends FarmLogType {
|
|||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['invoice_number'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['invoice_number'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Seller.
|
||||
$options = [
|
||||
|
@ -40,7 +40,7 @@ class Purchase extends FarmLogType {
|
|||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['seller'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['seller'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class Sale extends FarmLogType {
|
|||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['customer'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['customer'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Invoice number.
|
||||
$options = [
|
||||
|
@ -40,7 +40,7 @@ class Sale extends FarmLogType {
|
|||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['invoice_number'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['invoice_number'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class Seeding extends FarmLogType {
|
|||
'view' => 20,
|
||||
],
|
||||
];
|
||||
$fields['lot_number'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['lot_number'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Purchase date.
|
||||
$options = [
|
||||
|
@ -42,7 +42,7 @@ class Seeding extends FarmLogType {
|
|||
'view' => -35,
|
||||
],
|
||||
];
|
||||
$fields['purchase_date'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['purchase_date'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
// Source.
|
||||
$options = [
|
||||
|
@ -54,7 +54,7 @@ class Seeding extends FarmLogType {
|
|||
'view' => -40,
|
||||
],
|
||||
];
|
||||
$fields['source'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
|
||||
$fields['source'] = $this->farmFieldFactory->bundleFieldDefinition($options);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue