mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Add support for log bundle plugins.
This commit is contained in:
parent
3d22b3d677
commit
bd6faab922
|
@ -49,7 +49,7 @@ type: module
|
|||
package: farmOS Contrib
|
||||
core_version_requirement: ^9
|
||||
dependencies:
|
||||
- log:log
|
||||
- farm:farm_log
|
||||
```
|
||||
|
||||
Other common files and directories in a module include:
|
||||
|
|
|
@ -5,4 +5,4 @@ package: Testing
|
|||
core_version_requirement: ^9
|
||||
dependencies:
|
||||
- farm:farm_field
|
||||
- log:log
|
||||
- farm:farm_log
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_equipment_field_test\Plugin\Log\LogType;
|
||||
|
||||
use Drupal\farm_log\Plugin\Log\LogType\LogTypeBase;
|
||||
|
||||
/**
|
||||
* Provides the test log type.
|
||||
*
|
||||
* @LogType(
|
||||
* id = "test",
|
||||
* label = @Translation("Test"),
|
||||
* )
|
||||
*/
|
||||
class Test extends LogTypeBase {
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_field_test\Plugin\Asset\AssetType;
|
||||
|
||||
use Drupal\asset\Plugin\Asset\AssetType\AssetTypeBase;
|
||||
|
||||
/**
|
||||
* Provides the test asset type.
|
||||
*
|
||||
* @AssetType(
|
||||
* id = "test",
|
||||
* label = @Translation("Test"),
|
||||
* )
|
||||
*/
|
||||
class Test extends AssetTypeBase {
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_field_test\Plugin\Log\LogType;
|
||||
|
||||
use Drupal\farm_log\Plugin\Log\LogType\LogTypeBase;
|
||||
|
||||
/**
|
||||
* Provides the test log type.
|
||||
*
|
||||
* @LogType(
|
||||
* id = "test",
|
||||
* label = @Translation("Test"),
|
||||
* )
|
||||
*/
|
||||
class Test extends LogTypeBase {
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_field_test\Plugin\Plan\PlanType;
|
||||
|
||||
use Drupal\plan\Plugin\Plan\PlanType\PlanTypeBase;
|
||||
|
||||
/**
|
||||
* Provides the test plan type.
|
||||
*
|
||||
* @PlanType(
|
||||
* id = "test",
|
||||
* label = @Translation("Test"),
|
||||
* )
|
||||
*/
|
||||
class Test extends PlanTypeBase {
|
||||
|
||||
}
|
7
modules/core/log/farm_log.info.yml
Normal file
7
modules/core/log/farm_log.info.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
name: farmOS Log
|
||||
description: Extends the Log entity type for farmOS.
|
||||
type: module
|
||||
package: farmOS
|
||||
core_version_requirement: ^9
|
||||
dependencies:
|
||||
- log:log
|
34
modules/core/log/farm_log.module
Normal file
34
modules/core/log/farm_log.module
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* The farmOS Log module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_module_implements_alter().
|
||||
*/
|
||||
function farm_log_module_implements_alter(&$implementations, $hook) {
|
||||
|
||||
// Make sure this module's hook_entity_type_build() runs before the
|
||||
// entity module's implementation, so that we can set the Log entity type's
|
||||
// bundle_plugin_type.
|
||||
$module = 'farm_log';
|
||||
if ($hook == 'entity_type_build') {
|
||||
$implementation = [$module => $implementations[$module]];
|
||||
unset($implementations[$module]);
|
||||
$implementations = array_merge($implementation, $implementations);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_type_build().
|
||||
*/
|
||||
function farm_log_entity_type_build(array &$entity_types) {
|
||||
|
||||
// Enable the use of bundle plugins for log entities.
|
||||
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
|
||||
if (!empty($entity_types['log'])) {
|
||||
$entity_types['log']->set('bundle_plugin_type', 'log_type');
|
||||
}
|
||||
}
|
4
modules/core/log/farm_log.services.yml
Normal file
4
modules/core/log/farm_log.services.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
services:
|
||||
plugin.manager.log_type:
|
||||
class: Drupal\farm_log\LogTypeManager
|
||||
parent: default_plugin_manager
|
34
modules/core/log/src/Annotation/LogType.php
Normal file
34
modules/core/log/src/Annotation/LogType.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_log\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Defines the log type plugin annotation object.
|
||||
*
|
||||
* Plugin namespace: Plugin\Log\LogType.
|
||||
*
|
||||
* @see plugin_api
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class LogType extends Plugin {
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The log type label.
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*/
|
||||
public $label;
|
||||
|
||||
}
|
49
modules/core/log/src/LogTypeManager.php
Normal file
49
modules/core/log/src/LogTypeManager.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_log;
|
||||
|
||||
use Drupal\Component\Plugin\Exception\PluginException;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
|
||||
/**
|
||||
* Manages discovery and instantiation of log type plugins.
|
||||
*
|
||||
* @see \Drupal\log\Annotation\LogType
|
||||
* @see plugin_api
|
||||
*/
|
||||
class LogTypeManager extends DefaultPluginManager {
|
||||
|
||||
/**
|
||||
* Constructs a new LogTypeManager object.
|
||||
*
|
||||
* @param \Traversable $namespaces
|
||||
* An object that implements \Traversable which contains the root paths
|
||||
* keyed by the corresponding namespace to look for plugin implementations.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
|
||||
* The cache backend.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Plugin/Log/LogType', $namespaces, $module_handler, 'Drupal\farm_log\Plugin\Log\LogType\LogTypeInterface', 'Drupal\farm_log\Annotation\LogType');
|
||||
|
||||
$this->alterInfo('log_type_info');
|
||||
$this->setCacheBackend($cache_backend, 'log_type_plugins');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processDefinition(&$definition, $plugin_id) {
|
||||
parent::processDefinition($definition, $plugin_id);
|
||||
|
||||
foreach (['id', 'label'] as $required_property) {
|
||||
if (empty($definition[$required_property])) {
|
||||
throw new PluginException(sprintf('The log type %s must define the %s property.', $plugin_id, $required_property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
33
modules/core/log/src/Plugin/Log/LogType/LogTypeBase.php
Normal file
33
modules/core/log/src/Plugin/Log/LogType/LogTypeBase.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_log\Plugin\Log\LogType;
|
||||
|
||||
use Drupal\Core\Plugin\PluginBase;
|
||||
|
||||
/**
|
||||
* Provides the base log type class.
|
||||
*/
|
||||
abstract class LogTypeBase extends PluginBase implements LogTypeInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLabel() {
|
||||
return $this->pluginDefinition['label'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getWorkflowId() {
|
||||
return $this->pluginDefinition['workflow'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildFieldDefinitions() {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
28
modules/core/log/src/Plugin/Log/LogType/LogTypeInterface.php
Normal file
28
modules/core/log/src/Plugin/Log/LogType/LogTypeInterface.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_log\Plugin\Log\LogType;
|
||||
|
||||
use Drupal\entity\BundlePlugin\BundlePluginInterface;
|
||||
|
||||
/**
|
||||
* Defines the interface for log types.
|
||||
*/
|
||||
interface LogTypeInterface extends BundlePluginInterface {
|
||||
|
||||
/**
|
||||
* Gets the log type label.
|
||||
*
|
||||
* @return string
|
||||
* The log type label.
|
||||
*/
|
||||
public function getLabel();
|
||||
|
||||
/**
|
||||
* Gets the log workflow ID.
|
||||
*
|
||||
* @return string
|
||||
* The log workflow ID.
|
||||
*/
|
||||
public function getWorkflowId();
|
||||
|
||||
}
|
|
@ -5,4 +5,5 @@ package: Testing
|
|||
core_version_requirement: ^8.8 || ^9
|
||||
|
||||
dependencies:
|
||||
- farm_role:farm_role
|
||||
- log:log
|
||||
- farm:farm_role
|
||||
|
|
Loading…
Reference in a new issue