InlineFormManager.php in Commerce Core 8.2
File
src/InlineFormManager.php
View source
<?php
namespace Drupal\commerce;
use Drupal\commerce\Annotation\CommerceInlineForm;
use Drupal\commerce\Plugin\Commerce\InlineForm\EntityInlineFormInterface;
use Drupal\commerce\Plugin\Commerce\InlineForm\InlineFormInterface;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
class InlineFormManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Commerce/InlineForm', $namespaces, $module_handler, InlineFormInterface::class, CommerceInlineForm::class);
$this
->alterInfo('commerce_inline_form_info');
$this
->setCacheBackend($cache_backend, 'commerce_inline_form_plugins');
}
public function createInstance($plugin_id, array $configuration = [], EntityInterface $entity = NULL) {
$plugin = parent::createInstance($plugin_id, $configuration);
if ($plugin instanceof EntityInlineFormInterface) {
if (!$entity) {
throw new \RuntimeException(sprintf('The %s inline form requires an entity.', $plugin_id));
}
$plugin
->setEntity($entity);
}
if ($entity) {
assert($plugin instanceof EntityInlineFormInterface);
}
return $plugin;
}
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 inline form %s must define the %s property.', $plugin_id, $required_property));
}
}
}
}