AssignmentBaseForm.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 AssignmentBaseForm extends AssignmentFormBase {
  8. const METHOD_ID = 'base';
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function getFormId() {
  13. return 'features_assignment_base_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. // Pass the last argument to limit the select to config entity types that
  22. // provide bundles for other entity types.
  23. $this->setConfigTypeSelect($form, $settings['types']['config'], $this->t('base'), TRUE);
  24. // Pass the last argument to limit the select to content entity types do
  25. // not have config entity provided bundles, thus avoiding duplication with
  26. // the config type select options.
  27. $this->setContentTypeSelect($form, $settings['types']['content'], $this->t('base'), TRUE);
  28. $this->setActions($form);
  29. return $form;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function validateForm(array &$form, FormStateInterface $form_state) {
  35. $form_state->setValue('types', array_map('array_filter', $form_state->getValue('types')));
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function submitForm(array &$form, FormStateInterface $form_state) {
  41. // Merge in types selections.
  42. $settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID);
  43. $settings['types'] = $form_state->getValue('types');
  44. $this->currentBundle->setAssignmentSettings(self::METHOD_ID, $settings)->save();
  45. $this->setRedirect($form_state);
  46. drupal_set_message($this->t('Package assignment configuration saved.'));
  47. }
  48. }