AssignmentOptionalForm.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Drupal\features_ui\Form;
  3. use Drupal\Core\Form\FormStateInterface;
  4. /**
  5. * Configures the selected configuration assignment method for this site.
  6. */
  7. class AssignmentOptionalForm extends AssignmentFormBase {
  8. const METHOD_ID = 'optional';
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function getFormId() {
  13. return 'features_assignment_optional_form';
  14. }
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function buildForm(array $form, FormStateInterface $form_state, $bundle_name = NULL) {
  19. $this->currentBundle = $this->assigner->loadBundle($bundle_name);
  20. $settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID);
  21. $this->setConfigTypeSelect($form, $settings['types']['config'], $this->t('optional'));
  22. $this->setActions($form);
  23. return $form;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function validateForm(array &$form, FormStateInterface $form_state) {
  29. $form_state->setValue('types', array_map('array_filter', $form_state->getValue('types')));
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function submitForm(array &$form, FormStateInterface $form_state) {
  35. // Merge in types selections.
  36. $settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID);
  37. $settings['types'] = $form_state->getValue('types');
  38. $this->currentBundle->setAssignmentSettings(self::METHOD_ID, $settings)->save();
  39. $this->setRedirect($form_state);
  40. drupal_set_message($this->t('Package assignment configuration saved.'));
  41. }
  42. }