You are here

class OrderFieldsPaneDeriver in Commerce Checkout Order Fields 8

Hierarchy

Expanded class hierarchy of OrderFieldsPaneDeriver

File

src/Plugin/Derivative/OrderFieldsPaneDeriver.php, line 10

Namespace

Drupal\commerce_checkout_order_fields\Plugin\Derivative
View source
class OrderFieldsPaneDeriver extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The base plugin ID this derivative is for.
   *
   * @var string
   */
  protected $basePluginId;

  /**
   * The entity display repository.
   *
   * @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
   */
  protected $entityDisplayRepository;

  /**
   * Constructs a new OrderFieldsPaneDeriver object.
   *
   * @param string $base_plugin_id
   *   The base plugin ID.
   * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
   *   The entity display repository.
   */
  public function __construct($base_plugin_id, EntityDisplayRepositoryInterface $entity_display_repository) {
    $this->basePluginId = $base_plugin_id;
    $this->entityDisplayRepository = $entity_display_repository;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($base_plugin_id, $container
      ->get('entity_display.repository'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $form_modes = $this->entityDisplayRepository
      ->getFormModes('commerce_order');

    // Do not generate a derivative for default.
    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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
OrderFieldsPaneDeriver::$basePluginId protected property The base plugin ID this derivative is for.
OrderFieldsPaneDeriver::$entityDisplayRepository protected property The entity display repository.
OrderFieldsPaneDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
OrderFieldsPaneDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
OrderFieldsPaneDeriver::__construct public function Constructs a new OrderFieldsPaneDeriver object.