Commit c6187884 authored by john.oltman's avatar john.oltman
Browse files

#3523799: Enhance registration state options

parent f6eb845c
Loading
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -337,13 +337,7 @@ class EmailRegistrantsForm extends RegistrationFormBase {
    $host_entity = $this->getHostEntity($form_state);
    $registration_type = $host_entity->getRegistrationType();
    $workflow = $registration_type->getWorkflow();

    $options = [];
    $states = $workflow ? $workflow->getTypePlugin()->getStates() : [];
    foreach ($states as $id => $state) {
      $options[$id] = $state->label();
    }
    return $options;
    return $workflow ? $workflow->getTypePlugin()->getStateOptions() : [];
  }

  /**
+1 −5
Original line number Diff line number Diff line
@@ -145,11 +145,7 @@ class RegistrationTypeForm extends BundleEntityFormBase {
    else {
      $workflow = $this->entity->getWorkflow();
    }
    $states = $workflow ? $workflow->getTypePlugin()->getStates() : [];
    foreach ($states as $id => $state) {
      $options[$id] = $state->label();
    }
    return $options;
    return $workflow ? $workflow->getTypePlugin()->getStateOptions() : [];
  }

  /**
+13 −23
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\registration\RegistrationManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
@@ -26,11 +27,14 @@ class RegistrationSetStateAction extends ConfigurableActionBase implements Conta

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected EntityTypeManagerInterface $entityTypeManager;

  /**
   * The registration manager.
   */
  protected RegistrationManagerInterface $registrationManager;

  /**
   * Constructs an RegistrationSetStateAction object.
   *
@@ -42,10 +46,13 @@ class RegistrationSetStateAction extends ConfigurableActionBase implements Conta
   *   The plugin implementation definition.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\registration\RegistrationManagerInterface $registration_manager
   *   The registration manager.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, RegistrationManagerInterface $registration_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityTypeManager = $entity_type_manager;
    $this->registrationManager = $registration_manager;
  }

  /**
@@ -56,7 +63,8 @@ class RegistrationSetStateAction extends ConfigurableActionBase implements Conta
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('entity_type.manager')
      $container->get('entity_type.manager'),
      $container->get('registration.manager')
    );
  }

@@ -76,7 +84,7 @@ class RegistrationSetStateAction extends ConfigurableActionBase implements Conta
    $form['registration_state'] = [
      '#type' => 'select',
      '#title' => $this->t('Status'),
      '#options' => $this->getStateOptions(),
      '#options' => $this->registrationManager->getWorkflowStateOptions(TRUE),
      '#default_value' => $this->configuration['registration_state'],
      '#required' => TRUE,
    ];
@@ -138,24 +146,6 @@ class RegistrationSetStateAction extends ConfigurableActionBase implements Conta
    return $return_as_object ? $result : $result->isAllowed();
  }

  /**
   * Gets the available registration state options from the workflow.
   */
  protected function getStateOptions(): array {
    $states = [];
    $workflow = $this->entityTypeManager->getStorage('workflow')->load('registration');
    if ($workflow) {
      $all_states = $workflow->getTypePlugin()->getStates();
      foreach ($all_states as $id => $state) {
        /** @var \Drupal\registration\RegistrationState $state */
        if ($state->isShownOnForm()) {
          $states[$id] = $state->label();
        }
      }
    }
    return $states;
  }

  /**
   * Loads the current account object, if it does not exist yet.
   *
+13 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 *   },
 * )
 */
class Registration extends WorkflowTypeBase implements ContainerFactoryPluginInterface {
class Registration extends WorkflowTypeBase implements ContainerFactoryPluginInterface, RegistrationWorkflowTypeInterface {

  /**
   * The entity type manager.
@@ -94,6 +94,18 @@ class Registration extends WorkflowTypeBase implements ContainerFactoryPluginInt
    return $state;
  }

  /**
   * {@inheritdoc}
   */
  public function getStateOptions(): array {
    $options = [];
    $states = $this->getStates();
    foreach ($states as $id => $state) {
      $options[$id] = $state->label();
    }
    return $options;
  }

  /**
   * {@inheritdoc}
   */
+20 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\registration\Plugin\WorkflowType;

/**
 * An interface for registration workflow type plugins.
 */
interface RegistrationWorkflowTypeInterface {

  /**
   * Gets the available registration state options for the workflow plugin.
   *
   * The options are suitable for use in a form select element.
   *
   * @return array
   *   The states as an options array of labels keyed by ID.
   */
  public function getStateOptions(): array;

}
Loading