63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Structure asset module.
|
|
*/
|
|
|
|
use Drupal\Core\Entity\ContentEntityInterface;
|
|
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
|
|
|
/**
|
|
* Structure type options helper.
|
|
*
|
|
* @return array
|
|
* Returns an array of structure types for use in form select options.
|
|
*/
|
|
function farm_structure_type_options() {
|
|
/** @var \Drupal\farm_structure\Entity\FarmStructureTypeInterface[] $types */
|
|
$types = \Drupal::entityTypeManager()->getStorage('structure_type')->loadMultiple();
|
|
$options = [];
|
|
foreach ($types as $id => $type) {
|
|
$options[$id] = $type->getLabel();
|
|
}
|
|
return $options;
|
|
}
|
|
|
|
/**
|
|
* Allowed values callback function for the structure 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_structure_type_field_allowed_values(FieldStorageDefinitionInterface $definition, ?ContentEntityInterface $entity = NULL, bool &$cacheable = TRUE) {
|
|
return farm_structure_type_options();
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_ui_theme_region_items().
|
|
*/
|
|
function farm_structure_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' => [
|
|
'structure_type',
|
|
],
|
|
];
|
|
|
|
default:
|
|
return [];
|
|
}
|
|
}
|