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,62 @@
<?php
namespace Drupal\farm_material\EventSubscriber;
use Drupal\quantity\Event\QuantityEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Perform actions when quantity entities are saved/deleted.
*/
class QuantityEventSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*
* @return array
* The event names to listen for, and the methods that should be executed.
*/
public static function getSubscribedEvents() {
return [
QuantityEvent::PRESAVE => 'quantityPresave',
];
}
/**
* Copy material_type from a material inventory asset to material quantity.
*
* @param \Drupal\quantity\Event\QuantityEvent $event
* Quantity event.
*/
public function quantityPresave(QuantityEvent $event) {
$quantity = $event->quantity;
// Bail if not a material quantity.
if ($quantity->bundle() !== 'material') {
return;
}
// Bail if there is no inventory field or if it is empty.
if (!$quantity->hasField('inventory_asset') || $quantity->get('inventory_asset')->isEmpty()) {
return;
}
// Get the referenced inventory asset.
/** @var \Drupal\asset\Entity\AssetInterface[] $assets */
$assets = $event->quantity->get('inventory_asset')->referencedEntities();
$asset = reset($assets);
// Bail if not a material asset.
if (empty($asset) || $asset->bundle() !== 'material') {
return;
}
// Copy the material asset material_type field to the material quantity.
if (!$asset->get('material_type')->isEmpty()) {
$material_type = $asset->get('material_type')->getValue();
$quantity->set('material_type', $material_type);
}
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Drupal\farm_material\Plugin\Asset\AssetType;
use Drupal\farm_entity\Plugin\Asset\AssetType\FarmAssetType;
/**
* Provides the material asset type.
*
* @AssetType(
* id = "material",
* label = @Translation("Material"),
* )
*/
class Material extends FarmAssetType {
/**
* {@inheritdoc}
*/
public function buildFieldDefinitions() {
$fields = parent::buildFieldDefinitions();
$field_info = [
'material_type' => [
'type' => 'entity_reference',
'label' => $this->t('Material type'),
'description' => $this->t("Enter the type of material."),
'target_type' => 'taxonomy_term',
'target_bundle' => 'material_type',
'auto_create' => TRUE,
'required' => TRUE,
'weight' => [
'form' => -90,
'view' => -50,
],
],
];
foreach ($field_info as $name => $info) {
$fields[$name] = $this->farmFieldFactory->bundleFieldDefinition($info);
}
return $fields;
}
}