Add plan record type bundle plugin support via the farm_entity module.
This commit is contained in:
parent
9d31aa5ce7
commit
79704c3c7c
|
@ -46,7 +46,7 @@ function farm_entity_entity_type_build(array &$entity_types) {
|
|||
}
|
||||
|
||||
// Enable the use of bundle plugins on specific entity types.
|
||||
foreach (['asset', 'log', 'plan', 'quantity'] as $entity_type) {
|
||||
foreach (['asset', 'log', 'plan', 'plan_record', 'quantity'] as $entity_type) {
|
||||
if (!empty($entity_types[$entity_type])) {
|
||||
$entity_types[$entity_type]->set('bundle_plugin_type', $entity_type . '_type');
|
||||
$entity_types[$entity_type]->setHandlerClass('bundle_plugin', FarmEntityBundlePluginHandler::class);
|
||||
|
|
|
@ -12,6 +12,9 @@ services:
|
|||
plugin.manager.plan_type:
|
||||
class: Drupal\farm_entity\PlanTypeManager
|
||||
parent: default_plugin_manager
|
||||
plugin.manager.plan_record_type:
|
||||
class: Drupal\farm_entity\PlanRecordTypeManager
|
||||
parent: default_plugin_manager
|
||||
plugin.manager.quantity_type:
|
||||
class: Drupal\farm_entity\QuantityTypeManager
|
||||
parent: default_plugin_manager
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_entity\Annotation;
|
||||
|
||||
use Drupal\Component\Annotation\Plugin;
|
||||
|
||||
/**
|
||||
* Defines the plan record relationship type plugin annotation object.
|
||||
*
|
||||
* Plugin namespace: Plugin\PlanRecord\PlanRecordType.
|
||||
*
|
||||
* @see plugin_api
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class PlanRecordType extends Plugin {
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The plan record relationship type label.
|
||||
*
|
||||
* @var \Drupal\Core\Annotation\Translation
|
||||
*
|
||||
* @ingroup plugin_translatable
|
||||
*/
|
||||
public $label;
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_entity;
|
||||
|
||||
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 plan record relationship type plugins.
|
||||
*
|
||||
* @see \Drupal\farm_entity\Annotation\PlanType
|
||||
* @see plugin_api
|
||||
*/
|
||||
class PlanRecordTypeManager extends DefaultPluginManager {
|
||||
|
||||
/**
|
||||
* Constructs a new PlanRecordTypeManager 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/PlanRecord/PlanRecordType', $namespaces, $module_handler, 'Drupal\farm_entity\Plugin\PlanRecord\PlanRecordType\PlanRecordTypeInterface', 'Drupal\farm_entity\Annotation\PlanRecordType');
|
||||
|
||||
$this->alterInfo('plan_record_type_info');
|
||||
$this->setCacheBackend($cache_backend, 'plan_record_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 plan record relationship type %s must define the %s property.', $plugin_id, $required_property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_entity\Plugin\PlanRecord\PlanRecordType;
|
||||
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Provides a farmOS plan record relationship type base class.
|
||||
*/
|
||||
class FarmPlanRecordType extends PlanRecordTypeBase {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_entity\Plugin\PlanRecord\PlanRecordType;
|
||||
|
||||
use Drupal\farm_entity\FarmEntityTypeBase;
|
||||
|
||||
/**
|
||||
* Provides the base plan record relationship type class.
|
||||
*/
|
||||
abstract class PlanRecordTypeBase extends FarmEntityTypeBase implements PlanRecordTypeInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLabel() {
|
||||
return $this->pluginDefinition['label'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildFieldDefinitions() {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\farm_entity\Plugin\PlanRecord\PlanRecordType;
|
||||
|
||||
use Drupal\entity\BundlePlugin\BundlePluginInterface;
|
||||
|
||||
/**
|
||||
* Defines the interface for plan record relationship types.
|
||||
*/
|
||||
interface PlanRecordTypeInterface extends BundlePluginInterface {
|
||||
|
||||
/**
|
||||
* Gets the plan record relationship type label.
|
||||
*
|
||||
* @return string
|
||||
* The plan record relationship type label.
|
||||
*/
|
||||
public function getLabel();
|
||||
|
||||
}
|
Loading…
Reference in New Issue