OrderFieldsPaneDeriver.php in Commerce Checkout Order Fields 8
File
src/Plugin/Derivative/OrderFieldsPaneDeriver.php
View source
<?php
namespace Drupal\commerce_checkout_order_fields\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OrderFieldsPaneDeriver extends DeriverBase implements ContainerDeriverInterface {
protected $basePluginId;
protected $entityDisplayRepository;
public function __construct($base_plugin_id, EntityDisplayRepositoryInterface $entity_display_repository) {
$this->basePluginId = $base_plugin_id;
$this->entityDisplayRepository = $entity_display_repository;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('entity_display.repository'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$form_modes = $this->entityDisplayRepository
->getFormModes('commerce_order');
unset($form_modes['default']);
foreach ($form_modes as $form_mode_id => $form_mode_info) {
$this->derivatives[$form_mode_id] = [
'label' => sprintf('Order fields: %s', $form_mode_info['label']),
] + $base_plugin_definition;
}
return $this->derivatives;
}
}