clean install

This commit is contained in:
matze committed 2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 files changed
+3555714

No files matched your search

@@ -0,0 +1,17 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land
module:
- farm_location
id: land
label: Land
description: ''
workflow: asset_default
new_revision: true
third_party_settings:
farm_location:
is_location: true
is_fixed: true
@@ -0,0 +1,8 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land
id: other
label: Other
@@ -0,0 +1,55 @@
langcode: en
status: true
dependencies:
config:
- asset.type.land
- core.entity_view_mode.asset.map_popup
module:
- options
- text
id: asset.land.map_popup
targetEntityType: asset
bundle: land
mode: map_popup
content:
flag:
label: inline
type: list_default
weight: 0
region: content
settings: { }
third_party_settings: { }
land_type:
label: inline
type: list_default
weight: 1
region: content
settings: { }
third_party_settings: { }
location:
type: entity_reference_label
weight: 3
region: content
label: inline
settings:
link: true
third_party_settings: { }
notes:
label: inline
type: text_default
weight: 2
region: content
settings: { }
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
@@ -0,0 +1,11 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land
id: asset_land
color: green
conditions:
asset_type:
- land
@@ -0,0 +1,13 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land
id: land_type_other
color: grey
conditions:
asset_type:
- land
land_type:
- other
@@ -0,0 +1,11 @@
# Schema for land_type config entity.
farm_land.land_type.*:
type: config_entity
label: 'Land type'
mapping:
id:
type: string
label: 'ID'
label:
type: label
label: 'Label'
@@ -0,0 +1,8 @@
name: Land asset
description: Adds a Land asset type.
type: module
package: farmOS Assets
core_version_requirement: ^10
dependencies:
- farm:asset
- farm:farm_entity
@@ -0,0 +1,3 @@
farm_land:
default_permissions:
- view land_type
@@ -0,0 +1,62 @@
<?php
/**
* @file
* Land asset module.
*/
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Land type options helper.
*
* @return array
* Returns an array of land types for use in form select options.
*/
function farm_land_type_options() {
/** @var \Drupal\farm_land\Entity\FarmLandTypeInterface[] $types */
$types = \Drupal::entityTypeManager()->getStorage('land_type')->loadMultiple();
$options = [];
foreach ($types as $id => $type) {
$options[$id] = $type->getLabel();
}
return $options;
}
/**
* Allowed values callback function for the land type field.
*
* @param \Drupal\Core\Field\FieldStorageDefinitionInterface $definition
* The field definition.
* @param \Drupal\Core\Entity\ContentEntityInterface|null $entity
* The entity being created if applicable.
* @param bool $cacheable
* Boolean indicating if the allowed values can be cached. Defaults to TRUE.
*
* @return array
* Returns an array of allowed values for use in form select options.
*/
function farm_land_type_field_allowed_values(FieldStorageDefinitionInterface $definition, ?ContentEntityInterface $entity = NULL, bool &$cacheable = TRUE) {
return farm_land_type_options();
}
/**
* Implements hook_farm_ui_theme_region_items().
*/
function farm_land_farm_ui_theme_region_items(string $entity_type) {
// Define common asset, log, and plan region items on behalf of core modules.
switch ($entity_type) {
case 'asset':
return [
'second' => [
'land_type',
],
];
default:
return [];
}
}
@@ -0,0 +1,7 @@
services:
farm_land.map_render_event_subscriber:
class: Drupal\farm_land\EventSubscriber\MapRenderEventSubscriber
arguments:
[ '@entity_type.manager', '@farm_map.layer_style_loader' ]
tags:
- { name: 'event_subscriber' }
@@ -0,0 +1,63 @@
<?php
/**
* @file
* Provides Views runtime hooks for farm_land.module.
*/
use Drupal\farm_land\Entity\FarmLandType;
use Drupal\views\ViewExecutable;
/**
* Implements hook_views_pre_render().
*/
function farm_land_views_pre_render(ViewExecutable $view) {
// Add land type map layers to the land assets map.
if ($view->id() == 'farm_asset' && $view->current_display == 'page_type' && !empty($view->args[0]) && $view->args[0] == 'land') {
// If the asset_map has not been added, bail.
if (empty($view->attachment_before['asset_map'])) {
return;
}
$map = &$view->attachment_before['asset_map'];
// Load all land types.
$land_types = FarmLandType::loadMultiple();
// Get exposed filters.
$exposed_filters = $view->getExposedInput();
// If the land type exposed filter is already in use remove land types
// that are not included.
if (!empty($exposed_filters['land_type_value'])) {
$land_types = array_filter($land_types, function ($key) use ($exposed_filters) {
return in_array($key, $exposed_filters['land_type_value']);
}, ARRAY_FILTER_USE_KEY);
}
// Create a layer for each land type.
$asset_layers = [];
foreach ($land_types as $land_type) {
/** @var \Drupal\farm_map\Entity\LayerStyleInterface $layer_style */
$layer_style = \Drupal::service('farm_map.layer_style_loader')->load(['asset_type' => 'land', 'land_type' => $land_type->id()]);
if (!is_null($layer_style)) {
$color = $layer_style->get('color');
}
$asset_layers['land_' . $land_type->id()] = [
'group' => t('Land types'),
'label' => $land_type->label(),
'asset_type' => 'land',
'filters' => $exposed_filters + ['land_type_value[]' => $land_type->id()],
'color' => $color ?? 'orange',
'zoom' => TRUE,
];
}
// Add layers to the map settings.
$map['#map_settings']['asset_type_layers'] = array_merge($map['#map_settings']['asset_type_layers'], $asset_layers);
// Remove the land asset layer.
unset($map['#map_settings']['asset_type_layers']['full_land']);
}
}
@@ -0,0 +1,8 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land_types
id: bed
label: Bed
@@ -0,0 +1,8 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land_types
id: field
label: Field
@@ -0,0 +1,8 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land_types
id: landmark
label: Landmark
@@ -0,0 +1,8 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land_types
id: paddock
label: Paddock
@@ -0,0 +1,8 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land_types
id: property
label: Property
@@ -0,0 +1,13 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land_types
id: land_type_bed
color: green
conditions:
asset_type:
- land
land_type:
- bed
@@ -0,0 +1,13 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land_types
id: land_type_field
color: yellow
conditions:
asset_type:
- land
land_type:
- field
@@ -0,0 +1,13 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land_types
id: land_type_landmark
color: orange
conditions:
asset_type:
- land
land_type:
- landmark
@@ -0,0 +1,13 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land_types
id: land_type_paddock
color: darkgreen
conditions:
asset_type:
- land
land_type:
- paddock
@@ -0,0 +1,13 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_land_types
id: land_type_property
color: purple
conditions:
asset_type:
- land
land_type:
- property
@@ -0,0 +1,7 @@
name: farmOS Default Land Types
description: 'Provides default land types: Property, Field, Bed, Paddock, Landmark.'
type: module
package: farmOS Defaults
core_version_requirement: ^10
dependencies:
- farm:farm_land
@@ -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;
}
}
@@ -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();
}
@@ -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);
}
}
}
@@ -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;
}
}