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,53 @@
<?php
namespace Drupal\farm_land\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
/**
* Defines the FarmLandType entity.
*
* @ConfigEntityType(
* id = "land_type",
* label = @Translation("Land type"),
* label_collection = @Translation("Land types"),
* handlers = {
* "access" = "\Drupal\entity\EntityAccessControlHandler",
* "permission_provider" = "\Drupal\entity\EntityPermissionProvider",
* },
* entity_keys = {
* "id" = "id",
* "label" = "label",
* },
* config_export = {
* "id",
* "label",
* },
* )
*
* @ingroup farm
*/
class FarmLandType extends ConfigEntityBase implements FarmLandTypeInterface {
/**
* The land type ID.
*
* @var string
*/
protected $id;
/**
* The land type label.
*
* @var string
*/
protected $label;
/**
* {@inheritdoc}
*/
public function getLabel() {
return $this->label;
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Drupal\farm_land\Entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface for defining FarmLandType config entities.
*
* @ingroup farm
*/
interface FarmLandTypeInterface extends ConfigEntityInterface {
/**
* Returns the land type label.
*
* @return string
* The land type label.
*/
public function getLabel();
}

View File

@@ -0,0 +1,108 @@
<?php
namespace Drupal\farm_land\EventSubscriber;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\farm_land\Entity\FarmLandType;
use Drupal\farm_map\Event\MapRenderEvent;
use Drupal\farm_map\LayerStyleLoaderInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* An event subscriber for the MapRenderEvent.
*/
class MapRenderEventSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
/**
* Land asset type.
*
* @var \Drupal\asset\Entity\AssetTypeInterface
*/
protected $landAssetType;
/**
* The layer style loader service.
*
* @var \Drupal\farm_map\layerStyleLoader
*/
protected $layerStyleLoader;
/**
* MapRenderEventSubscriber Constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\farm_map\LayerStyleLoaderInterface $layer_style_loader
* The layer style loader service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, LayerStyleLoaderInterface $layer_style_loader) {
$this->landAssetType = $entity_type_manager->getStorage('asset_type')->load('land');
$this->layerStyleLoader = $layer_style_loader;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
MapRenderEvent::EVENT_NAME => ['onMapRender', -100],
];
}
/**
* React to the MapRenderEvent.
*
* @param \Drupal\farm_map\Event\MapRenderEvent $event
* The MapRenderEvent.
*/
public function onMapRender(MapRenderEvent $event) {
// If the "locations" behavior is added to the map, add layers for each
// land type.
if (in_array('locations', $event->getMapBehaviors())) {
$layers = [];
// Define the parent group.
$group = $this->t('Locations');
// Create a layer group for the asset type.
$layers['land'] = [
'group' => $group,
'label' => $this->landAssetType->label(),
'is_group' => TRUE,
];
// Load land types.
$land_types = FarmLandType::loadMultiple();
// Create a layer for each sub-type.
foreach ($land_types as $land_type) {
/** @var \Drupal\farm_map\Entity\LayerStyleInterface $layer_style */
$conditions = [
'asset_type' => 'land',
'land_type' => $land_type->id(),
];
$layer_style = $this->layerStyleLoader->load($conditions);
if (!empty($layer_style)) {
$color = $layer_style->get('color');
}
$layers['land_' . $land_type->id()] = [
'group' => $this->landAssetType->label(),
'label' => $land_type->label(),
'asset_type' => 'land',
'filters' => ['land_type_value[]' => $land_type->id()],
'color' => $color ?? 'orange',
'zoom' => TRUE,
];
}
// Add layers to the map settings.
$settings[$event->getMapTargetId()]['asset_type_layers'] = $layers;
$event->addSettings($settings);
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Drupal\farm_land\Plugin\Asset\AssetType;
use Drupal\farm_entity\Plugin\Asset\AssetType\FarmAssetType;
/**
* Provides the land asset type.
*
* @AssetType(
* id = "land",
* label = @Translation("Land"),
* )
*/
class Land extends FarmAssetType {
/**
* {@inheritdoc}
*/
public function buildFieldDefinitions() {
$fields = [];
// Land type field.
$options = [
'type' => 'list_string',
'label' => $this->t('Land type'),
'allowed_values_function' => 'farm_land_type_field_allowed_values',
'required' => TRUE,
'weight' => [
'form' => -80,
'view' => -80,
],
];
$fields['land_type'] = $this->farmFieldFactory->bundleFieldDefinition($options);
return $fields;
}
}