ConfigsList.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Drupal\devel\Form;
  3. use Drupal\Component\Utility\Html;
  4. use Drupal\Core\Form\FormBase;
  5. use Drupal\Core\Form\FormStateInterface;
  6. use Drupal\Core\Url;
  7. /**
  8. * Form that displays all the config variables to edit them.
  9. */
  10. class ConfigsList extends FormBase {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function getFormId() {
  15. return 'devel_config_system_form';
  16. }
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function buildForm(array $form, FormStateInterface $form_state, $filter = '') {
  21. $form['filter'] = array(
  22. '#type' => 'details',
  23. '#title' => t('Filter variables'),
  24. '#attributes' => array('class' => array('container-inline')),
  25. '#open' => isset($filter) && trim($filter) != '',
  26. );
  27. $form['filter']['name'] = array(
  28. '#type' => 'textfield',
  29. '#title' => $this->t('Variable name'),
  30. '#title_display' => 'invisible',
  31. '#default_value' => $filter,
  32. );
  33. $form['filter']['actions'] = ['#type' => 'actions'];
  34. $form['filter']['actions']['show'] = [
  35. '#type' => 'submit',
  36. '#value' => $this->t('Filter'),
  37. ];
  38. $header = array(
  39. 'name' => array('data' => $this->t('Name')),
  40. 'edit' => array('data' => $this->t('Operations')),
  41. );
  42. $rows = array();
  43. $destination = $this->getDestinationArray();
  44. // List all the variables filtered if any filter was provided.
  45. $names = $this->configFactory()->listAll($filter);
  46. foreach ($names as $config_name) {
  47. $operations['edit'] = array(
  48. 'title' => $this->t('Edit'),
  49. 'url' => Url::fromRoute('devel.config_edit', array('config_name' => $config_name)),
  50. 'query' => $destination
  51. );
  52. $rows[] = array(
  53. 'name' => $config_name,
  54. 'operation' => array('data' => array('#type' => 'operations', '#links' => $operations)),
  55. );
  56. }
  57. $form['variables'] = array(
  58. '#type' => 'table',
  59. '#header' => $header,
  60. '#rows' => $rows,
  61. '#empty' => $this->t('No variables found')
  62. );
  63. return $form;
  64. }
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public function submitForm(array &$form, FormStateInterface $form_state) {
  69. $filter = $form_state->getValue('name');
  70. $form_state->setRedirectUrl(Url::FromRoute('devel.configs_list', array('filter' => Html::escape($filter))));
  71. }
  72. }