Loading src/Form/EmailRegistrantsForm.php +1 −7 Original line number Diff line number Diff line Loading @@ -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() : []; } /** Loading src/Form/RegistrationTypeForm.php +1 −5 Original line number Diff line number Diff line Loading @@ -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() : []; } /** Loading src/Plugin/Action/RegistrationSetStateAction.php +13 −23 Original line number Diff line number Diff line Loading @@ -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; /** Loading @@ -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. * Loading @@ -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; } /** Loading @@ -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') ); } Loading @@ -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, ]; Loading Loading @@ -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. * Loading src/Plugin/WorkflowType/Registration.php +13 −1 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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} */ Loading src/Plugin/WorkflowType/RegistrationWorkflowTypeInterface.php 0 → 100644 +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
src/Form/EmailRegistrantsForm.php +1 −7 Original line number Diff line number Diff line Loading @@ -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() : []; } /** Loading
src/Form/RegistrationTypeForm.php +1 −5 Original line number Diff line number Diff line Loading @@ -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() : []; } /** Loading
src/Plugin/Action/RegistrationSetStateAction.php +13 −23 Original line number Diff line number Diff line Loading @@ -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; /** Loading @@ -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. * Loading @@ -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; } /** Loading @@ -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') ); } Loading @@ -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, ]; Loading Loading @@ -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. * Loading
src/Plugin/WorkflowType/Registration.php +13 −1 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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} */ Loading
src/Plugin/WorkflowType/RegistrationWorkflowTypeInterface.php 0 → 100644 +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; }