AssignmentExcludeForm.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 AssignmentExcludeForm extends AssignmentFormBase {
  8. const METHOD_ID = 'exclude';
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function getFormId() {
  13. return 'features_assignment_exclude_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('exclude'));
  22. $module_settings = $settings['module'];
  23. $curated_settings = $settings['curated'];
  24. $form['curated'] = array(
  25. '#type' => 'checkbox',
  26. '#title' => $this->t('Exclude designated site-specific configuration'),
  27. '#default_value' => $curated_settings,
  28. '#description' => $this->t('Select this option to exclude from packaging items on a curated list of site-specific configuration.'),
  29. );
  30. $form['module'] = array(
  31. '#type' => 'container',
  32. '#tree' => TRUE,
  33. );
  34. $form['module']['installed'] = array(
  35. '#type' => 'checkbox',
  36. '#title' => $this->t('Exclude installed module-provided entity configuration'),
  37. '#default_value' => $module_settings['installed'],
  38. '#description' => $this->t('Select this option to exclude from packaging any configuration that is provided by already installed modules.'),
  39. '#attributes' => array(
  40. 'data-module-installed' => 'status',
  41. ),
  42. );
  43. $show_if_module_installed_checked = array(
  44. 'visible' => array(
  45. ':input[data-module-installed="status"]' => array('checked' => TRUE),
  46. ),
  47. );
  48. $info = system_get_info('module', drupal_get_profile());
  49. $form['module']['profile'] = array(
  50. '#type' => 'checkbox',
  51. '#title' => $this->t("Don't exclude install profile's configuration"),
  52. '#default_value' => $module_settings['profile'],
  53. '#description' => $this->t("Select this option to not exclude from packaging any configuration that is provided by this site's install profile, %profile.", array('%profile' => $info['name'])),
  54. '#states' => $show_if_module_installed_checked,
  55. );
  56. $machine_name = $this->currentBundle->getMachineName();
  57. $machine_name = !empty($machine_name) ? $machine_name : $this->t('none');
  58. $form['module']['namespace'] = array(
  59. '#type' => 'checkbox',
  60. '#title' => $this->t("Don't exclude non-installed configuration by namespace"),
  61. '#default_value' => $module_settings['namespace'],
  62. '#description' => $this->t("Select this option to not exclude from packaging any configuration that is provided by non-installed modules with the package namespace (currently %namespace).", array('%namespace' => $machine_name)),
  63. '#states' => $show_if_module_installed_checked,
  64. '#attributes' => array(
  65. 'data-namespace' => 'status',
  66. ),
  67. );
  68. $show_if_namespace_checked = array(
  69. 'visible' => array(
  70. ':input[data-namespace="status"]' => array('checked' => TRUE),
  71. ':input[data-module-installed="status"]' => array('checked' => TRUE),
  72. ),
  73. );
  74. $form['module']['namespace_any'] = array(
  75. '#type' => 'checkbox',
  76. '#title' => $this->t("Don't exclude ANY configuration by namespace"),
  77. '#default_value' => $module_settings['namespace_any'],
  78. '#description' => $this->t("Select this option to not exclude from packaging any configuration that is provided by ANY modules with the package namespace (currently %namespace).
  79. Warning: Can cause installed configuration to be reassigned to different packages.", array('%namespace' => $machine_name)),
  80. '#states' => $show_if_namespace_checked,
  81. );
  82. $this->setActions($form);
  83. return $form;
  84. }
  85. /**
  86. * {@inheritdoc}
  87. */
  88. public function validateForm(array &$form, FormStateInterface $form_state) {
  89. $form_state->setValue('types', array_map('array_filter', $form_state->getValue('types')));
  90. }
  91. /**
  92. * {@inheritdoc}
  93. */
  94. public function submitForm(array &$form, FormStateInterface $form_state) {
  95. // Merge in selections.
  96. $settings = $this->currentBundle->getAssignmentSettings(self::METHOD_ID);
  97. $settings = array_merge($settings, [
  98. 'types' => $form_state->getValue('types'),
  99. 'curated' => $form_state->getValue('curated'),
  100. 'module' => $form_state->getValue('module'),
  101. ]);
  102. $this->currentBundle->setAssignmentSettings(self::METHOD_ID, $settings)->save();
  103. $this->setRedirect($form_state);
  104. drupal_set_message($this->t('Package assignment configuration saved.'));
  105. }
  106. }