clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_equipment
id: equipment
label: Equipment
description: ''
workflow: asset_default
new_revision: true

View File

@@ -0,0 +1,72 @@
langcode: en
status: true
dependencies:
config:
- asset.type.equipment
- core.entity_view_mode.asset.map_popup
module:
- options
- text
id: asset.equipment.map_popup
targetEntityType: asset
bundle: equipment
mode: map_popup
content:
flag:
label: inline
type: list_default
weight: 0
region: content
settings: { }
third_party_settings: { }
location:
type: entity_reference_label
weight: 5
region: content
label: inline
settings:
link: true
third_party_settings: { }
manufacturer:
label: inline
type: string
weight: 1
region: content
settings:
link_to_entity: false
third_party_settings: { }
model:
label: inline
type: string
weight: 2
region: content
settings:
link_to_entity: false
third_party_settings: { }
notes:
label: inline
type: text_default
weight: 4
region: content
settings: { }
third_party_settings: { }
serial_number:
label: inline
type: string
weight: 3
region: content
settings:
link_to_entity: false
third_party_settings: { }
hidden:
data: true
file: true
geometry: true
id_tag: true
image: true
intrinsic_geometry: true
is_fixed: true
is_location: true
parent: true
status: true
uid: true

View File

@@ -0,0 +1,11 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_equipment
id: asset_equipment
color: orange
conditions:
asset_type:
- equipment

View File

@@ -0,0 +1,8 @@
name: Equipment asset
description: Adds an Equipment asset type.
type: module
package: farmOS Assets
core_version_requirement: ^10
dependencies:
- farm:asset
- farm:farm_entity

View File

@@ -0,0 +1,46 @@
<?php
/**
* @file
* Contains farm_equipment.module.
*/
use Drupal\Core\Entity\EntityTypeInterface;
/**
* Implements hook_farm_entity_bundle_field_info().
*/
function farm_equipment_farm_entity_bundle_field_info(EntityTypeInterface $entity_type, string $bundle) {
$fields = [];
// Add an Equipment reference field to logs.
if ($entity_type->id() == 'log') {
$options = [
'type' => 'entity_reference',
'label' => t('Equipment used'),
'description' => t('What equipment was used?'),
'target_type' => 'asset',
'target_bundle' => 'equipment',
'multiple' => TRUE,
'weight' => [
'form' => 40,
'view' => 40,
],
];
$fields['equipment'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
}
return $fields;
}
/**
* Implements hook_farm_ui_theme_field_group_items().
*/
function farm_equipment_farm_ui_theme_field_group_items(string $entity_type, string $bundle) {
if ($entity_type == 'log') {
return [
'equipment' => 'asset',
];
}
return [];
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Drupal\farm_equipment\Plugin\Asset\AssetType;
use Drupal\farm_entity\Plugin\Asset\AssetType\FarmAssetType;
/**
* Provides the equipment asset type.
*
* @AssetType(
* id = "equipment",
* label = @Translation("Equipment"),
* )
*/
class Equipment extends FarmAssetType {
/**
* {@inheritdoc}
*/
public function buildFieldDefinitions() {
$fields = parent::buildFieldDefinitions();
$field_info = [
'manufacturer' => [
'type' => 'string',
'label' => $this->t('Manufacturer'),
'weight' => [
'form' => -20,
'view' => -50,
],
],
'model' => [
'type' => 'string',
'label' => $this->t('Model'),
'weight' => [
'form' => -15,
'view' => -40,
],
],
'serial_number' => [
'type' => 'string',
'label' => $this->t('Serial number'),
'weight' => [
'form' => -10,
'view' => -30,
],
],
];
foreach ($field_info as $name => $info) {
$fields[$name] = $this->farmFieldFactory->bundleFieldDefinition($info);
}
return $fields;
}
}

View File

@@ -0,0 +1,9 @@
langcode: en
status: true
dependencies: { }
id: test
label: Test
description: ''
name_pattern: 'Test log [log:id]'
workflow: log_default
new_revision: true

View File

@@ -0,0 +1,8 @@
name: farmOS Equipment Test
description: Module for testing Equipment field.
type: module
package: Testing
core_version_requirement: ^10
dependencies:
- farm:farm_entity
- farm:farm_equipment

View File

@@ -0,0 +1,17 @@
<?php
namespace Drupal\farm_equipment_test\Plugin\Log\LogType;
use Drupal\farm_entity\Plugin\Log\LogType\FarmLogType;
/**
* Provides the test log type.
*
* @LogType(
* id = "test",
* label = @Translation("Test"),
* )
*/
class Test extends FarmLogType {
}

View File

@@ -0,0 +1,79 @@
<?php
namespace Drupal\Tests\farm_equipment\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\farm_test\Functional\FarmBrowserTestBase;
/**
* Tests the equipment used field.
*
* @group farm
*/
class EquipmentFieldTest extends FarmBrowserTestBase {
use StringTranslationTrait;
/**
* Test user.
*
* @var \Drupal\user\Entity\User
*/
protected $user;
/**
* {@inheritdoc}
*/
protected static $modules = [
'farm_entity',
'farm_equipment',
'farm_equipment_test',
];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// Create and login a user with permission to administer assets and logs.
$this->user = $this->createUser(['administer assets', 'administer log']);
$this->drupalLogin($this->user);
}
/**
* Test that the Equipment field is added to logs and visible.
*/
public function testEquipmentField() {
$entity_type_manager = $this->container->get('entity_type.manager');
$asset_storage = $entity_type_manager->getStorage('asset');
$log_storage = $entity_type_manager->getStorage('log');
// Create an equipment asset.
$asset = $asset_storage->create([
'name' => $this->randomMachineName(),
'type' => 'equipment',
]);
$asset->save();
// Go to the log add form.
$this->drupalGet('log/add/test');
$this->assertSession()->statusCodeEquals(200);
// Confirm that the equipment reference field form is visible.
$this->assertSession()->fieldExists('equipment[0][target_id]');
// Create a log that references the equipment.
$log = $log_storage->create(['type' => 'test']);
$log->equipment[] = ['target_id' => $asset->id()];
$log->save();
// Go to the log view page.
$this->drupalGet('log/' . $log->id());
$this->assertSession()->statusCodeEquals(200);
// Confirm that the equipment reference field display is visible.
$this->assertSession()->pageTextContains("Equipment used");
}
}